Class: RailsParam::Parameter
- Inherits:
-
Object
- Object
- RailsParam::Parameter
- Defined in:
- lib/rails_param/parameter.rb
Constant Summary collapse
- TIME_TYPES =
[Date, DateTime, Time].freeze
- STRING_OR_TIME_TYPES =
([String] + TIME_TYPES).freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name:, value:, options: {}, type: nil) ⇒ Parameter
constructor
A new instance of Parameter.
- #set_default ⇒ Object
- #should_set_default? ⇒ Boolean
- #transform ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(name:, value:, options: {}, type: nil) ⇒ Parameter
Returns a new instance of Parameter.
8 9 10 11 12 13 |
# File 'lib/rails_param/parameter.rb', line 8 def initialize(name:, value:, options: {}, type: nil) @name = name @value = value @options = @type = type end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rails_param/parameter.rb', line 3 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/rails_param/parameter.rb', line 3 def @options end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/rails_param/parameter.rb', line 3 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/rails_param/parameter.rb', line 3 def value @value end |
Instance Method Details
#set_default ⇒ Object
19 20 21 |
# File 'lib/rails_param/parameter.rb', line 19 def set_default self.value = [:default].respond_to?(:call) ? [:default].call : [:default] end |
#should_set_default? ⇒ Boolean
15 16 17 |
# File 'lib/rails_param/parameter.rb', line 15 def should_set_default? value.nil? && check_param_presence?([:default]) end |
#transform ⇒ Object
23 24 25 |
# File 'lib/rails_param/parameter.rb', line 23 def transform self.value = [:transform].to_proc.call(value) end |