Module: OrientDB::AR::Relations
- Defined in:
- lib/orientdb-ar/relations.rb,
lib/orientdb-ar/relations/links_one.rb,
lib/orientdb-ar/relations/links_many.rb,
lib/orientdb-ar/relations/embedds_one.rb,
lib/orientdb-ar/relations/embedds_many.rb
Instance Method Summary collapse
- #embedds_many(klass_name, options = { }) ⇒ Object
- #embedds_one(klass_name, options = { }) ⇒ Object
- #links_many(klass_name, options = { }) ⇒ Object
- #links_one(klass_name, options = { }) ⇒ Object
Instance Method Details
#embedds_many(klass_name, options = { }) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/orientdb-ar/relations/embedds_many.rb', line 4 def (klass_name, = { }) klass_name, = klass_name, , :plural, [] name = [:name] relationships[name] = .merge :type => :embedds_many, :class_name => klass_name field name, [OrientDB::FIELD_TYPES[:embedded_list], OrientDB::AR::Base.oclass_name_for(klass_name)] class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name} # def address self[:#{name}] || #{[:default].inspect} # self[:address] || nil end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name}=(value) # def addresses=(value) self[:#{name}] = value # self[:addresses] = value end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def add_#{name.singularize}(value) # def add_address(value) self[:#{name}] ||= #{[:default].inspect} # self[:addresses] ||= [] self[:#{name}] << self.class.to_orientdb(value) # self[:addresses] << self.class.to_orientdb(value) #{name} # addresses end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def build_#{name}(fields = {}) # def build_address(fields = {}) add_#{name} #{klass_name}.new fields # self[:addresses] = Address.new fields end # end eorb end |
#embedds_one(klass_name, options = { }) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/orientdb-ar/relations/embedds_one.rb', line 4 def (klass_name, = { }) klass_name, = klass_name, , :singular name = [:name] relationships[name] = .merge :type => :embedds_one, :class_name => klass_name field name, [OrientDB::FIELD_TYPES[:embedded], OrientDB::AR::Base.oclass_name_for(klass_name)] class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name} # def address self[:#{name}] || #{[:default].inspect} # self[:address] || nil end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name}=(value) # def addresses=(value) self[:#{name}] = value # self[:addresses] = value end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def build_#{name}(fields = {}) # def build_address(fields = {}) self[:#{name}] = #{klass_name}.new fields # self[:addresses] = Address.new fields #{name} # address end # end eorb end |
#links_many(klass_name, options = { }) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/orientdb-ar/relations/links_many.rb', line 4 def links_many(klass_name, = { }) klass_name, = klass_name, , :plural, [] name = [:name] relationships[name] = .merge :type => :links_many, :class_name => klass_name field name, [OrientDB::FIELD_TYPES[:link_list], OrientDB::AR::Base.oclass_name_for(klass_name)] class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name} # def address self[:#{name}] || #{[:default].inspect} # self[:address] || nil end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name}=(value) # def addresses=(value) self[:#{name}] = value # self[:addresses] = value end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def add_#{name.singularize}(value) # def add_address(value) self[:#{name}] ||= #{[:default].inspect} # self[:addresses] ||= [] self[:#{name}] << self.class.to_orientdb(value) # self[:addresses] << self.class.to_orientdb(value) #{name} # addresses end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def build_#{name}(fields = {}) # def build_address(fields = {}) add_#{name} #{klass_name}.new fields # self[:addresses] = Address.new fields end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def create_#{name}(fields = {}) # def create_address(fields = {}) add_#{name} #{klass_name}.create fields # self[:addresses] = Address.create fields end # end eorb end |
#links_one(klass_name, options = { }) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/orientdb-ar/relations/links_one.rb', line 4 def links_one(klass_name, = { }) klass_name, = klass_name, , :singular puts "links_one : #{klass_name} : #{.inspect}" name = [:name] relationships[name] = .merge :type => :links_one, :class_name => klass_name field name, [OrientDB::FIELD_TYPES[:link], OrientDB::AR::Base.oclass_name_for(klass_name)] class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name} # def address self[:#{name}] || #{[:default].inspect} # self[:address] || nil end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def #{name}=(value) # def addresses=(value) self[:#{name}] = value # self[:addresses] = value end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def build_#{name}(fields = {}) # def build_address(fields = {}) self[:#{name}] = #{klass_name}.new fields # self[:addresses] = Address.create fields #{name} # address end # end eorb class_eval <<-eorb, __FILE__, __LINE__ + 1 def create_#{name}(fields = {}) # def create_address(fields = {}) self[:#{name}] = #{klass_name}.create fields # self[:addresses] = Address.create fields #{name} # address end # end eorb end |