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



73
74
75
# 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) ⇒ Object



61
62
63
64
65
66
67
# 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

#pathObject



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

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

#path=(value) ⇒ Object



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

def path=(value)
  @path = value
end

#path_prefix(path, property) ⇒ Object



30
31
32
33
34
35
# 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?Boolean

Returns:

  • (Boolean)


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

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

#plural_keyObject



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

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

#prefix_pathObject



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

def prefix_path
  @prefix_path
end

#prefix_propertyObject



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

def prefix_property
  @prefix_property
end

#rest_actions(*actions) ⇒ Object



14
15
16
17
18
19
20
# 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) ⇒ Object



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

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

#show_path(id) ⇒ Object



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

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

#singular_keyObject



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

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