Class: Smplkit::Flags::FlagEnvironment
- Inherits:
-
Object
- Object
- Smplkit::Flags::FlagEnvironment
- Defined in:
- lib/smplkit/flags/models.rb
Overview
Per-environment configuration on a Flag.
Lives at flag.environments[env_name]. Frozen — mutate via Flag#add_rule / Flag#enable_rules / Flag#disable_rules / Flag#set_default / Flag#clear_rules (with environment:).
Attributes:
- enabled: Whether the flag is active in this environment.
- default: Environment-specific default override (+nil+ means no override).
- rules: Targeting rules to evaluate, in order.
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #enabled? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(enabled: true, default: nil, rules: []) ⇒ FlagEnvironment
constructor
A new instance of FlagEnvironment.
-
#with(**changes) ⇒ Object
Return a new FlagEnvironment with the given fields replaced.
Constructor Details
#initialize(enabled: true, default: nil, rules: []) ⇒ FlagEnvironment
Returns a new instance of FlagEnvironment.
51 52 53 54 55 56 |
# File 'lib/smplkit/flags/models.rb', line 51 def initialize(enabled: true, default: nil, rules: []) @enabled = enabled @default = default @rules = rules.is_a?(Array) ? rules.dup.freeze : rules freeze end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
49 50 51 |
# File 'lib/smplkit/flags/models.rb', line 49 def default @default end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
49 50 51 |
# File 'lib/smplkit/flags/models.rb', line 49 def enabled @enabled end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
49 50 51 |
# File 'lib/smplkit/flags/models.rb', line 49 def rules @rules end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
69 70 71 |
# File 'lib/smplkit/flags/models.rb', line 69 def ==(other) other.is_a?(FlagEnvironment) && enabled == other.enabled && default == other.default && rules == other.rules end |
#enabled? ⇒ Boolean
58 |
# File 'lib/smplkit/flags/models.rb', line 58 def enabled? = @enabled |
#hash ⇒ Object
74 |
# File 'lib/smplkit/flags/models.rb', line 74 def hash = [enabled, default, rules].hash |
#with(**changes) ⇒ Object
Return a new FlagEnvironment with the given fields replaced.
61 62 63 64 65 66 67 |
# File 'lib/smplkit/flags/models.rb', line 61 def with(**changes) self.class.new( enabled: changes.fetch(:enabled, @enabled), default: changes.fetch(:default, @default), rules: changes.fetch(:rules, @rules) ) end |