Class: ENVied

Inherits:
Object
  • Object
show all
Defined in:
lib/envied.rb,
lib/envied/cli.rb,
lib/envied/version.rb,
lib/envied/configuration.rb

Defined Under Namespace

Classes: Cli, Coercer, Configuration, EnvProxy, Variable

Constant Summary collapse

VERSION =
'0.7.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

.envObject (readonly)

Returns the value of attribute env.



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

def env
  @env
end

Class Method Details

.error_on_missing_variables!Object



20
21
22
23
# File 'lib/envied.rb', line 20

def self.error_on_missing_variables!
  names = env.missing_variables.map(&:name)
  raise "The following environment variables should be set: #{names * ', '}" if names.any?
end

.error_on_uncoercible_variables!Object



25
26
27
28
29
30
# File 'lib/envied.rb', line 25

def self.error_on_uncoercible_variables!
  errors = env.uncoercible_variables.map do |v|
    "%{name} ('%{value}' can't be coerced to %{type})" % {name: v.name, value: env.value_to_coerce(v), type: v.type }
  end
  raise "The following environment variables are not coercible: #{errors.join(", ")}" if errors.any?
end

.method_missing(method, *args, &block) ⇒ Object



49
50
51
# File 'lib/envied.rb', line 49

def self.method_missing(method, *args, &block)
  respond_to_missing?(method) ? (env && env[method.to_s]) : super
end

.require(*groups) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/envied.rb', line 12

def self.require(*groups)
  @config ||= Configuration.load
  @env ||= EnvProxy.new(@config, groups: required_groups(*groups))

  error_on_missing_variables!
  error_on_uncoercible_variables!
end

.required_groups(*groups) ⇒ Object



32
33
34
35
# File 'lib/envied.rb', line 32

def self.required_groups(*groups)
  result = groups.compact
  result.any? ? result.map(&:to_sym) : [:default]
end

.respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/envied.rb', line 53

def self.respond_to_missing?(method, include_private = false)
  (env && env.has_key?(method)) || super
end

.spring_enabled?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/envied.rb', line 45

def self.spring_enabled?
  defined?(Spring) && Spring.respond_to?(:watcher)
end

.springify(&block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/envied.rb', line 37

def self.springify(&block)
  if spring_enabled?
    Spring.after_fork(&block)
  else
    block.call
  end
end