Module: DaisybillApi::Ext::CRUD::ClassMethods

Defined in:
lib/daisybill_api/ext/crud.rb

Instance Method Summary collapse

Instance Method Details

#client(method, path, params = {}) ⇒ Object



72
73
74
# File 'lib/daisybill_api/ext/crud.rb', line 72

def client(method, path, params = {})
  DaisybillApi::Data::Client.build method, path, params
end

#index_path(prefix_id) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/daisybill_api/ext/crud.rb', line 60

def index_path(prefix_id)
  if path_prefix?
    index_path_with_prefix(prefix_id)
  else
    index_path_without_prefix
  end
end

#pathObject



25
26
27
# File 'lib/daisybill_api/ext/crud.rb', line 25

def path
  @path ||= "/#{plural_key}"
end

#path=(value) ⇒ Object



21
22
23
# File 'lib/daisybill_api/ext/crud.rb', line 21

def path=(value)
  @path = value
end

#path_prefix(path, property) ⇒ Object



29
30
31
32
33
34
# File 'lib/daisybill_api/ext/crud.rb', line 29

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?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/daisybill_api/ext/crud.rb', line 36

def path_prefix?
  !!(@prefix_path && @prefix_property)
end

#plural_keyObject



48
49
50
# File 'lib/daisybill_api/ext/crud.rb', line 48

def plural_key
  @plural_key ||= demodulize self.model_name.plural
end

#prefix_pathObject



40
41
42
# File 'lib/daisybill_api/ext/crud.rb', line 40

def prefix_path
  @prefix_path
end

#prefix_propertyObject



44
45
46
# File 'lib/daisybill_api/ext/crud.rb', line 44

def prefix_property
  @prefix_property
end

#rest_actions(*actions) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/daisybill_api/ext/crud.rb', line 13

def rest_actions(*actions)
  actions.each { |action|
    name = action.capitalize
    extend "DaisybillApi::Ext::CRUD::#{name}::ClassMethods".constantize
    include "DaisybillApi::Ext::CRUD::#{name}::InstanceMethods".constantize
  }
end

#search_path(prefix_id) ⇒ Object



68
69
70
# File 'lib/daisybill_api/ext/crud.rb', line 68

def search_path(prefix_id)
  "#{index_path(prefix_id)}/search"
end

#show_path(id) ⇒ Object



56
57
58
# File 'lib/daisybill_api/ext/crud.rb', line 56

def show_path(id)
  "#{path}/#{id}"
end

#singular_keyObject



52
53
54
# File 'lib/daisybill_api/ext/crud.rb', line 52

def singular_key
  @singular_key ||= demodulize self.model_name.singular
end