Class: CaptainConfig::BooleanConfig

Inherits:
BaseConfig
  • Object
show all
Defined in:
lib/captain_config/models/boolean_config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.coerce(value) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/captain_config/models/boolean_config.rb', line 23

def self.coerce(value)
  case value
  when 'true'
    true
  when 'false'
    false
  when true
    true
  when false
    false
  else
    raise ArgumentError.new("Cannot coerce value: #{value.inspect}")
  end
end

Instance Method Details

#valueObject



4
5
6
7
8
9
10
11
12
13
# File 'lib/captain_config/models/boolean_config.rb', line 4

def value
  case self.text
  when 'true'
    true
  when 'false'
    false
  else
    raise "Invalid text: #{text.inspect}"
  end
end

#value=(new_value) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/captain_config/models/boolean_config.rb', line 15

def value=(new_value)
  if new_value != true && new_value != false
    raise ArgumentError.new("Invalid value: #{new_value.inspect}")
  end

  self.text = new_value.to_s
end