Class: DearInventory::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/dear_inventory/environment.rb

Constant Summary collapse

ENVIRONMENTS =
%i[production test].freeze

Class Method Summary collapse

Class Method Details

.production?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/dear_inventory/environment.rb', line 9

def production?
  to_sym == :production
end

.set(value) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
# File 'lib/dear_inventory/environment.rb', line 23

def set(value)
  return @to_sym = value if ENVIRONMENTS.include?(value)

  error_value = value.is_a?(Symbol) ? ":#{value}" : value.to_s
  raise(
    ArgumentError,
    "#{error_value} is not an acceptable environment; " \
      "please use either :production or :test"
  )
end

.test?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dear_inventory/environment.rb', line 13

def test?
  to_sym == :test
end

.to_symObject



17
18
19
# File 'lib/dear_inventory/environment.rb', line 17

def to_sym
  @to_sym ||= set(default)
end