Module: RouteNGNClient::RemoteModel::ClassMethods

Included in:
RouteNGNClient::RemoteModel
Defined in:
lib/routengn_client/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/routengn_client/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
45
# File 'lib/routengn_client/remote_model.rb', line 32

def all(conditions = {}, options = {}, &callback)
  options.merge!(:klass => self)
  params = conditions
  params[:per_page] ||= @resource_attributes[:per_page]
  params[:page] ||= 1
  params[:include_paging_info] = 'true' unless params.has_key?(:include_paging_info)
  
  response = Request.new(@resource_attributes, :get, [path_base, index_method], path_ext, params, options).execute(RouteNGNClient.connection)
  models = response.to_models

  callback.call(models) if callback

  models
end

#collection_nameObject



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

def collection_name;@resource_attributes[:collection_name];end

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

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/routengn_client/remote_model.rb', line 62

def create!(attributes = {}, options = {}, &callback)
  raise NotImplementedError
end

#find(id, options = {}, &callback) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/routengn_client/remote_model.rb', line 51

def find(id, options = {}, &callback)
  options.merge!(:klass => self)
  
  response = Request.new(@resource_attributes, :get, [path_base, id.to_s], path_ext, {}, options).execute(RouteNGNClient.connection)      
  model = response.to_model

  callback.call(models) if callback

  model
end

#index_methodObject



19
# File 'lib/routengn_client/remote_model.rb', line 19

def index_method;@resource_attributes[:index_method];end

#path_base(params = {}) ⇒ Object



26
27
28
29
30
# File 'lib/routengn_client/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/routengn_client/remote_model.rb', line 18

def path_ext;@resource_attributes[:path_ext];end

#set_resource_attributes(ra) ⇒ Object



22
23
24
# File 'lib/routengn_client/remote_model.rb', line 22

def set_resource_attributes(ra)
  @resource_attributes = DEFAULT_RESOURCE_ATTRIBUTES.merge(ra)
end

#where(conditions = {}, options = {}, &callback) ⇒ Object



47
48
49
# File 'lib/routengn_client/remote_model.rb', line 47

def where(conditions = {}, options = {}, &callback)
  self.all(conditions, options, &callback)
end