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

#pliny_envObject

DEPRECATED: pliny_env is deprecated in favour of app_env.

See more at https://github.com/interagent/pliny/issues/277

This method is kept temporary in case it is used somewhere in the app.



64
65
66
67
68
# File 'lib/pliny/config_helpers.rb', line 64

def pliny_env
  warn "Config.pliny_env is deprecated and will be removed, " \
       "use Config.app_env instead."
  env
end

#rack_envObject



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

def rack_env
  if env == "development" || env == "test"
    "development"
  else
    "deployment"
  end
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