Sha256: 1fdd3181e6aa6e82d88685e2baaf99943f9fe322a4ce0a22d3fdac5998f292d9

Contents?: true

Size: 722 Bytes

Versions: 36

Compression:

Stored size: 722 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? && matched_field[:class].present?
        klass = matched_field[:class]

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

      end
    end

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

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
avo-1.4.0.pre.1 lib/avo/fields_collector.rb
avo-1.3.5 lib/avo/fields_collector.rb
avo-1.3.5.pre.1 lib/avo/fields_collector.rb
avo-1.3.4 lib/avo/fields_collector.rb
avo-1.3.3 lib/avo/fields_collector.rb
avo-1.3.2 lib/avo/fields_collector.rb
avo-1.3.1 lib/avo/fields_collector.rb
avo-1.3.0 lib/avo/fields_collector.rb
avo-1.2.11.pre.4 lib/avo/fields_collector.rb
avo-1.2.11.pre.3 lib/avo/fields_collector.rb
avo-1.2.11.pre.2 lib/avo/fields_collector.rb
avo-1.2.11.pre.1 lib/avo/fields_collector.rb
avo-1.2.10 lib/avo/fields_collector.rb
avo-1.2.9 lib/avo/fields_collector.rb
avo-1.2.8 lib/avo/fields_collector.rb
avo-1.2.7 lib/avo/fields_collector.rb
avo-1.2.6 lib/avo/fields_collector.rb
avo-1.2.6.pre.1 lib/avo/fields_collector.rb
avo-1.2.5 lib/avo/fields_collector.rb
avo-1.2.4 lib/avo/fields_collector.rb