class Yaks::Mapper::Form::Field

Constants

Builder

Public Class Methods

create(*args) click to toggle source
# File lib/yaks/mapper/form/field.rb, line 25
def self.create(*args)
  attrs = args.last.instance_of?(Hash) ? args.pop : {}
  if name = args.shift
    attrs = attrs.merge(name: name)
  end
  new(attrs)
end

Public Instance Methods

resource_attributes() click to toggle source

All attributes that can be converted 1-to-1 to Resource::Form::Field

# File lib/yaks/mapper/form/field.rb, line 55
def resource_attributes
  self.class.attributes.names - [:options, :if]
end
resource_options(mapper) click to toggle source
# File lib/yaks/mapper/form/field.rb, line 43
def resource_options(mapper)
  # make sure all empty options arrays are the same instance,
  # makes for prettier #pp
  if options.empty?
    options
  else
    options.map {|opt| opt.to_resource_field_option(mapper) }.compact
  end
end
to_resource_fields(mapper) click to toggle source

Convert to a Resource::Form::Field, expanding any dynamic values

# File lib/yaks/mapper/form/field.rb, line 35
def to_resource_fields(mapper)
  return [] unless self.if.nil? || mapper.expand_value(self.if)
  [ Resource::Form::Field.new(
      resource_attributes.each_with_object({}) do |attr, attrs|
        attrs[attr] = mapper.expand_value(public_send(attr))
      end.merge(options: resource_options(mapper))) ]
end