Class: ActionController::Parameters
- Inherits:
-
ActiveSupport::HashWithIndifferentAccess
- Object
- ActiveSupport::HashWithIndifferentAccess
- ActionController::Parameters
- Defined in:
- lib/action_controller/parameters.rb
Instance Attribute Summary collapse
-
#permitted ⇒ Object
(also: #permitted?)
Returns the value of attribute permitted.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #dup ⇒ Object
- #fetch(key, *args) ⇒ Object
-
#initialize(attributes = nil) ⇒ Parameters
constructor
A new instance of Parameters.
- #permit(*filters) ⇒ Object
- #permit! ⇒ Object
- #require(key) ⇒ Object (also: #required)
- #slice(*keys) ⇒ Object
Constructor Details
#initialize(attributes = nil) ⇒ Parameters
Returns a new instance of Parameters.
19 20 21 22 |
# File 'lib/action_controller/parameters.rb', line 19 def initialize(attributes = nil) super(attributes) @permitted = false end |
Instance Attribute Details
#permitted ⇒ Object Also known as: permitted?
Returns the value of attribute permitted.
16 17 18 |
# File 'lib/action_controller/parameters.rb', line 16 def permitted @permitted end |
Instance Method Details
#[](key) ⇒ Object
69 70 71 |
# File 'lib/action_controller/parameters.rb', line 69 def [](key) convert_hashes_to_parameters(key, super) end |
#dup ⇒ Object
83 84 85 86 87 |
# File 'lib/action_controller/parameters.rb', line 83 def dup super.tap do |duplicate| duplicate.instance_variable_set :@permitted, @permitted end end |
#fetch(key, *args) ⇒ Object
73 74 75 76 77 |
# File 'lib/action_controller/parameters.rb', line 73 def fetch(key, *args) convert_hashes_to_parameters(key, super) rescue KeyError raise ActionController::ParameterMissing.new(key) end |
#permit(*filters) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/action_controller/parameters.rb', line 40 def permit(*filters) params = self.class.new filters.each do |filter| case filter when Symbol, String then params[filter] = self[filter] if has_key?(filter) keys.grep(/\A#{Regexp.escape(filter)}\(\di\)\z/).each { |key| params[key] = self[key] } when Hash then self.slice(*filter.keys).each do |key, value| return unless value key = key.to_sym params[key] = each_element(value) do |value| # filters are a Hash, so we expect value to be a Hash too next if filter.is_a?(Hash) && !value.is_a?(Hash) value = self.class.new(value) if !value.respond_to?(:permit) value.permit(*Array.wrap(filter[key])) end end end end params.permit! end |
#permit! ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/action_controller/parameters.rb', line 24 def permit! each_pair do |key, value| convert_hashes_to_parameters(key, value) self[key].permit! if self[key].respond_to? :permit! end @permitted = true self end |
#require(key) ⇒ Object Also known as: required
34 35 36 |
# File 'lib/action_controller/parameters.rb', line 34 def require(key) self[key].presence || raise(ActionController::ParameterMissing.new(key)) end |
#slice(*keys) ⇒ Object
79 80 81 |
# File 'lib/action_controller/parameters.rb', line 79 def slice(*keys) self.class.new(super) end |