class RackFlags::Reader
Public Class Methods
blank_reader()
click to toggle source
# File lib/rack-flags/reader.rb, line 14 def self.blank_reader new( [], {} ) end
new( base_flags, overrides )
click to toggle source
# File lib/rack-flags/reader.rb, line 18 def initialize( base_flags, overrides ) @base_flags = load_base_flags( base_flags ) @overrides = overrides end
Public Instance Methods
base_flags()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
base_flag_exists?( flag_name )
click to toggle source
# File lib/rack-flags/reader.rb, line 50 def base_flag_exists?( flag_name ) @base_flags.has_key?( flag_name ) end
fetch_base_flag( flag_name )
click to toggle source
# File lib/rack-flags/reader.rb, line 54 def fetch_base_flag( flag_name ) @base_flags.fetch( flag_name ) do BaseFlag.new( nil, nil, false ) # if we couldn't find a flag return a Null flag end end
load_base_flags( flags )
click to toggle source
# File lib/rack-flags/reader.rb, line 46 def load_base_flags( flags ) Hash[ *flags.map{ |f| [f.name.to_sym, f] }.flatten ] end