class GenericViewMapper::Attribute

Attributes

name[R]
options[R]

Public Class Methods

new(name, options) click to toggle source
# File lib/generic_view_mapper/view/attribute.rb, line 7
def initialize(name, options)
  @name = name
  @options = options
end

Public Instance Methods

field_name() click to toggle source
# File lib/generic_view_mapper/view/attribute.rb, line 12
def field_name
  options
    .fetch(:as) { name }
    .to_s
    .camelize(:lower)
    .to_sym
end
render(target, view_context) click to toggle source
# File lib/generic_view_mapper/view/attribute.rb, line 30
def render(target, view_context)
  { field_name => send_to(target, view_context) }
end
send_to(target, view_context) click to toggle source
# File lib/generic_view_mapper/view/attribute.rb, line 20
def send_to(target, view_context)
  name.to_s.split('.').inject(target) do |obj, method|
    if view_context.respond_to?(method)
      view_context.public_send(method)
    else
      obj.public_send(method)
    end
  end
end