module RouteNGNClient::RemoteModel::ClassMethods

Attributes

resource_attributes[R]

Public Instance Methods

all(conditions = {}, options = {}, &callback) click to toggle source
# 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_name() click to toggle source
# File lib/routengn_client/remote_model.rb, line 20
def collection_name;@resource_attributes[:collection_name];end
create!(attributes = {}, options = {}, &callback) click to toggle source
# File lib/routengn_client/remote_model.rb, line 62
def create!(attributes = {}, options = {}, &callback)
  raise NotImplementedError
end
find(id, options = {}, &callback) click to toggle source
# 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_method() click to toggle source
# File lib/routengn_client/remote_model.rb, line 19
def index_method;@resource_attributes[:index_method];end
path_base(params = {}) click to toggle source
# 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_ext() click to toggle source
# File lib/routengn_client/remote_model.rb, line 18
def path_ext;@resource_attributes[:path_ext];end
set_resource_attributes(ra) click to toggle source
# 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) click to toggle source
# File lib/routengn_client/remote_model.rb, line 47
def where(conditions = {}, options = {}, &callback)
  self.all(conditions, options, &callback)
end