Class: ActiveMocker::HasOne

Inherits:
SingleRelation show all
Defined in:
lib/active_mocker/mock/has_one.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SingleRelation

#assign_associations

Constructor Details

#initialize(item, child_self:, foreign_key:) ⇒ HasOne

Returns a new instance of HasOne.



6
7
8
9
# File 'lib/active_mocker/mock/has_one.rb', line 6

def initialize(item, child_self:, foreign_key:)
  item.send(:write_attribute, foreign_key, item.try(:id)) unless item.try(:id).nil?
  super
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



4
5
6
# File 'lib/active_mocker/mock/has_one.rb', line 4

def item
  @item
end