module GrapeOnRails::Validator

Constants

ALLOW_ACTIONS

Public Instance Methods

extract_action(method_name) click to toggle source
# File lib/grape_on_rails/validator.rb, line 32
def extract_action method_name
  method_name[/.+?(?=_params)/]
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/grape_on_rails/validator.rb, line 19
      def method_missing method, *args, &block
        action = extract_action method
        super unless action&.match? ALLOW_ACTIONS
        define_method "hook_#{action}", block
        class_eval <<-RUBY, __FILE__, __LINE__ + 1
          before_action :hook_#{action}, only: :#{action}
        RUBY
      end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/grape_on_rails/validator.rb, line 28
def respond_to_missing? method_name, include_private = false
  extract_action(method_name)&.match?(ALLOW_ACTIONS) || super(method_name, include_private)
end
validate_actions(*actions) click to toggle source
# File lib/grape_on_rails/validator.rb, line 12
def validate_actions *actions
  actions.each do |action|
    meta_method = "before_action :validate_#{action}, only: :#{action}"
    class_eval meta_method
  end
end