Module: Card::Format::MethodDelegation
- Included in:
- Card::Format
- Defined in:
- card/lib/card/format/method_delegation.rb
Constant Summary
collapse
- RENDER_METHOD_RE =
/^
(?<underscore>_)? # leading underscore to skip permission check
render
(?:_(?<view>\w+))? # view name
(?<bang>!)? # trailing bang to skip optional check
$/x
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *opts, &proc) ⇒ Object
TODO: make it so we fall back to super if action_view can’t handle method.
It’s not as easy as elsif api_render? method
, because respond_to gives
false for many methods action view can actually handle, like h
39
40
41
42
43
44
45
|
# File 'card/lib/card/format/method_delegation.rb', line 39
def method_missing method, *opts, &proc
if (match = api_render? method)
api_render match, opts
else
delegate_to_action_view(method, opts, proc) { yield }
end
end
|
Instance Method Details
#action_view ⇒ Object
18
19
20
|
# File 'card/lib/card/format/method_delegation.rb', line 18
def action_view
@action_view ||= root? ? new_action_view : root.action_view
end
|
#api_render(match, opts) ⇒ Object
12
13
14
15
16
|
# File 'card/lib/card/format/method_delegation.rb', line 12
def api_render match, opts
view = match[:view] || opts.shift
render! view, render_args(match[:underscore], match[:bang], opts)
end
|