Module: LeanCloud::Helper::ClassMethods
- Defined in:
- lib/lean_cloud/helper.rb
Constant Summary
collapse
- DEFAULT_ACTIONS =
{
:search => {via: :get, root: true },
:show => {via: :get, root: true, on: :member },
:create => {via: :post, root: true },
:update => {via: :put, root: true, on: :member },
:destroy=> {via: :delete, root: true, on: :member }
}
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args, &block) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/lean_cloud/helper.rb', line 39
def method_missing(method_id, *args, &block)
if route=routes.find {|route| route.name.to_s == method_id.to_s}
dispatch(route, *args, &block)
else
super
end
end
|
Instance Method Details
#add_route(name, options = {}, match = nil) ⇒ Object
30
31
32
33
|
# File 'lib/lean_cloud/helper.rb', line 30
def add_route(name, options={},match=nil)
options[:namespace] ||= namespace
routes << Route.new(name, options, match)
end
|
#match(name, options = {}) ⇒ Object
25
26
27
28
|
# File 'lib/lean_cloud/helper.rb', line 25
def match(name, options={})
raise "`as' can't be nil!" if !options[:as]
add_route(options.delete(:as), options, name)
end
|
#only(*args) ⇒ Object
15
16
17
18
19
|
# File 'lib/lean_cloud/helper.rb', line 15
def only(*args)
args.each do |action|
add_route(action, DEFAULT_ACTIONS[action].dup)
end
end
|
#respond_to?(method_id) ⇒ Boolean
35
36
37
|
# File 'lib/lean_cloud/helper.rb', line 35
def respond_to?(method_id)
routes.any? {|route| route.name.to_s == method_id.to_s}
end
|
#route(name, options = {}) ⇒ Object
21
22
23
|
# File 'lib/lean_cloud/helper.rb', line 21
def route(name, options={})
add_route(name, options)
end
|