Class: Stoplight::Admin::LightsRepository
- Inherits:
-
Object
- Object
- Stoplight::Admin::LightsRepository
- Defined in:
- lib/stoplight/admin/lights_repository.rb,
lib/stoplight/admin/lights_repository/light.rb
Defined Under Namespace
Classes: Light
Instance Attribute Summary collapse
Instance Method Summary collapse
- #all ⇒ <Stoplight::Admin::LightsRepository::Light>
-
#initialize(data_store:) ⇒ LightsRepository
constructor
@param data_store [Stoplight::Domain::_DataStore].
- #lock(name, color = nil) ⇒ void
- #remove(name) ⇒ void
- #unlock(name) ⇒ void
-
#with_color(*colors) ⇒ <Stoplight::Admin::LightsRepository::Light>
Lights with the requested colors.
Constructor Details
#initialize(data_store:) ⇒ LightsRepository
@param data_store [Stoplight::Domain::_DataStore]
13 14 15 |
# File 'lib/stoplight/admin/lights_repository.rb', line 13 def initialize(data_store:) @data_store = data_store end |
Instance Attribute Details
#data_store=(value) ⇒ Stoplight::Domain::_DataStore
9 10 11 |
# File 'lib/stoplight/admin/lights_repository.rb', line 9 def data_store @data_store end |
Instance Method Details
#all ⇒ <Stoplight::Admin::LightsRepository::Light>
18 19 20 21 22 23 |
# File 'lib/stoplight/admin/lights_repository.rb', line 18 def all data_store .names .map { |name| load_light(name) } .sort_by(&:default_sort_key) end |
#lock(name, color = nil) ⇒ void
This method returns an undefined value.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/stoplight/admin/lights_repository.rb', line 40 def lock(name, color = nil) config = build_config(name) color ||= data_store.get_state_snapshot(config).color case color when Stoplight::Color::GREEN data_store.set_state(config, Stoplight::State::LOCKED_GREEN) else data_store.set_state(config, Stoplight::State::LOCKED_RED) end end |
#remove(name) ⇒ void
This method returns an undefined value.
61 62 63 64 65 |
# File 'lib/stoplight/admin/lights_repository.rb', line 61 def remove(name) config = build_config(name) data_store.delete_light(config) end |
#unlock(name) ⇒ void
This method returns an undefined value.
54 55 56 57 |
# File 'lib/stoplight/admin/lights_repository.rb', line 54 def unlock(name) config = build_config(name) data_store.set_state(config, State::UNLOCKED) end |
#with_color(*colors) ⇒ <Stoplight::Admin::LightsRepository::Light>
Returns lights with the requested colors.
28 29 30 31 32 33 34 |
# File 'lib/stoplight/admin/lights_repository.rb', line 28 def with_color(*colors) requested_colors = Array(colors) all.select do |light| requested_colors.include?(light.color) end end |