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’]



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

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

#boolObject



26
27
28
# File 'lib/pliny/config_helpers.rb', line 26

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

#floatObject



22
23
24
# File 'lib/pliny/config_helpers.rb', line 22

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

#intObject



18
19
20
# File 'lib/pliny/config_helpers.rb', line 18

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

#mandatory(name, method = nil) ⇒ Object



3
4
5
6
# File 'lib/pliny/config_helpers.rb', line 3

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

#optional(name, method = nil) ⇒ Object



8
9
10
11
# File 'lib/pliny/config_helpers.rb', line 8

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

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



13
14
15
16
# File 'lib/pliny/config_helpers.rb', line 13

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

#stringObject



30
31
32
# File 'lib/pliny/config_helpers.rb', line 30

def string
  nil
end

#symbolObject



34
35
36
# File 'lib/pliny/config_helpers.rb', line 34

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