Class: Pupa::ForeignObject
- Inherits:
-
Object
- Object
- Pupa::ForeignObject
- Extended by:
- Forwardable
- Includes:
- Concerns::IndifferentAccess
- Defined in:
- lib/pupa/models/foreign_object.rb
Overview
A minimal model for a foreign object.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#foreign_keys ⇒ Object
readonly
Returns the value of attribute foreign_keys.
Instance Method Summary collapse
-
#initialize(properties = {}) ⇒ ForeignObject
constructor
A new instance of ForeignObject.
-
#to_h ⇒ Object
Constructor Details
#initialize(properties = {}) ⇒ ForeignObject
Returns a new instance of ForeignObject.
11 12 13 14 15 16 |
# File 'lib/pupa/models/foreign_object.rb', line 11 def initialize(properties = {}) hash = symbolize_keys(properties) value = hash.delete(:foreign_keys) || {} @attributes = hash.merge(value) @foreign_keys = value.keys end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/pupa/models/foreign_object.rb', line 7 def attributes @attributes end |
#foreign_keys ⇒ Object (readonly)
Returns the value of attribute foreign_keys.
7 8 9 |
# File 'lib/pupa/models/foreign_object.rb', line 7 def foreign_keys @foreign_keys end |
Instance Method Details
#to_h ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/pupa/models/foreign_object.rb', line 18 def to_h {}.tap do |hash| attributes.each do |property,value| if value == false || value.present? hash[property] = value end end end end |