Module: Loggly::RemoteModel::ClassMethods
- Included in:
- Loggly::RemoteModel
- Defined in:
- lib/loggly/remote_model.rb
Instance Attribute Summary collapse
-
#resource_attributes ⇒ Object
readonly
Returns the value of attribute resource_attributes.
Instance Method Summary collapse
- #all(conditions = {}, options = {}, &callback) ⇒ Object
- #collection_name ⇒ Object
- #create!(attributes = {}, options = {}, &callback) ⇒ Object
- #find(id, options = {}, &callback) ⇒ Object
- #index_method ⇒ Object
- #path_base(params = {}) ⇒ Object
- #path_ext ⇒ Object
- #prepare_params(conditions = {}, options = {}) ⇒ Object
- #set_resource_attributes(ra) ⇒ Object
- #where(conditions = {}, options = {}, &callback) ⇒ Object
Instance Attribute Details
#resource_attributes ⇒ Object (readonly)
Returns the value of attribute resource_attributes.
16 17 18 |
# File 'lib/loggly/remote_model.rb', line 16 def resource_attributes @resource_attributes end |
Instance Method Details
#all(conditions = {}, options = {}, &callback) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/loggly/remote_model.rb', line 32 def all(conditions = {}, = {}, &callback) = .merge(:klass => self) params = conditions params[:size] = ([:per_page] ||= @resource_attributes[:per_page]) params[:page] = ([:page] ||= 0) response = Request.new(@resource_attributes, :get, [path_base, index_method], path_ext, params, ).execute(Loggly.connection) models = response.to_models callback.call(models) if callback models end |
#collection_name ⇒ Object
20 |
# File 'lib/loggly/remote_model.rb', line 20 def collection_name;@resource_attributes[:collection_name];end |
#create!(attributes = {}, options = {}, &callback) ⇒ Object
73 74 75 |
# File 'lib/loggly/remote_model.rb', line 73 def create!(attributes = {}, = {}, &callback) raise NotImplementedError end |
#find(id, options = {}, &callback) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/loggly/remote_model.rb', line 62 def find(id, = {}, &callback) .merge(:klass => self) response = Request.new(@resource_attributes, :get, [path_base, id.to_s], path_ext, {}, ).execute(Loggly.connection) model = response.to_model callback.call(models) if callback model end |
#index_method ⇒ Object
19 |
# File 'lib/loggly/remote_model.rb', line 19 def index_method;@resource_attributes[:index_method];end |
#path_base(params = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/loggly/remote_model.rb', line 26 def path_base(params = {}) pb = @resource_attributes[:path_base] || File.join('/', @resource_attributes[:collection_name]) params.each { |k,v| pb.gsub!(":#{k}", v) } unless params.blank? pb end |
#path_ext ⇒ Object
18 |
# File 'lib/loggly/remote_model.rb', line 18 def path_ext;@resource_attributes[:path_ext];end |
#prepare_params(conditions = {}, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/loggly/remote_model.rb', line 46 def prepare_params(conditions = {}, = {}) params = {} params[:q] = if conditions[:q].kind_of?(Hash) conditions[:q].map { |condition| condition.join(':') }.join(' AND ') else '*' end params end |
#set_resource_attributes(ra) ⇒ Object
22 23 24 |
# File 'lib/loggly/remote_model.rb', line 22 def set_resource_attributes(ra) @resource_attributes = DEFAULT_RESOURCE_ATTRIBUTES.merge(ra) end |
#where(conditions = {}, options = {}, &callback) ⇒ Object
58 59 60 |
# File 'lib/loggly/remote_model.rb', line 58 def where(conditions = {}, = {}, &callback) self.all(conditions, , &callback) end |