Class: MassiveRecord::ORM::Relations::Metadata
- Inherits:
-
Object
- Object
- MassiveRecord::ORM::Relations::Metadata
- Defined in:
- lib/massive_record/orm/relations/metadata.rb
Overview
The master of metadata related to a relation. For instance; references_one :employee, :foreign_key => “person_id”, :class_name => “Person”
Instance Attribute Summary collapse
- #class_name ⇒ Object
-
#find_with ⇒ Object
Returns the value of attribute find_with.
- #foreign_key ⇒ Object
- #inverse_of ⇒ Object
- #name ⇒ Object
-
#owner_class ⇒ Object
Returns the value of attribute owner_class.
- #polymorphic ⇒ Object (also: #polymorphic?)
-
#records_starts_from ⇒ Object
Returns the value of attribute records_starts_from.
- #relation_type ⇒ Object
- #store_in ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #embedded ⇒ Object (also: #embedded?)
- #embedded_in ⇒ Object (also: #embedded_in?)
- #foreign_key_setter ⇒ Object
- #hash ⇒ Object
-
#initialize(name, options = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #new_relation_proxy(proxy_owner) ⇒ Object
- #persisting_foreign_key? ⇒ Boolean
- #polymorphic_type_column ⇒ Object
- #polymorphic_type_column_setter ⇒ Object
- #proxy_target_class ⇒ Object
- #represents_a_collection? ⇒ Boolean
- #store_foreign_key_in ⇒ Object
- #store_foreign_key_in=(column_family) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Metadata
Returns a new instance of Metadata.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 19 def initialize(name, = {}) . self.name = name self.foreign_key = [:foreign_key] if .has_key? :store_in self.store_in = [:store_in] elsif .has_key? :store_foreign_key_in self.store_foreign_key_in = [:store_foreign_key_in] end self.class_name = [:class_name] self.find_with = [:find_with] self.records_starts_from = [:records_starts_from] if [:records_starts_from] self.polymorphic = [:polymorphic] self.inverse_of = [:inverse_of] end |
Instance Attribute Details
#class_name ⇒ Object
65 66 67 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 65 def class_name (@class_name || calculate_class_name).to_s end |
#find_with ⇒ Object
Returns the value of attribute find_with.
16 17 18 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 16 def find_with @find_with end |
#foreign_key ⇒ Object
48 49 50 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 48 def foreign_key (@foreign_key || calculate_foreign_key).to_s end |
#inverse_of ⇒ Object
69 70 71 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 69 def inverse_of (@inverse_of || calculate_inverse_of).to_s end |
#name ⇒ Object
36 37 38 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 36 def name @name.to_s if @name end |
#owner_class ⇒ Object
Returns the value of attribute owner_class.
16 17 18 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 16 def owner_class @owner_class end |
#polymorphic ⇒ Object Also known as: polymorphic?
97 98 99 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 97 def polymorphic !!@polymorphic end |
#records_starts_from ⇒ Object
Returns the value of attribute records_starts_from.
17 18 19 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 17 def records_starts_from @records_starts_from end |
#relation_type ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 40 def relation_type if @relation_type relation_type = @relation_type.to_s relation_type += "_polymorphic" if polymorphic? relation_type end end |
#store_in ⇒ Object
77 78 79 80 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 77 def store_in return @store_in.to_s if @store_in @store_in = name if end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
118 119 120 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 118 def ==(other) other.instance_of?(self.class) && other.hash == hash end |
#embedded ⇒ Object Also known as: embedded?
102 103 104 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 102 def relation_type == "embeds_many" end |
#embedded_in ⇒ Object Also known as: embedded_in?
107 108 109 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 107 def relation_type == "embedded_in" || relation_type == "embedded_in_polymorphic" end |
#foreign_key_setter ⇒ Object
52 53 54 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 52 def foreign_key_setter foreign_key+'=' end |
#hash ⇒ Object
123 124 125 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 123 def hash name.hash end |
#new_relation_proxy(proxy_owner) ⇒ Object
113 114 115 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 113 def new_relation_proxy(proxy_owner) proxy_class_name.constantize.new(:proxy_owner => proxy_owner, :metadata => self) end |
#persisting_foreign_key? ⇒ Boolean
92 93 94 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 92 def persisting_foreign_key? ! && !!store_in && !records_starts_from end |
#polymorphic_type_column ⇒ Object
56 57 58 59 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 56 def polymorphic_type_column type_column = foreign_key.gsub(/_id$/, '') type_column + "_type" end |
#polymorphic_type_column_setter ⇒ Object
61 62 63 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 61 def polymorphic_type_column_setter polymorphic_type_column+'=' end |
#proxy_target_class ⇒ Object
73 74 75 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 73 def proxy_target_class class_name.constantize end |
#represents_a_collection? ⇒ Boolean
129 130 131 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 129 def represents_a_collection? %w(references_many embeds_many).include? relation_type end |
#store_foreign_key_in ⇒ Object
82 83 84 85 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 82 def store_foreign_key_in ActiveSupport::Deprecation.warn("store_foreign_key_in is deprecated. Use store_in instead!") store_in end |
#store_foreign_key_in=(column_family) ⇒ Object
87 88 89 90 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 87 def store_foreign_key_in=(column_family) ActiveSupport::Deprecation.warn("store_foreign_key_in is deprecated. Use store_in instead!") self.store_in = column_family end |