Module: V2::Features::RelatableObject::InstanceMethods
- Defined in:
- lib/familia/features/relatable_objects.rb
Instance Method Summary collapse
-
#extid ⇒ Object
(also: #external_identifier)
-
#init ⇒ Object
We lazily generate the object ID and external ID when they are first accessed so that we can instantiate and load existing objects, without eagerly generating them, only to be overridden by the storage layer.
-
#objid ⇒ Object
(also: #relatable_objid)
-
#owned? ⇒ Boolean
-
#owner?(related_object) ⇒ Boolean
Check if the given customer is the owner of this domain.
Instance Method Details
#extid ⇒ Object Also known as: external_identifier
58 59 60 61 62 63 |
# File 'lib/familia/features/relatable_objects.rb', line 58 def extid @extid ||= begin # lazy loader generated_id = self.class.generate_extid self.extid = generated_id end end |
#init ⇒ Object
We lazily generate the object ID and external ID when they are first accessed so that we can instantiate and load existing objects, without eagerly generating them, only to be overridden by the storage layer.
41 42 43 44 45 |
# File 'lib/familia/features/relatable_objects.rb', line 41 def init super if defined?(super) # Only call if parent has init @api_version ||= 'v2' end |
#objid ⇒ Object Also known as: relatable_objid
47 48 49 50 51 52 53 54 55 |
# File 'lib/familia/features/relatable_objects.rb', line 47 def objid @objid ||= begin # lazy loader generated_id = self.class.generate_objid # Using the attr_writer method ensures any future Familia # enhancements to the setter are properly invoked (as opposed # to directly assigning @objid). self.objid = generated_id end end |
#owned? ⇒ Boolean
80 81 82 83 84 85 86 |
# File 'lib/familia/features/relatable_objects.rb', line 80 def owned? # We can only have an owner if we are relatable ourselves. return false unless is_a?(RelatableObject) # If our object identifier is present, we have an owner self.class.owners.key?(objid) end |
#owner?(related_object) ⇒ Boolean
Check if the given customer is the owner of this domain
70 71 72 73 74 75 76 77 78 |
# File 'lib/familia/features/relatable_objects.rb', line 70 def owner?() self.class.relatable?() do # Check the hash (our objid => related_object's objid) owner_objid = self.class.owners.get(objid).to_s return false if owner_objid.empty? owner_objid.eql?(.objid) end end |