module Granite::Projector::ControllerActions::ClassMethods

Public Instance Methods

action(name, options = {}, &block) click to toggle source
# File lib/granite/projector/controller_actions.rb, line 20
        def action(name, options = {}, &block)
          if block
            self.controller_actions = controller_actions.merge(name.to_sym => options)
            controller_class.__send__(:define_method, name, &block)
            class_eval <<-METHOD, __FILE__, __LINE__ + 1
              def #{name}_url(options = {})
                action_url(:#{name}, **options.symbolize_keys)
              end

              def #{name}_path(options = {})
                action_path(:#{name}, **options.symbolize_keys)
              end
            METHOD
          else
            controller_actions[name.to_sym]
          end
        end
action_for(http_method, action) click to toggle source
# File lib/granite/projector/controller_actions.rb, line 38
def action_for(http_method, action)
  controller_actions.find do |controller_action, controller_action_options|
    controller_action_options.fetch(:as, controller_action).to_s == action &&
      Array(controller_action_options.fetch(:method)).include?(http_method)
  end&.first
end