Class: Yaks::Mapper::Form
- Inherits:
-
Object
- Object
- Yaks::Mapper::Form
show all
- Extended by:
- Forwardable, Util
- Defined in:
- lib/yaks/mapper/form.rb,
lib/yaks/mapper/form/field.rb,
lib/yaks/mapper/form/config.rb,
lib/yaks/mapper/form/legend.rb,
lib/yaks/mapper/form/fieldset.rb,
lib/yaks/mapper/form/field/option.rb,
lib/yaks/mapper/form/dynamic_field.rb
Defined Under Namespace
Classes: Config, DynamicField, Field, Fieldset, Legend
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Util
Resolve, camelize, extract_options, reject_keys, slice_hash, symbolize_keys, underscore
Class Method Details
.create(*args, &block) ⇒ Object
9
10
11
12
13
|
# File 'lib/yaks/mapper/form.rb', line 9
def self.create(*args, &block)
args, options = (args)
options[:name] = args.first if args.first
new(config: Config.build(options, &block))
end
|
Instance Method Details
#add_to_resource(resource, mapper, _context) ⇒ Object
20
21
22
23
|
# File 'lib/yaks/mapper/form.rb', line 20
def add_to_resource(resource, mapper, _context)
return resource if config.if && !mapper.expand_value(config.if)
resource.add_form(to_resource_form(mapper))
end
|
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/yaks/mapper/form.rb', line 25
def to_resource_form(mapper)
attrs = {
fields: config.to_resource_fields(mapper),
action: mapper.expand_uri(action)
}
[:name, :title, :method, :media_type].each do |attr|
attrs[attr] = mapper.expand_value(public_send(attr))
end
Resource::Form.new(attrs)
end
|