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
Append the argument to the Array, changes the Array itself.
-
#[]=(key, value) ⇒ Object
Updating of single items.
-
#initialize(work_on:, work_with:) ⇒ Array
constructor
Initialisation method stores the model-instance to work on in @orient.
- #method_missing(*args) ⇒ Object
- #record ⇒ Object
-
#remove(*item) ⇒ Object
Remove performs Array#delete .
-
#remove_at(*pos) ⇒ Object
Remove_at performs Array#delete_at.
-
#where(*item) ⇒ Object
just works with Hashes as parameters.
Methods included from Support
#compose_where, #generate_sql_list
Methods inherited from Array
#analyse, #from_orient, #to_orient
Constructor Details
#initialize(work_on:, work_with:) ⇒ Array
Initialisation method stores the model-instance to work on in @orient.
The keyword_parameter "work_on" holds the record to work_ion.
Ihe second argument is the array to work with
If instead of a model-instance the model-class is provided, a new model-instance is created and returned
Its up to the caller to save the new instance in the database
Further a list of array-elements is expected, which are forwarded (as Array) to Array
20 21 22 23 24 25 26 27 28 |
# File 'lib/orient.rb', line 20 def initialize work_on:, work_with: @orient = work_on.class == Class ? work_on.new : work_on super work_with @name = @orient.attributes.key(self) # puts "ORIENT: #{@orient.inspect} " @name = yield if @name.nil? && block_given? # puts "NAME: #{@name.inspect}" # puts "SELF: #{self.inspect}" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/orient.rb', line 91 def method_missing *args map{|x| x.send *args } rescue NoMethodError => e logger.progname = "OrientSupport::Array#MethodMissing" logger.error{"Undefined method: #{e.message}"} end |
Instance Method Details
#<<(*arg) ⇒ Object
Append the argument to the Array, changes the Array itself.
The change is transmitted to the database immediately
38 39 40 41 |
# File 'lib/orient.rb', line 38 def << *arg @orient.add_item_to_property(@name, *arg) if @name.present? super end |
#[]=(key, value) ⇒ Object
Updating of single items
This only works if the hole Array is previously loaded into the Ruby-array.
49 50 51 52 |
# File 'lib/orient.rb', line 49 def []= key, value super @orient.update set: {@name => self} if @name.present? end |
#record ⇒ Object
30 31 32 |
# File 'lib/orient.rb', line 30 def record @orient end |
#remove(*item) ⇒ Object
Remove performs Array#delete
If the Array-element is a link, this is removed, the linked table is untouched
73 74 75 |
# File 'lib/orient.rb', line 73 def remove *item @orient.remove_item_from_property(@name,*item) if @name.present? end |
#remove_at(*pos) ⇒ Object
Remove_at performs Array#delete_at
62 63 64 |
# File 'lib/orient.rb', line 62 def remove_at *pos @orient.remove_position_from_property(@name,*pos) if @name.present? end |
#where(*item) ⇒ Object
just works with Hashes as parameters
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/orient.rb', line 78 def where *item where_string = item.map{|m| where_string = compose_where( m ) }.join(' and ') subquery= OrientSupport::OrientQuery.new from: @orient, projection: "expand( #{@name})" q= OrientSupport::OrientQuery.new from: subquery, where: item # query = "SELECT FROM ( SELECT EXPAND( #{@name} ) FROM #{@orient.classname}) #{where_string} " # puts q.compose # sql_cmd = -> (command) {{ type: "cmd", language: "sql", command: command }} # @orient.orientdb.execute do # sql_cmd[query.to_s] # end @orient.query q end |