Class: Lightrail::Wrapper::Associations::HasOneConfig

Inherits:
AssociationConfig show all
Defined in:
lib/lightrail/wrapper/associations.rb

Instance Attribute Summary

Attributes inherited from AssociationConfig

#as, #includes, #key, #name

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ HasOneConfig

Returns a new instance of HasOneConfig.



23
24
25
26
27
28
# File 'lib/lightrail/wrapper/associations.rb', line 23

def initialize(name, options)
  super
  @as          = options[:as] || name.to_s.pluralize.to_sym
  @key         = options[:key] || :"#{name}_id"
  @includes    = options[:includes] || name.to_s.pluralize
end

Instance Method Details

#update(view, object) ⇒ Object



30
31
32
# File 'lib/lightrail/wrapper/associations.rb', line 30

def update(view, object)
  view[@key] = object && object.id
end