Module: Loggly::RemoteModel::ClassMethods

Included in:
Loggly::RemoteModel
Defined in:
lib/loggly/remote_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resource_attributesObject (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 = {}, options = {}, &callback)
  options = options.merge(:klass => self)
  params = conditions
  params[:size] = (options[:per_page] ||= @resource_attributes[:per_page])
  params[:page] = (options[:page] ||= 0)

  response = Request.new(@resource_attributes, :get, [path_base, index_method], path_ext, params, options).execute(Loggly.connection)
  models = response.to_models

  callback.call(models) if callback

  models
end

#collection_nameObject



20
# File 'lib/loggly/remote_model.rb', line 20

def collection_name;@resource_attributes[:collection_name];end

#create!(attributes = {}, options = {}, &callback) ⇒ Object

Raises:

  • (NotImplementedError)


73
74
75
# File 'lib/loggly/remote_model.rb', line 73

def create!(attributes = {}, options = {}, &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, options = {}, &callback)
  options.merge(:klass => self)

  response = Request.new(@resource_attributes, :get, [path_base, id.to_s], path_ext, {}, options).execute(Loggly.connection)
  model = response.to_model

  callback.call(models) if callback

  model
end

#index_methodObject



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_extObject



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 = {}, options = {})
  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 = {}, options = {}, &callback)
  self.all(conditions, options, &callback)
end