Class: LittleGhost::Sandbox::EnvironmentPolicy
- Inherits:
-
Object
- Object
- LittleGhost::Sandbox::EnvironmentPolicy
- Defined in:
- lib/little_ghost/sandbox/environment_policy.rb
Overview
Declares whether a child inherits the host environment and which explicit values are added or replaced.
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Explicit child environment values.
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Returns
valueunchanged or builds a policy from a Hash.
Instance Method Summary collapse
-
#inherit? ⇒ Boolean
Indicates whether configured backends may inherit host values.
-
#initialize(inherit: false, values: {}) ⇒ EnvironmentPolicy
constructor
Builds an environment policy with explicit String-compatible
values. -
#to_h ⇒ Object
Returns the explicit child environment values.
Constructor Details
#initialize(inherit: false, values: {}) ⇒ EnvironmentPolicy
Builds an environment policy with explicit String-compatible values.
24 25 26 27 28 29 30 |
# File 'lib/little_ghost/sandbox/environment_policy.rb', line 24 def initialize(inherit: false, values: {}) raise PolicyError, "sandbox environment values must be a Hash" unless values.is_a?(Hash) @inherit = !!inherit @values = values.to_h { |key, value| [String(key).freeze, String(value).freeze] }.freeze freeze end |
Instance Attribute Details
#values ⇒ Object (readonly)
Explicit child environment values.
33 34 35 |
# File 'lib/little_ghost/sandbox/environment_policy.rb', line 33 def values @values end |
Class Method Details
.coerce(value) ⇒ Object
Returns value unchanged or builds a policy from a Hash.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/little_ghost/sandbox/environment_policy.rb', line 9 def self.coerce(value) return value if value.is_a?(self) raise PolicyError, "sandbox environment must be a Hash" unless value.is_a?(Hash) if value.key?(:set) || value.key?("set") || value.key?(:inherit) || value.key?("inherit") values = value[:set] || value["set"] || {} inherit = value.fetch(:inherit, value.fetch("inherit", false)) else values = value inherit = false end new(inherit:, values:) end |
Instance Method Details
#inherit? ⇒ Boolean
Indicates whether configured backends may inherit host values.
36 37 |
# File 'lib/little_ghost/sandbox/environment_policy.rb', line 36 def inherit? = @inherit # Returns the explicit child environment values. |
#to_h ⇒ Object
Returns the explicit child environment values.
38 |
# File 'lib/little_ghost/sandbox/environment_policy.rb', line 38 def to_h = values |