Class: Stoplight::Admin::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::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

Returns:

  • (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.

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



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.

Parameters:

  • name (String)

    removes light metadata by its name



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.

Parameters:

  • name (String)

    unlocks light by its name



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.

Parameters:

  • colors (String)

    ] colors name

Returns:



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