Class: Hashmake::ArgSpec
- Inherits:
-
Object
- Object
- Hashmake::ArgSpec
- Defined in:
- lib/hashmake/arg_spec.rb
Overview
Provides a specification of how a hashed arg is to be processed by the hash_make method.
Constant Summary collapse
- CONTAINERS =
The valid container types. If nil, indicates no container is expected, just a plain object of type given by :type.
[ nil, Hash, Array ]
- DEFAULT_ARGS =
Defines default key/value pairs to use in initializing an instance. The :reqd key is set to true by default. The :validator key is set to a Proc that always returns true. The :container key is set to CONTAINER_NONE.
{ :reqd => true, :validator => ->(a){true}, :container => nil, :type => Object, }
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#reqd ⇒ Object
readonly
Returns the value of attribute reqd.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#validator ⇒ Object
readonly
Returns the value of attribute validator.
Instance Method Summary collapse
-
#initialize(hashed_args) ⇒ ArgSpec
constructor
A new instance of ArgSpec.
Constructor Details
#initialize(hashed_args) ⇒ ArgSpec
A new instance of ArgSpec.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hashmake/arg_spec.rb', line 47 def initialize hashed_args new_args = DEFAULT_ARGS.merge(hashed_args) @type = new_args[:type] raise ArgumentError, "args[:type] #{@type} is not a Class" unless @type.is_a?(Class) @validator = new_args[:validator] @reqd = new_args[:reqd] @container = new_args[:container] raise ArgumentError, "CONTAINERS does not include container #{@container}" unless CONTAINERS.include?(@container) unless @reqd msg = "if hashed arg is not required, a default value or value generator (proc) must be defined via :default key" raise ArgumentError, msg unless new_args.has_key?(:default) @default = new_args[:default] end end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
25 26 27 |
# File 'lib/hashmake/arg_spec.rb', line 25 def container @container end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
25 26 27 |
# File 'lib/hashmake/arg_spec.rb', line 25 def default @default end |
#reqd ⇒ Object (readonly)
Returns the value of attribute reqd.
25 26 27 |
# File 'lib/hashmake/arg_spec.rb', line 25 def reqd @reqd end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
25 26 27 |
# File 'lib/hashmake/arg_spec.rb', line 25 def type @type end |
#validator ⇒ Object (readonly)
Returns the value of attribute validator.
25 26 27 |
# File 'lib/hashmake/arg_spec.rb', line 25 def validator @validator end |