Module: Pliny::CastingConfigHelpers

Included in:
Config
Defined in:
lib/pliny/config_helpers.rb

Instance Method Summary collapse

Instance Method Details

#array(method = nil) ⇒ Object

optional :accronyms, array(string)

> [‘a’, ‘b’]

optional :numbers, array(int)

> [1, 2]

optional :notype, array

> [‘a’, ‘b’]



46
47
48
49
50
# File 'lib/pliny/config_helpers.rb', line 46

def array(method = nil)
  ->(v) do
    v&.split(",")&.map { |a| cast(a, method) }
  end
end

#boolObject



28
29
30
# File 'lib/pliny/config_helpers.rb', line 28

def bool
  ->(v) { v.to_s == "true" }
end

#floatObject



24
25
26
# File 'lib/pliny/config_helpers.rb', line 24

def float
  ->(v) { v.to_f }
end

#intObject



20
21
22
# File 'lib/pliny/config_helpers.rb', line 20

def int
  ->(v) { v.to_i }
end

#mandatory(name, method = nil) ⇒ Object



5
6
7
8
# File 'lib/pliny/config_helpers.rb', line 5

def mandatory(name, method = nil)
  value = cast(ENV.fetch(name.to_s.upcase), method)
  create(name, value)
end

#optional(name, method = nil) ⇒ Object



10
11
12
13
# File 'lib/pliny/config_helpers.rb', line 10

def optional(name, method = nil)
  value = cast(ENV[name.to_s.upcase], method)
  create(name, value)
end

#override(name, default, method = nil) ⇒ Object



15
16
17
18
# File 'lib/pliny/config_helpers.rb', line 15

def override(name, default, method = nil)
  value = cast(ENV.fetch(name.to_s.upcase, default), method)
  create(name, value)
end

#rack_envObject



52
53
54
55
56
57
58
# File 'lib/pliny/config_helpers.rb', line 52

def rack_env
  if app_env == "development" || app_env == "test"
    "development"
  else
    "deployment"
  end
end

#stringObject



32
33
34
# File 'lib/pliny/config_helpers.rb', line 32

def string
  nil
end

#symbolObject



36
37
38
# File 'lib/pliny/config_helpers.rb', line 36

def symbol
  ->(v) { v.to_sym }
end