Class: RhoSources
- Inherits:
-
Object
- Object
- RhoSources
- Defined in:
- lib/rho-sources.rb
Instance Method Summary collapse
- #create(user, data = nil) ⇒ Object
- #delete(user, data = nil) ⇒ Object
- #delete_all(user) ⇒ Object
- #evalue_condition(content, conditions) ⇒ Object
- #find(user, *args) ⇒ Object
- #get_key(key) ⇒ Object
-
#initialize(source_name, token) ⇒ RhoSources
constructor
A new instance of RhoSources.
- #name ⇒ Object
- #truncate(user) ⇒ Object
- #undefined_arg ⇒ Object
- #user_not_nil ⇒ Object
Constructor Details
#initialize(source_name, token) ⇒ RhoSources
Returns a new instance of RhoSources.
7 8 9 10 11 |
# File 'lib/rho-sources.rb', line 7 def initialize(source_name,token) @name = source_name @token = token RhoApiConnect.set_token(token) end |
Instance Method Details
#create(user, data = nil) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/rho-sources.rb', line 44 def create(user, data = nil) unless user.nil? or user.empty? result = RhoApiConnect.push_objects(user,@name,data) else user_not_nil end end |
#delete(user, data = nil) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/rho-sources.rb', line 52 def delete(user, data = nil) unless user.nil? or user.empty? result = RhoApiConnect.push_deletes(user,@name,data) else user_not_nil end end |
#delete_all(user) ⇒ Object
60 61 62 |
# File 'lib/rho-sources.rb', line 60 def delete_all(user) truncate(user) end |
#evalue_condition(content, conditions) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rho-sources.rb', line 77 def evalue_condition(content,conditions) return true if conditions.nil? sw = true conditions.each do |key,value| if content[get_key(key)] != value sw = false end end if conditions.class == Hash sw end |
#find(user, *args) ⇒ Object
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 |
# File 'lib/rho-sources.rb', line 17 def find(user, *args) new_result = {} unless user.nil? or user.empty? result = RhoApiConnect.get_db_doc_by_type(user,@name,"md") unless args.empty? if args[0][:conditions].nil? undefined_arg return nil end result.each do |object,content| content[:object] = object if evalue_condition(content,args[0][:conditions]) new_result[object] = content end end result = nil new_result else result end else user_not_nil end end |
#get_key(key) ⇒ Object
72 73 74 75 |
# File 'lib/rho-sources.rb', line 72 def get_key(key) return key if key == :object return key.to_s end |
#name ⇒ Object
13 14 15 |
# File 'lib/rho-sources.rb', line 13 def name @name end |
#truncate(user) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/rho-sources.rb', line 64 def truncate(user) unless user.nil? or user.empty? result = RhoApiConnect.set_db_doc_by_type(user,@name,"","md") else user_not_nil end end |
#undefined_arg ⇒ Object
93 94 95 96 |
# File 'lib/rho-sources.rb', line 93 def undefined_arg puts "undefined argument !!" nil end |
#user_not_nil ⇒ Object
88 89 90 91 |
# File 'lib/rho-sources.rb', line 88 def user_not_nil puts "user name can not be nil or empty" nil end |