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
- #name ⇒ Object
- #polymorphic ⇒ Object
-
#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?)
- #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? ⇒ 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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 14 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] end |
Instance Attribute Details
#class_name ⇒ Object
59 60 61 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 59 def class_name (@class_name || calculate_class_name).to_s end |
#find_with ⇒ Object
Returns the value of attribute find_with.
11 12 13 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 11 def find_with @find_with end |
#foreign_key ⇒ Object
42 43 44 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 42 def foreign_key (@foreign_key || calculate_foreign_key).to_s end |
#name ⇒ Object
30 31 32 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 30 def name @name.to_s if @name end |
#polymorphic ⇒ Object
86 87 88 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 86 def polymorphic !!@polymorphic end |
#records_starts_from ⇒ Object
Returns the value of attribute records_starts_from.
12 13 14 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 12 def records_starts_from @records_starts_from end |
#relation_type ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 34 def relation_type if @relation_type relation_type = @relation_type.to_s relation_type += "_polymorphic" if polymorphic? relation_type end end |
#store_in ⇒ Object
67 68 69 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 67 def store_in @store_in.to_s if @store_in end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
100 101 102 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 100 def ==(other) other.instance_of?(self.class) && other.hash == hash end |
#foreign_key_setter ⇒ Object
46 47 48 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 46 def foreign_key_setter foreign_key+'=' end |
#hash ⇒ Object
105 106 107 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 105 def hash name.hash end |
#new_relation_proxy(proxy_owner) ⇒ Object
95 96 97 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 95 def new_relation_proxy(proxy_owner) proxy_class_name.constantize.new(:proxy_owner => proxy_owner, :metadata => self) end |
#persisting_foreign_key? ⇒ Boolean
81 82 83 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 81 def persisting_foreign_key? !!store_in && !records_starts_from end |
#polymorphic? ⇒ Boolean
90 91 92 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 90 def polymorphic? polymorphic end |
#polymorphic_type_column ⇒ Object
50 51 52 53 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 50 def polymorphic_type_column type_column = foreign_key.gsub(/_id$/, '') type_column + "_type" end |
#polymorphic_type_column_setter ⇒ Object
55 56 57 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 55 def polymorphic_type_column_setter polymorphic_type_column+'=' end |
#proxy_target_class ⇒ Object
63 64 65 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 63 def proxy_target_class class_name.constantize end |
#represents_a_collection? ⇒ Boolean
111 112 113 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 111 def represents_a_collection? relation_type == 'references_many' end |
#store_foreign_key_in ⇒ Object
71 72 73 74 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 71 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
76 77 78 79 |
# File 'lib/massive_record/orm/relations/metadata.rb', line 76 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 |