Module: LightSwitch
- Defined in:
- lib/light_switch.rb,
lib/light_switch/engine.rb,
lib/light_switch/version.rb,
lib/light_switch/null_cache.rb,
app/models/light_switch/switch.rb,
lib/light_switch/configuration.rb,
app/models/light_switch/application_record.rb,
app/controllers/light_switch/switches_controller.rb,
app/controllers/light_switch/application_controller.rb
Defined Under Namespace
Classes: ApplicationController, ApplicationRecord, Configuration, Engine, NullCache, Switch, SwitchesController
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Class Method Details
.[](switch_name) ⇒ Object
28
29
30
31
32
|
# File 'lib/light_switch.rb', line 28
def [](switch_name)
config.cache.fetch("#{LightSwitch::Switch.name.underscore}/#{switch_name}", **config.cache_fetch_options) do
LightSwitch::Switch.find_or_initialize_by(name: switch_name.to_s)
end
end
|
.config ⇒ Object
9
10
11
|
# File 'lib/light_switch.rb', line 9
def config
@config ||= Configuration.new
end
|
13
14
15
|
# File 'lib/light_switch.rb', line 13
def configure
yield config
end
|
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/light_switch.rb', line 17
def configure_defaults
config.cache = NullCache.new
config.cache_fetch_options = {
expires_in: 86_400, race_condition_ttl: 300 }
config.switches = []
end
|
.off?(switch_name) ⇒ Boolean
38
39
40
|
# File 'lib/light_switch.rb', line 38
def off?(switch_name)
self[switch_name].off?
end
|
.on?(switch_name) ⇒ Boolean
34
35
36
|
# File 'lib/light_switch.rb', line 34
def on?(switch_name)
self[switch_name].on?
end
|