Class: ToggleSwitch
- Inherits:
-
Object
- Object
- ToggleSwitch
- Defined in:
- lib/toggle_switch.rb,
lib/toggle_switch/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
- @@nest =
Array.new
Class Method Summary collapse
- .[](key) ⇒ Object
- .fetch(key) ⇒ Object
- .get_nested_hash ⇒ Object
- .load(file_or_hash) ⇒ Object
- .pop_nest ⇒ Object
- .push_nest(key) ⇒ Object
- .reload(file_or_hash) ⇒ Object
- .run ⇒ Object
Class Method Details
.[](key) ⇒ Object
41 42 43 |
# File 'lib/toggle_switch.rb', line 41 def self.[] key fetch key end |
.fetch(key) ⇒ Object
36 37 38 39 |
# File 'lib/toggle_switch.rb', line 36 def self.fetch key push_nest key.to_s return self end |
.get_nested_hash ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/toggle_switch.rb', line 17 def self.get_nested_hash config = @@config.dup @@nest.each do |nest| return nil unless config[nest.to_s] || config[nest.to_sym] config = config[nest.to_s] || config[nest.to_sym] end return config end |
.load(file_or_hash) ⇒ Object
13 14 15 |
# File 'lib/toggle_switch.rb', line 13 def self.load file_or_hash reload file_or_hash end |
.pop_nest ⇒ Object
31 32 33 34 |
# File 'lib/toggle_switch.rb', line 31 def self.pop_nest @@nest.pop get_nested_hash end |
.push_nest(key) ⇒ Object
26 27 28 29 |
# File 'lib/toggle_switch.rb', line 26 def self.push_nest key @@nest << key get_nested_hash end |
.reload(file_or_hash) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/toggle_switch.rb', line 5 def self.reload file_or_hash if file_or_hash.is_a?(Hash) @@config = file_or_hash else @@config = YAML.load_file(file_or_hash) end end |
.run ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/toggle_switch.rb', line 45 def self.run config = get_nested_hash if config yield end @@nest.clear end |