Class: RackFlags::Reader
- Inherits:
-
Object
- Object
- RackFlags::Reader
- Defined in:
- lib/rack-flags/reader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #base_flags ⇒ Object
- #full_flags ⇒ Object
-
#initialize(base_flags, overrides) ⇒ Reader
constructor
A new instance of Reader.
- #on?(flag_name) ⇒ Boolean
Constructor Details
#initialize(base_flags, overrides) ⇒ Reader
Returns a new instance of Reader.
18 19 20 21 |
# File 'lib/rack-flags/reader.rb', line 18 def initialize( base_flags, overrides ) @base_flags = load_base_flags( base_flags ) @overrides = overrides end |
Class Method Details
.blank_reader ⇒ Object
14 15 16 |
# File 'lib/rack-flags/reader.rb', line 14 def self.blank_reader new( [], {} ) end |
Instance Method Details
#base_flags ⇒ Object
23 24 25 |
# File 'lib/rack-flags/reader.rb', line 23 def base_flags @base_flags.values.inject({}) { |h,flag| h[flag.name] = flag.default; h } end |
#full_flags ⇒ Object
27 28 29 30 31 |
# File 'lib/rack-flags/reader.rb', line 27 def full_flags @base_flags.values.map do |base_flag| FullFlag.new(base_flag, @overrides[base_flag.name.to_sym]) end end |
#on?(flag_name) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rack-flags/reader.rb', line 33 def on?(flag_name) flag_name = flag_name.to_sym return false unless base_flag_exists?( flag_name ) @overrides.fetch(flag_name) do # fall back to defaults fetch_base_flag(flag_name).default end end |