Class: StoplightAdmin::LightsRepository::Light

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight_admin/lights_repository/light.rb

Constant Summary collapse

COLORS =
[
  GREEN = Stoplight::Color::GREEN,
  YELLOW = Stoplight::Color::YELLOW,
  RED = Stoplight::Color::RED
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, color:, state:, failures:) ⇒ Light

Returns a new instance of Light.

Parameters:

  • name (String)
  • color (String)
  • state (String)
  • failures (<Stoplight::Failure>)


32
33
34
35
36
37
# File 'lib/stoplight_admin/lights_repository/light.rb', line 32

def initialize(name:, color:, state:, failures:)
  @name = name
  @color = color
  @state = state
  @failures = failures
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



18
19
20
# File 'lib/stoplight_admin/lights_repository/light.rb', line 18

def color
  @color
end

#failuresObject

Returns the value of attribute failures.



26
27
28
# File 'lib/stoplight_admin/lights_repository/light.rb', line 26

def failures
  @failures
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/stoplight_admin/lights_repository/light.rb', line 14

def name
  @name
end

#stateObject

Returns the value of attribute state.



22
23
24
# File 'lib/stoplight_admin/lights_repository/light.rb', line 22

def state
  @state
end

Instance Method Details

#as_jsonObject



49
50
51
52
53
54
55
56
# File 'lib/stoplight_admin/lights_repository/light.rb', line 49

def as_json
  {
    name: name,
    color: color,
    failures: failures,
    locked: locked?
  }
end

#default_sort_keyArray

Returns:

  • (Array)


59
60
61
# File 'lib/stoplight_admin/lights_repository/light.rb', line 59

def default_sort_key
  [-COLORS.index(color), name]
end

#locked?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/stoplight_admin/lights_repository/light.rb', line 40

def locked?
  !unlocked?
end

#unlocked?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/stoplight_admin/lights_repository/light.rb', line 45

def unlocked?
  state == Stoplight::State::UNLOCKED
end