Module: Dynomite::Associations::Association
- Included in:
- ManyAssociation, SingleAssociation
- Defined in:
- lib/dynomite/associations/association.rb
Instance Attribute Summary collapse
-
#loaded ⇒ Object
Returns the value of attribute loaded.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #coerce_to_id(object) ⇒ Object
- #coerce_to_item(object) ⇒ Object
- #declaration_field_name ⇒ Object
- #declaration_field_type ⇒ Object
- #find_target ⇒ Object
-
#initialize(source, name, options) ⇒ Dynomite::Association
Create a new association.
- #loaded? ⇒ Boolean
- #reader_target ⇒ Object
- #reset ⇒ Object
- #target ⇒ Object
Instance Attribute Details
#loaded ⇒ Object
Returns the value of attribute loaded.
7 8 9 |
# File 'lib/dynomite/associations/association.rb', line 7 def loaded @loaded end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/dynomite/associations/association.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/dynomite/associations/association.rb', line 7 def @options end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/dynomite/associations/association.rb', line 7 def source @source end |
Instance Method Details
#coerce_to_id(object) ⇒ Object
27 28 29 |
# File 'lib/dynomite/associations/association.rb', line 27 def coerce_to_id(object) object.respond_to?(:partition_key) ? object.partition_key : object end |
#coerce_to_item(object) ⇒ Object
31 32 33 |
# File 'lib/dynomite/associations/association.rb', line 31 def coerce_to_item(object) object.is_a?(String) ? target_class.find(object) : object end |
#declaration_field_name ⇒ Object
59 60 61 |
# File 'lib/dynomite/associations/association.rb', line 59 def declaration_field_name "#{name}_ids" end |
#declaration_field_type ⇒ Object
63 64 65 |
# File 'lib/dynomite/associations/association.rb', line 63 def declaration_field_type :set end |
#find_target ⇒ Object
39 |
# File 'lib/dynomite/associations/association.rb', line 39 def find_target; end |
#initialize(source, name, options) ⇒ Dynomite::Association
Create a new association.
20 21 22 23 24 25 |
# File 'lib/dynomite/associations/association.rb', line 20 def initialize(source, name, ) @source = source @name = name @options = @loaded = false end |
#loaded? ⇒ Boolean
35 36 37 |
# File 'lib/dynomite/associations/association.rb', line 35 def loaded? @loaded end |
#reader_target ⇒ Object
50 51 52 |
# File 'lib/dynomite/associations/association.rb', line 50 def reader_target self end |
#reset ⇒ Object
54 55 56 57 |
# File 'lib/dynomite/associations/association.rb', line 54 def reset @target = nil @loaded = false end |
#target ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dynomite/associations/association.rb', line 41 def target unless loaded? @target = find_target @loaded = true end @target end |