Class: OrientSupport::Hash

Inherits:
Hash show all
Includes:
Support
Defined in:
lib/support/orient.rb

Overview

WithIndifferentAccess

Instance Method Summary collapse

Methods included from Support

#compose_where, #generate_sql_list

Methods inherited from Hash

#coerce, #from_orient, #to_human, #to_or, #to_orient

Constructor Details

#initialize(modelinstance, args) ⇒ Hash

Returns a new instance of Hash.



126
127
128
129
130
131
132
133
134
135
# File 'lib/support/orient.rb', line 126

def initialize modelinstance, args
	super()
#	puts "Hash.new args #{args}"
	@orient = modelinstance
	self.merge! args
	@name = modelinstance.attributes.key(self)
	@name =  yield if @name.nil? && block_given?
#	puts "@name #{@name}"
	self
end

Instance Method Details

#[]=(k, v) ⇒ Object



138
139
140
# File 'lib/support/orient.rb', line 138

def []=  k, v
	 @orient.update { "#{@name.to_s}.#{k.to_s} = #{v.to_or}" }
end

#append(arg) ⇒ Object Also known as: <<

Inserts the provided Hash to the (possibly emty) list-property and returns a hash



143
144
145
146
147
148
# File 'lib/support/orient.rb', line 143

def append arg
	# the argument is simply provided as JSON-parameter to »update«
	# generated query: update {rrid} set { @name } = { arg.to_json } return after @this
	# todo : consider returning a OrientSuport::Hash
	@orient.update { "#{@name.to_s} = "+ arg.to_json }[@name]
end

#delete_if(&b) ⇒ Object

end



172
173
174
175
176
# File 'lib/support/orient.rb', line 172

def delete_if &b
	super &b
	@orient.update set:{ @name => self}

end

#remove(*k) ⇒ Object

removes a key-value entry from the hash.

parameter: list of key’s (duplicate values are removed)



155
156
157
158
# File 'lib/support/orient.rb', line 155

def remove *k
	# todo combine queries in a transaction
	k.map{ |key| @orient.update( remove: true ) { "#{@name.to_s}.#{key} " } }.last
end