Module: Granite::Projector::ControllerActions::ClassMethods
- Defined in:
- lib/granite/projector/controller_actions.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#action(name, options = {}, &block) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #action_for(http_method, action) ⇒ Object
Instance Method Details
#action(name, options = {}, &block) ⇒ Object
rubocop:disable Metrics/MethodLength
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/granite/projector/controller_actions.rb', line 20 def action(name, = {}, &block) # rubocop:disable Metrics/MethodLength if block self.controller_actions = controller_actions.merge(name.to_sym => ) controller_class.__send__(:define_method, name, &block) class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{name}_url(options = {}) # def foo_url(options = {} action_url(:#{name}, **options.symbolize_keys) # action_url(:foo, **options.symbolize_keys) end # end # def #{name}_path(options = {}) # def foo_path(options = {}) action_path(:#{name}, **options.symbolize_keys) # action_path(:foo, **options.symbolize_keys) end # end METHOD else controller_actions[name.to_sym] end end |
#action_for(http_method, action) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/granite/projector/controller_actions.rb', line 38 def action_for(http_method, action) controller_actions.find do |controller_action, | .fetch(:as, controller_action).to_s == action && Array(.fetch(:method)).include?(http_method) end&.first end |