Class: Ronin::Core::Params::Param
- Inherits:
-
Object
- Object
- Ronin::Core::Params::Param
- Defined in:
- lib/ronin/core/params/param.rb
Overview
Represents an individual param.
Instance Attribute Summary collapse
-
#default ⇒ Object, ...
readonly
The default value or proc for the param.
-
#desc ⇒ String
readonly
The description of the param.
-
#name ⇒ Symbol
readonly
The name of the param.
-
#required ⇒ Boolean
readonly
Specifies whether the param is required or not.
-
#type ⇒ Types::Type
readonly
The param type.
Instance Method Summary collapse
-
#coerce(value) ⇒ Object
Coerces the value for the param.
-
#default_value ⇒ Object
Returns the default value for the param.
-
#has_default? ⇒ Boolean
Determines if the param has a default value.
-
#initialize(name, type, required: false, default: nil, desc:) ⇒ Param
constructor
private
Initializes the param.
-
#required? ⇒ Boolean
Determines if the param is required.
Constructor Details
#initialize(name, type, required: false, default: nil, desc:) ⇒ Param
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the param.
74 75 76 77 78 79 80 |
# File 'lib/ronin/core/params/param.rb', line 74 def initialize(name,type, required: false, default: nil, desc: ) @name = name @type = type @required = required @default = default @desc = desc end |
Instance Attribute Details
#default ⇒ Object, ... (readonly)
The default value or proc for the param.
47 48 49 |
# File 'lib/ronin/core/params/param.rb', line 47 def default @default end |
#desc ⇒ String (readonly)
The description of the param.
52 53 54 |
# File 'lib/ronin/core/params/param.rb', line 52 def desc @desc end |
#name ⇒ Symbol (readonly)
The name of the param.
32 33 34 |
# File 'lib/ronin/core/params/param.rb', line 32 def name @name end |
#required ⇒ Boolean (readonly)
Specifies whether the param is required or not.
42 43 44 |
# File 'lib/ronin/core/params/param.rb', line 42 def required @required end |
#type ⇒ Types::Type (readonly)
The param type.
37 38 39 |
# File 'lib/ronin/core/params/param.rb', line 37 def type @type end |
Instance Method Details
#coerce(value) ⇒ Object
Coerces the value for the param.
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ronin/core/params/param.rb', line 123 def coerce(value) case value when nil if required? raise(ValidationError,"param requires a non-nil value") end else @type.coerce(value) end end |
#default_value ⇒ Object
Returns the default value for the param.
105 106 107 108 109 |
# File 'lib/ronin/core/params/param.rb', line 105 def default_value if @default.respond_to?(:call) then @default.call else @default.dup end end |
#has_default? ⇒ Boolean
Determines if the param has a default value.
96 97 98 |
# File 'lib/ronin/core/params/param.rb', line 96 def has_default? !@default.nil? end |
#required? ⇒ Boolean
Determines if the param is required.
87 88 89 |
# File 'lib/ronin/core/params/param.rb', line 87 def required? @required end |