Class: ParamsFor::Base
- Inherits:
-
Object
- Object
- ParamsFor::Base
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/params_for/base.rb
Class Method Summary collapse
-
.attr_accessor(*vars) ⇒ Object
Memoizes the accessor atrributes in the @attributes variable to be able to list them and access them.
-
.attributes ⇒ Array(Symbols)
Accessor method to the memoized attrubutes setted by the attr_accessor method.
Instance Method Summary collapse
-
#attributes ⇒ Array(Symbol)
Alias for the attributes class method.
-
#initialize(params = {}) ⇒ Base
constructor
Initializes the param validator object with the given controller params HashwithIndifferentAccess object and feeds any defined attribute with the given param key if they exists.
-
#to_params ⇒ HashWithIndifferentAccess
Returns the given attibutes validated and parsed if needed to be used in the controller.
Constructor Details
#initialize(params = {}) ⇒ Base
Initializes the param validator object with the given controller params HashwithIndifferentAccess object and feeds any defined attribute with the given param key if they exists
30 31 32 33 34 |
# File 'lib/params_for/base.rb', line 30 def initialize(params = {}) params.each do |key, value| attribute?(key) && send("#{key}=", value) end end |
Class Method Details
.attr_accessor(*vars) ⇒ Object
Memoizes the accessor atrributes in the @attributes variable to be able to list them and access them
10 11 12 13 14 |
# File 'lib/params_for/base.rb', line 10 def self.attr_accessor(*vars) @attributes ||= [] @attributes.concat vars super(*vars) end |
.attributes ⇒ Array(Symbols)
Accessor method to the memoized attrubutes setted by the attr_accessor method
19 20 21 22 23 24 |
# File 'lib/params_for/base.rb', line 19 def self.attributes @attributes ||= [] super_attributes = superclass.attributes if superclass && superclass.respond_to?(:attributes) (super_attributes || []) + @attributes end |
Instance Method Details
#attributes ⇒ Array(Symbol)
Alias for the attributes class method
39 40 41 |
# File 'lib/params_for/base.rb', line 39 def attributes self.class.attributes end |
#to_params ⇒ HashWithIndifferentAccess
Returns the given attibutes validated and parsed if needed to be used in the controller
47 48 49 |
# File 'lib/params_for/base.rb', line 47 def to_params ::HashWithIndifferentAccess.new(attributes_hash) end |