module DaisybillApi::Ext::CRUD::ClassMethods

@private

Constants

PREFIX_LENGTH

Public Instance Methods

client(method, path, params = {}) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 73
def client(method, path, params = {})
  DaisybillApi::Data::Client.build method, path, params
end
index_path(prefix_id) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 61
def index_path(prefix_id)
  if path_prefix?
    index_path_with_prefix(prefix_id)
  else
    index_path_without_prefix
  end
end
path() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 26
def path
  @path ||= "/#{plural_key}"
end
path=(value) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 22
def path=(value)
  @path = value
end
path_prefix(path, property) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 30
def path_prefix(path, property)
  @prefix_path = path
  @prefix_property = property
  attribute property, :integer, readonly: true
  validates property, presence: true, if: :new_record?
end
path_prefix?() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 37
def path_prefix?
  !!(@prefix_path && @prefix_property)
end
plural_key() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 49
def plural_key
  @plural_key ||= demodulize self.model_name.plural
end
prefix_path() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 41
def prefix_path
  @prefix_path
end
prefix_property() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 45
def prefix_property
  @prefix_property
end
rest_actions(*actions) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 14
def rest_actions(*actions)
  actions.each { |action|
    name = action.to_s.classify
    extend "DaisybillApi::Ext::CRUD::#{name}::ClassMethods".constantize
    include "DaisybillApi::Ext::CRUD::#{name}::InstanceMethods".constantize
  }
end
search_path(prefix_id) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 69
def search_path(prefix_id)
  "#{index_path(prefix_id)}/search"
end
show_path(id) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 57
def show_path(id)
  "#{path}/#{id}"
end
singular_key() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 53
def singular_key
  @singular_key ||= demodulize self.model_name.singular
end

Private Instance Methods

demodulize(name) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 81
def demodulize(name)
  name[PREFIX_LENGTH..name.length]
end
index_path_with_prefix(prefix_id) click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 85
def index_path_with_prefix(prefix_id)
  "#{prefix_path}/#{prefix_id}#{path}"
end
index_path_without_prefix() click to toggle source
# File lib/daisybill_api/ext/crud.rb, line 89
def index_path_without_prefix
  path
end