Class: Philiprehberger::EnvValidator::Schema
- Inherits:
-
Object
- Object
- Philiprehberger::EnvValidator::Schema
- Defined in:
- lib/philiprehberger/env_validator/schema.rb
Overview
Defines the schema for environment variable validation.
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
Instance Method Summary collapse
-
#array(name, item_type: :string, separator: ',', required: false, default: nil) ⇒ void
Define an array variable parsed from a delimited string.
-
#boolean(name, required: false, default: nil, choices: nil) ⇒ void
Define a boolean variable.
-
#float(name, required: false, default: nil, choices: nil) ⇒ void
Define a float variable.
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
-
#integer(name, required: false, default: nil, choices: nil) ⇒ void
Define an integer variable.
-
#string(name, required: false, default: nil, choices: nil) ⇒ void
Define a string variable.
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
9 10 11 |
# File 'lib/philiprehberger/env_validator/schema.rb', line 9 def initialize @definitions = {} end |
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
7 8 9 |
# File 'lib/philiprehberger/env_validator/schema.rb', line 7 def definitions @definitions end |
Instance Method Details
#array(name, item_type: :string, separator: ',', required: false, default: nil) ⇒ void
This method returns an undefined value.
Define an array variable parsed from a delimited string.
The ENV value is split on ‘separator`, each element is stripped of surrounding whitespace, and each element is cast to `item_type` using the same type caster the other schema methods use.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/philiprehberger/env_validator/schema.rb', line 68 def array(name, item_type: :string, separator: ',', required: false, default: nil) @definitions[name.to_s] = { type: :array, item_type: item_type, separator: separator, required: required, default: default, choices: nil } end |
#boolean(name, required: false, default: nil, choices: nil) ⇒ void
This method returns an undefined value.
Define a boolean variable.
52 53 54 |
# File 'lib/philiprehberger/env_validator/schema.rb', line 52 def boolean(name, required: false, default: nil, choices: nil) @definitions[name.to_s] = { type: :boolean, required: required, default: default, choices: choices } end |
#float(name, required: false, default: nil, choices: nil) ⇒ void
This method returns an undefined value.
Define a float variable.
41 42 43 |
# File 'lib/philiprehberger/env_validator/schema.rb', line 41 def float(name, required: false, default: nil, choices: nil) @definitions[name.to_s] = { type: :float, required: required, default: default, choices: choices } end |
#integer(name, required: false, default: nil, choices: nil) ⇒ void
This method returns an undefined value.
Define an integer variable.
30 31 32 |
# File 'lib/philiprehberger/env_validator/schema.rb', line 30 def integer(name, required: false, default: nil, choices: nil) @definitions[name.to_s] = { type: :integer, required: required, default: default, choices: choices } end |
#string(name, required: false, default: nil, choices: nil) ⇒ void
This method returns an undefined value.
Define a string variable.
19 20 21 |
# File 'lib/philiprehberger/env_validator/schema.rb', line 19 def string(name, required: false, default: nil, choices: nil) @definitions[name.to_s] = { type: :string, required: required, default: default, choices: choices } end |