Class: OrientSupport::Array
- Includes:
- Support
- Defined in:
- lib/orient.rb
Overview
This Module fences specialized ruby objects
Direct Known Subclasses
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #[](*arg) ⇒ Object
-
#[]=(key, value) ⇒ Object
Updating of single items.
- #delete(*item) ⇒ Object
- #delete_at(*pos) ⇒ Object
- #delete_if ⇒ Object
-
#initialize(modelinstance, *args) ⇒ Array
constructor
Initialisation method stores the modelinstance in @orient.
- #method_missing(*args) ⇒ Object
- #where(*item) ⇒ Object
Methods included from Support
#compose_where, #generate_sql_list
Methods inherited from Array
Constructor Details
#initialize(modelinstance, *args) ⇒ Array
Initialisation method stores the modelinstance in @orient.
Further a list of array-elements is expected, which are forwarded (as Array) to Array
15 16 17 18 19 20 |
# File 'lib/orient.rb', line 15 def initialize modelinstance, *args @orient = modelinstance super args @name = modelinstance.attributes.key(self) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
76 77 78 |
# File 'lib/orient.rb', line 76 def method_missing *args map{|x| x.send args.first } end |
Instance Method Details
#<<(arg) ⇒ Object
22 23 24 25 |
# File 'lib/orient.rb', line 22 def << arg @orient.add_item_to_property( @name, arg ) if @name.present? super end |
#[](*arg) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/orient.rb', line 38 def [] *arg # puts "[] ARG: #{arg.inspect}" # arg.each{|u| puts "[] #{u.inspect} : #{u.class} " } super end |
#[]=(key, value) ⇒ Object
Updating of single items
this only works if the hole embedded Array is previosly loaded into the ruby-array.
33 34 35 36 |
# File 'lib/orient.rb', line 33 def []= key, value super @orient.update set: { @name => self } if @name.present? end |
#delete(*item) ⇒ Object
64 65 66 |
# File 'lib/orient.rb', line 64 def delete *item @orient.remove_item_from_property( @name ) { item } if @name.present? end |
#delete_at(*pos) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/orient.rb', line 45 def delete_at *pos if @name.present? delete self[*pos] else super end # old version: works only if the hole array is loaded into memory # self[*pos]=nil # @orient.update set:{ @name => self.compact } end |
#delete_if ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/orient.rb', line 56 def delete_if if @name.present? delete *self.map{|y| y if yield(y) }.compact # if the block returns true then delete the item else super end end |
#where(*item) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/orient.rb', line 68 def where *item where_string = item.map{|m| where_string = compose_where m }.join( ' and ' ) query = "select from ( select expand( #{@name} ) from #{@orient.classname}) #{where_string} " puts query @orient.query query end |