module Card::Format::MethodDelegation
missing methods may be render calls or action view methods these methods sort that out
Constants
- RENDER_METHOD_RE
Public Instance Methods
Source
# File lib/card/format/method_delegation.rb, line 20 def action_view @action_view ||= root? ? new_action_view : root.action_view end
Source
# File lib/card/format/method_delegation.rb, line 14 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
Source
# File lib/card/format/method_delegation.rb, line 34 def action_view? method action_view.respond_to? method end
Source
# File lib/card/format/method_delegation.rb, line 26 def api_render? method method.match RENDER_METHOD_RE end
Source
# File lib/card/format/method_delegation.rb, line 71 def delegate_to_action_view method, opts, &old_proc new_proc = proc { |*a| raw yield(*a) } if old_proc response = action_view.send method, *opts, &new_proc response.is_a?(String) ? action_view.raw(response) : response end
Source
# File lib/card/format/method_delegation.rb, line 57 def interpret_render_opts opts, &block (opts[0] ? opts.shift.clone : {}).tap(&block) end
Source
# File lib/card/format/method_delegation.rb, line 41 def method_missing method, *opts, &proc if (match = api_render? method) api_render match, opts else delegate_to_action_view method, opts, &proc end end
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`
Source
# File lib/card/format/method_delegation.rb, line 65 def new_action_view CardActionView.new(controller).tap do |t| t.extend CardController._helpers end end
Source
# File lib/card/format/method_delegation.rb, line 61 def optional_render_opt opts, args opts.shift || args[:optional] || :show end
Source
# File lib/card/format/method_delegation.rb, line 49 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
Source
# File lib/card/format/method_delegation.rb, line 30 def respond_to_missing? method, _include_private=false api_render?(method) || action_view?(method) end