Module: HConfig

Defined in:
lib/hconfig.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’]



45
46
47
48
49
50
51
# File 'lib/hconfig.rb', line 45

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

#boolObject



27
28
29
# File 'lib/hconfig.rb', line 27

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

#floatObject



23
24
25
# File 'lib/hconfig.rb', line 23

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

#intObject



19
20
21
# File 'lib/hconfig.rb', line 19

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

#mandatory(name, method = nil) ⇒ Object



4
5
6
7
# File 'lib/hconfig.rb', line 4

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

#optional(name, method = nil) ⇒ Object



9
10
11
12
# File 'lib/hconfig.rb', line 9

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

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



14
15
16
17
# File 'lib/hconfig.rb', line 14

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

#stringObject



31
32
33
# File 'lib/hconfig.rb', line 31

def string
  nil
end

#symbolObject



35
36
37
# File 'lib/hconfig.rb', line 35

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