Class: PinballWizard::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/pinball_wizard/feature.rb

Direct Known Subclasses

NullFeature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Feature

Returns a new instance of Feature.



8
9
10
11
12
13
14
# File 'lib/pinball_wizard/feature.rb', line 8

def initialize(name, options = {})
  @name      = name.to_s
  @options   = options
  @active    = ensure_callable(options.fetch(:active, false))
  @options   = Helpers::Hash.without(options, :name, :active)
  @disabled  = false
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



5
6
7
# File 'lib/pinball_wizard/feature.rb', line 5

def active
  @active
end

#disabledObject (readonly)

Returns the value of attribute disabled.



6
7
8
# File 'lib/pinball_wizard/feature.rb', line 6

def disabled
  @disabled
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/pinball_wizard/feature.rb', line 6

def message
  @message
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



5
6
7
# File 'lib/pinball_wizard/feature.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/pinball_wizard/feature.rb', line 5

def options
  @options
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/pinball_wizard/feature.rb', line 18

def active?
  active.call
end

#determine_stateObject



32
33
34
# File 'lib/pinball_wizard/feature.rb', line 32

def determine_state
  # noop: use defaults
end

#disable(message = 'No reason given.') ⇒ Object



27
28
29
30
# File 'lib/pinball_wizard/feature.rb', line 27

def disable(message = 'No reason given.')
  @disabled = true
  @message = message
end

#disabled?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/pinball_wizard/feature.rb', line 22

def disabled?
  determine_state # Called here for Registry#disabled?
  disabled
end

#stateObject



36
37
38
39
40
41
42
43
44
# File 'lib/pinball_wizard/feature.rb', line 36

def state
  if disabled?
    "disabled: #{message}"
  elsif active?
    'active'
  else
    'inactive'
  end
end