Class: InventoryRefresh::InventoryCollection::Reference
- Inherits:
-
Object
- Object
- InventoryRefresh::InventoryCollection::Reference
- Defined in:
- lib/inventory_refresh/inventory_collection/reference.rb
Instance Attribute Summary collapse
-
#full_reference ⇒ Object
readonly
Returns the value of attribute full_reference.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#stringified_reference ⇒ Object
readonly
Returns the value of attribute stringified_reference.
Class Method Summary collapse
-
.build_stringified_reference(hash, keys) ⇒ String
Builds string uuid from passed Hash and keys.
-
.build_stringified_reference_for_record(record, keys) ⇒ String
Builds string uuid from passed Object and keys.
-
.stringify_reference(reference) ⇒ String
Returns passed array joined by stringify_joiner.
Instance Method Summary collapse
-
#initialize(data, ref, keys) ⇒ Reference
constructor
A new instance of Reference.
- #loadable? ⇒ Boolean
- #nested_secondary_index? ⇒ Boolean
-
#primary? ⇒ Boolean
Return true if reference is to primary index, false otherwise.
Constructor Details
#initialize(data, ref, keys) ⇒ Reference
Returns a new instance of Reference.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 14 def initialize(data, ref, keys) @full_reference = build_full_reference(data, keys) @ref = ref @keys = keys @nested_secondary_index = keys.select { |key| full_reference[key].kind_of?(InventoryRefresh::InventoryObjectLazy) }.any? do |key| !full_reference[key].primary? end @stringified_reference = self.class.build_stringified_reference(full_reference, keys) end |
Instance Attribute Details
#full_reference ⇒ Object (readonly)
Returns the value of attribute full_reference.
6 7 8 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 6 def full_reference @full_reference end |
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
6 7 8 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 6 def keys @keys end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
6 7 8 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 6 def ref @ref end |
#stringified_reference ⇒ Object (readonly)
Returns the value of attribute stringified_reference.
6 7 8 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 6 def stringified_reference @stringified_reference end |
Class Method Details
.build_stringified_reference(hash, keys) ⇒ String
Builds string uuid from passed Hash and keys
48 49 50 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 48 def build_stringified_reference(hash, keys) stringify_reference(keys.map { |attribute| hash[attribute].to_s }) end |
.build_stringified_reference_for_record(record, keys) ⇒ String
Builds string uuid from passed Object and keys
57 58 59 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 57 def build_stringified_reference_for_record(record, keys) stringify_reference(keys.map { |attribute| record.public_send(attribute).to_s }) end |
.stringify_reference(reference) ⇒ String
Returns passed array joined by stringify_joiner
65 66 67 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 65 def stringify_reference(reference) reference.join(stringify_joiner) end |
Instance Method Details
#loadable? ⇒ Boolean
38 39 40 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 38 def loadable? keys.any? { |attribute| full_reference[attribute].present? } end |
#nested_secondary_index? ⇒ Boolean
34 35 36 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 34 def nested_secondary_index? nested_secondary_index end |
#primary? ⇒ Boolean
Return true if reference is to primary index, false otherwise. Reference is primary, only if all the nested references are primary.
30 31 32 |
# File 'lib/inventory_refresh/inventory_collection/reference.rb', line 30 def primary? ref == :manager_ref && !nested_secondary_index end |