class Yaks::Mapper::Form

Public Class Methods

create(*args, &block) click to toggle source
# File lib/yaks/mapper/form.rb, line 9
def self.create(*args, &block)
  args, options = extract_options(args)
  options[:name] = args.first if args.first
  new(config: Config.build(options, &block))
end

Public Instance Methods

add_to_resource(resource, mapper, _context) click to toggle source
# 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
to_resource_form(mapper) click to toggle source
# 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