Class: Dotenv::Schema
- Inherits:
-
Hash
- Object
- Hash
- Dotenv::Schema
- Defined in:
- lib/dotenv/schema.rb
Defined Under Namespace
Classes: ValidationError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ Schema
constructor
A new instance of Schema.
- #validate!(env) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Schema
Returns a new instance of Schema.
8 9 10 |
# File 'lib/dotenv/schema.rb', line 8 def initialize(hash={}) replace hash if hash end |
Class Method Details
.load(file) ⇒ Object
12 13 14 |
# File 'lib/dotenv/schema.rb', line 12 def self.load(file) new YAML.load(File.read(file)) end |
Instance Method Details
#validate!(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dotenv/schema.rb', line 16 def validate!(env) undefined_keys = env.keys - keys unless undefined_keys.empty? raise ValidationError, "Undefined variable(s): #{undefined_keys.join(', ')}; Please add them into #{Dotenv.schema_path}" end each do |key, | if env[key] == '' && ( && !['allow_empty_string'] || !) raise ValidationError, "ENV['#{key}'] must not be empty string" end if !env.has_key?(key) && ( && !['allow_not_exists'] || !) raise ValidationError, "ENV['#{key}'] must exist" end end true end |