class ActionParameter::Base
Attributes
Public Class Methods
initialize: Initialize parameter class and creates controller_name and action_name helpers.
Options¶ ↑
-
params
- The ActionController::Parameters instance from the controller who initialize this.
# File lib/action_parameter/base.rb, line 11 def initialize(params) @params = params create_base_helpers end
Public Instance Methods
locals: Creates helper methods for the ActionParameter
instace.
Options¶ ↑
-
locals
- Hash used to create helper methods available for theActionParameter
instance.
Examples¶ ↑
-
locals(new_method: @value, another_method: @other_value) # => ‘ActionParameter instace’
Returns the ActionParameter
instace.
# File lib/action_parameter/base.rb, line 28 def locals(locals = {}) create_methods(locals) self end
Protected Instance Methods
create_base_helpers
: Creates controller_name and action_name helper methods, every time an ActionParameter
instace is created.
# File lib/action_parameter/base.rb, line 36 def create_base_helpers locals = { controller_name: params[:controller], action_name: params[:action] } create_methods(locals) end
create_methods
: Creates instance methods using locals hash’s keys and values.
Options¶ ↑
-
locals
- Hash used to create helper methods available for theActionParameter
instance. Methods will be named using the hash keys and they’ll return the hash values.
Examples¶ ↑
create_methods(current_user: @user, another_key: @another_variable) Will create 'current_user' and 'another_key' instance methods. This methods will be aviable only in the current parameter class where create_method was called. 'current_user' will return @user. 'another_key' will return @another_variable
# File lib/action_parameter/base.rb, line 56 def create_methods(locals = {}) locals = {} unless locals klass = class << self; self; end locals.each do |method_name, value| klass.send(:define_method, method_name) do value end end end