lib/yaks/mapper/form/fieldset.rb in yaks-0.8.3 vs lib/yaks/mapper/form/fieldset.rb in yaks-0.9.0

- old
+ new

@@ -1,42 +1,20 @@ module Yaks class Mapper class Form class Fieldset extend Forwardable - include Concord.new(:config) + include Attributes.new(:config) - def_delegators :config, :fields, :dynamic_blocks + def_delegators :config, :fields - ConfigBuilder = Builder.new(Config) do - 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_forward :dynamic + def self.create(options = {}, &block) + new(config: Config.build(options, &block)) end - def self.create(_opts={}, &block) - new(ConfigBuilder.build(Config.new, &block)) - end - - def to_resource(mapper) - config = dynamic_blocks.inject(self.config) do |config, block| - ConfigBuilder.build(config, mapper.object, &block) - end - - resource_fields = resource_fields(config.fields, mapper) - - Resource::Form::Fieldset.new(fields: resource_fields) - end - - def resource_fields(fields, mapper) - fields.map { |field| field.to_resource(mapper) } + def to_resource_fields(mapper) + return [] if config.if && !mapper.expand_value(config.if) + [ Resource::Form::Fieldset.new(fields: config.to_resource_fields(mapper)) ] end end end end end