Module: ConfigManager::Toggle
- Defined in:
- lib/config_manager/toggle.rb
Class Method Summary collapse
- .active?(test, challenge = nil) ⇒ Boolean
- .active_in_db?(test, challenge = nil) ⇒ Boolean
- .create(*args) ⇒ Object
- .delete(name) ⇒ Object
- .from_yaml(path) ⇒ Object
- .quick(name, acceptable_values = 'test') ⇒ Object
- .to_yaml ⇒ Object
- .toggles ⇒ Object
Class Method Details
.active?(test, challenge = nil) ⇒ Boolean
3 4 5 |
# File 'lib/config_manager/toggle.rb', line 3 def self.active?(test, challenge=nil) ToggleIdentityMap.value(test) { active_in_db?(test, challenge) } end |
.active_in_db?(test, challenge = nil) ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/config_manager/toggle.rb', line 7 def self.active_in_db?(test, challenge=nil) return true if stub_in_host_app? toggle_def = Toggles::Definition.new(test) return false unless toggle_def.type type_klass = toggle_def.type_class if challenge type_klass.active? toggle_def, challenge else type_klass.active? toggle_def end end |
.create(*args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/config_manager/toggle.rb', line 29 def self.create(*args) toggle_hash = args.first toggle_def = Toggles::Definition.new(toggle_hash[:name]) toggle_def.type = toggle_hash[:type] values = (toggle_hash[:type] == 'boolean') ? toggle_hash[:formatted_acceptable_values] : toggle_hash[:formatted_acceptable_values].gsub(/\s*,\s*/,',').split(',') toggle_def.acceptable_values = values toggle_def end |
.delete(name) ⇒ Object
42 43 44 45 |
# File 'lib/config_manager/toggle.rb', line 42 def self.delete(name) toggle = Toggles::Definition.new(name) toggle.delete end |
.from_yaml(path) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/config_manager/toggle.rb', line 47 def self.from_yaml(path) toggles = YAML::load(File.open(path)) counts = [0, 0] toggles.each do |name, values| begin create({:name => name, :type => values['type'], :formatted_acceptable_values => values['acceptable_values']}) counts[0] += 1 rescue RuntimeError Rails.logger.error "Bad toggle definition. #{$!}" counts[1] += 1 end end counts end |
.quick(name, acceptable_values = 'test') ⇒ Object
70 71 72 73 74 |
# File 'lib/config_manager/toggle.rb', line 70 def self.quick(name, acceptable_values='test') create :name => name, :type => 'set', :formatted_acceptable_values => acceptable_values end |
.to_yaml ⇒ Object
65 66 67 68 |
# File 'lib/config_manager/toggle.rb', line 65 def self.to_yaml toggles_hash = Hash[toggles.map(&:to_hash).map{|t| [t.keys.first, t.values.first]}] YAML.dump(toggles_hash) end |
.toggles ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/config_manager/toggle.rb', line 21 def self.toggles toggle_defs = [] $redis.keys("#{Toggles::Definition.prefix}*").each do |key| toggle_defs << Toggles::Definition.new(key.gsub(Toggles::Definition.prefix, '')) end toggle_defs.sort{|x,y| x.name <=> y.name} end |