Class: Yaks::Mapper::Attribute

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Util
Includes:
Util
Defined in:
lib/yaks/mapper/attribute.rb

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(name, options = {}, &block) ⇒ Object



7
8
9
# File 'lib/yaks/mapper/attribute.rb', line 7

def self.create(name, options = {}, &block)
  new(options.merge(name: name, block: block))
end

Instance Method Details

#add_to_resource(resource, mapper, _context) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/yaks/mapper/attribute.rb', line 11

def add_to_resource(resource, mapper, _context)
  return resource unless Resolve(self.if, mapper)

  if block
    attribute = Resolve(block, mapper)
  else
    attribute = mapper.load_attribute(name)
  end

  resource.merge_attributes(name => attribute)
end