Class: StoplightAdmin::LightsRepository

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(data_store:) ⇒ LightsRepository

@param data_store [Stoplight::DataStore::Base]



11
12
13
# File 'lib/stoplight_admin/lights_repository.rb', line 11

def initialize(data_store:)
  @data_store = data_store
end

Instance Attribute Details

#data_store=(value) ⇒ Stoplight::DataStore::Base

Returns:

  • (Stoplight::DataStore::Base)


7
8
9
# File 'lib/stoplight_admin/lights_repository.rb', line 7

def data_store
  @data_store
end

Instance Method Details

#all<StoplightAdmin::LightsRepository::Light>



16
17
18
19
20
21
# File 'lib/stoplight_admin/lights_repository.rb', line 16

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.

Parameters:

  • name (String)

    locks light by its name

  • color (String, nil) (defaults to: nil)

    locks to this color. When nil is given, locks to the current color



38
39
40
41
42
43
44
45
46
47
# File 'lib/stoplight_admin/lights_repository.rb', line 38

def lock(name, color = nil)
  light = build_light(name)

  case color || light.color
  when Stoplight::Color::GREEN
    light.lock(Stoplight::Color::GREEN)
  else
    light.lock(Stoplight::Color::RED)
  end
end

#unlock(name) ⇒ void

This method returns an undefined value.

Parameters:

  • name (String)

    unlocks light by its name



51
52
53
# File 'lib/stoplight_admin/lights_repository.rb', line 51

def unlock(name)
  build_light(name).unlock
end

#with_color(*colors) ⇒ <StoplightAdmin::LightsRepository::Light>

Returns lights with the requested colors.

Parameters:

  • colors (String)

    ] colors name

Returns:



26
27
28
29
30
31
32
# File 'lib/stoplight_admin/lights_repository.rb', line 26

def with_color(*colors)
  requested_colors = Array(colors)

  all.select do |light|
    requested_colors.include?(light.color)
  end
end