Sha256: 0e814d5bd8e8c982b638dcdc96717eaa83b92427b93a09fd238fd9d3eeba00af

Contents?: true

Size: 760 Bytes

Versions: 2

Compression:

Stored size: 760 Bytes

Contents

module Avo
  module FieldsCollector
    def field(field_name, as:, **args, &block)
      self.fields ||= []

      self.fields << parse_field(field_name, as: as, **args, &block)
    end

    def parse_field(field_name, as:, **args, &block)
      matched_field = Avo::App.fields.find do |field|
        field[:name].to_s == as.to_s
      end

      if matched_field.present? and matched_field[:class].present?
        klass = matched_field[:class]

        if block_given?
          field = klass.new(field_name, **args || {}, &block)
        else
          field = klass.new(field_name, **args || {})
        end

        field
      end
    end

    def heading(body, **args)
      self.fields << Avo::Fields::HeadingField.new(body, **args)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
avo-0.5.0.beta9 lib/avo/fields_collector.rb
avo-0.5.0.beta8 lib/avo/fields_collector.rb