Class: Yaks::Mapper::Form::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/yaks/mapper/form/config.rb

Constant Summary collapse

Builder =
Yaks::Builder.new(self) do
  def_set :action, :title, :method, :media_type
  def_add :field, create: Field::Builder, append_to: :fields
  def_add :fieldset, create: Fieldset, append_to: :fields
  HTML5Forms::INPUT_TYPES.each do |type|
    def_add(type,
            create: Field::Builder,
            append_to: :fields,
            defaults: {type: type})
  end
  def_add :legend, create: Legend, append_to: :fields
  def_add :dynamic, create: DynamicField, append_to: :fields
  def_forward :condition
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(options = {}, &block) ⇒ Object

Build up a configuration based on an initial set of attributes, and a configuration block



37
38
39
# File 'lib/yaks/mapper/form/config.rb', line 37

def self.build(options = {}, &block)
  Builder.create(options, &block)
end

.build_with_object(object, &block) ⇒ Object

Build up a configuration based on a config block. Provide an object to be supplied to the block



43
44
45
# File 'lib/yaks/mapper/form/config.rb', line 43

def self.build_with_object(object, &block)
  Builder.build(new, object, &block)
end

.create(options) ⇒ Object

Builder expects a ‘create’ method. Alias to constructor



31
32
33
# File 'lib/yaks/mapper/form/config.rb', line 31

def self.create(options)
  new(options)
end

Instance Method Details

#condition(prc = nil, &blk) ⇒ Object



47
48
49
# File 'lib/yaks/mapper/form/config.rb', line 47

def condition(prc = nil, &blk)
  with(if: prc || blk)
end

#to_resource_fields(mapper) ⇒ Object



51
52
53
54
55
# File 'lib/yaks/mapper/form/config.rb', line 51

def to_resource_fields(mapper)
  fields.flat_map do |field|
    field.to_resource_fields(mapper)
  end
end