Class: EnvValidator::Configuration
- Inherits:
-
Object
- Object
- EnvValidator::Configuration
- Defined in:
- lib/env_validator/configuration.rb
Instance Attribute Summary collapse
-
#current_env ⇒ Object
readonly
Returns the value of attribute current_env.
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #applicable_rules ⇒ Object
- #clear! ⇒ Object
- #environment(env_name, &block) ⇒ Object
- #group(group_name, &block) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #optional(name, **options, &block) ⇒ Object
- #required(name, **options, &block) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
47 48 49 50 51 52 |
# File 'lib/env_validator/configuration.rb', line 47 def initialize @rules = {} @environments = {} @groups = {} @current_env = detect_environment end |
Instance Attribute Details
#current_env ⇒ Object (readonly)
Returns the value of attribute current_env.
45 46 47 |
# File 'lib/env_validator/configuration.rb', line 45 def current_env @current_env end |
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
45 46 47 |
# File 'lib/env_validator/configuration.rb', line 45 def environments @environments end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
45 46 47 |
# File 'lib/env_validator/configuration.rb', line 45 def groups @groups end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
45 46 47 |
# File 'lib/env_validator/configuration.rb', line 45 def rules @rules end |
Instance Method Details
#applicable_rules ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/env_validator/configuration.rb', line 72 def applicable_rules rules = @rules.values.dup # Apply environment-specific rules if they exist if @environments[@current_env] env_config = Configuration.new env_config.instance_eval(&@environments[@current_env]) rules.concat(env_config.rules.values) end rules end |
#clear! ⇒ Object
85 86 87 88 89 |
# File 'lib/env_validator/configuration.rb', line 85 def clear! @rules.clear @environments.clear @groups.clear end |
#environment(env_name, &block) ⇒ Object
64 65 66 |
# File 'lib/env_validator/configuration.rb', line 64 def environment(env_name, &block) @environments[env_name.to_sym] = block end |
#group(group_name, &block) ⇒ Object
68 69 70 |
# File 'lib/env_validator/configuration.rb', line 68 def group(group_name, &block) @groups[group_name.to_sym] = block end |