Module: Zena::Remote::Interface::Read::ClassMethods
- Included in:
- ClassMethods
- Defined in:
- lib/zena/remote/interface.rb
Overview
Used by connection.find(…)
Instance Method Summary collapse
- #all(query = nil, options = {}) ⇒ Object
- #count(query = nil, options = {}) ⇒ Object
- #find_url ⇒ Object
- #first(query = nil, options = {}) ⇒ Object
- #get(*args) ⇒ Object
- #process_find(count, query, options = {}) ⇒ Object
Instance Method Details
#all(query = nil, options = {}) ⇒ Object
108 109 110 |
# File 'lib/zena/remote/interface.rb', line 108 def all(query = nil, = {}) process_find(:all, query, ) end |
#count(query = nil, options = {}) ⇒ Object
116 117 118 |
# File 'lib/zena/remote/interface.rb', line 116 def count(query = nil, = {}) process_find(:count, query, ) end |
#find_url ⇒ Object
74 75 76 |
# File 'lib/zena/remote/interface.rb', line 74 def find_url "/nodes/search" end |
#first(query = nil, options = {}) ⇒ Object
112 113 114 |
# File 'lib/zena/remote/interface.rb', line 112 def first(query = nil, = {}) process_find(:first, query, ) end |
#get(*args) ⇒ Object
78 79 80 |
# File 'lib/zena/remote/interface.rb', line 78 def get(*args) @connection.get(*args) end |
#process_find(count, query, options = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/zena/remote/interface.rb', line 82 def process_find(count, query, = {}) if query.kind_of?(Hash) query = query.symbolize_keys klass = query.delete(:class) || @name query_args = [] query.each do |key, value| query_args << "#{key} = #{Zena::Db.quote(value)}" end query = "nodes where class like #{klass} and #{query_args.join(' and ')} in site" elsif query.kind_of?(String) # query must be a filter query = "nodes where class like #{@name} and #{query} in site" elsif query.kind_of?(Fixnum) # query is an id query = "nodes where class like #{@name} and id = #{query} in site" else # no filter query = "nodes where class like #{@name} in site" end super(count, query, ) end |