module Card::Format::MethodDelegation
Constants
- RENDER_METHOD_RE
Public Instance Methods
action_view()
click to toggle source
# File 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)
click to toggle source
# File lib/card/format/method_delegation.rb, line 12 def api_render match, opts # view can be part of method name or first argument view = match[:view] || opts.shift render! view, render_args(match[:underscore], match[:bang], opts) end
Private Instance Methods
action_view?(method)
click to toggle source
# File lib/card/format/method_delegation.rb, line 32 def action_view? method action_view.respond_to? method end
api_render?(method)
click to toggle source
# File lib/card/format/method_delegation.rb, line 24 def api_render? method method.match RENDER_METHOD_RE end
delegate_to_action_view(method, opts, proc) { |*a| ... }
click to toggle source
# File lib/card/format/method_delegation.rb, line 69 def delegate_to_action_view method, opts, proc proc = proc { |*a| raw yield(*a) } if proc response = action_view.send method, *opts, &proc response.is_a?(String) ? action_view.raw(response) : response end
interpret_render_opts(opts, &block)
click to toggle source
# File lib/card/format/method_delegation.rb, line 55 def interpret_render_opts opts, &block (opts[0] ? opts.shift.clone : {}).tap(&block) end
method_missing(method, *opts) { || ... }
click to toggle source
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`
# File 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
new_action_view()
click to toggle source
# File lib/card/format/method_delegation.rb, line 63 def new_action_view CardActionView.new(controller).tap do |t| t.extend CardController._helpers end end
optional_render_opt(opts, args)
click to toggle source
# File lib/card/format/method_delegation.rb, line 59 def optional_render_opt opts, args opts.shift || args[:optional] || :show end
render_args(underscore, bang, opts)
click to toggle source
# File lib/card/format/method_delegation.rb, line 47 def render_args underscore, bang, opts # opts is a list; args is a hash. we're using various inputs to build the hash interpret_render_opts opts do |args| args[:optional] = optional_render_opt opts, args unless bang args[:skip_perms] = true if underscore end end
respond_to_missing?(method, _include_private=false)
click to toggle source
# File lib/card/format/method_delegation.rb, line 28 def respond_to_missing? method, _include_private=false api_render?(method) || action_view?(method) end