Module: ConfConf

Defined in:
lib/conf_conf.rb,
lib/conf_conf/user.rb,
lib/conf_conf/project.rb,
lib/conf_conf/cli/root.rb,
lib/conf_conf/configuration.rb,
lib/conf_conf/project/developer.rb,
lib/conf_conf/project/developers.rb,
lib/conf_conf/project/environment.rb,
lib/conf_conf/project/environments.rb,
lib/conf_conf/project/environment/storage.rb

Defined Under Namespace

Modules: CLI Classes: Configuration, InconsistentConfigurationError, MissingConfigurationValueError, Project, Reference, User

Constant Summary collapse

VERSION =
'2.0.3'

Class Method Summary collapse

Class Method Details

.configuration(environment_name = nil, &block) ⇒ Object

TODO: This could be cleaned up considerably.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/conf_conf.rb', line 29

def configuration(environment_name=nil, &block)
  if environment_name
    # Load ENV
    project         = ConfConf::Project.new
    environment     = project.environments[environment_name]

    environment.variables.each do |name, value|
      ENV[name] = value
    end
  end

  # Run configuration block, if given
  configuration = ConfConf::Configuration.new

  if block
    configuration.run(block)
    references      = configuration.references
  else
    references      = {}
  end

  if environment_name
    # Find references to variables that aren't defaulted here
    inconsistencies = project.inconsistencies(environment)

    inconsistencies.each do |inconsistency|
      if references[inconsistency] && references[inconsistency].default_value?
        inconsistencies.delete(inconsistency)
      end
    end

    if inconsistencies.length > 0
      raise ConfConf::InconsistentConfigurationError.new(inconsistencies)
    end
  end

  OpenStruct.new(configuration.parsed_values)
end

.load(environment_name) ⇒ Object



76
77
78
# File 'lib/conf_conf.rb', line 76

def load(environment_name)
  configuration(environment_name)
end

.rails_configuration(environment_name = nil, &block) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/conf_conf.rb', line 68

def rails_configuration(environment_name=nil, &block)
  configuration = configuration(environment_name, block)

  configuration.parsed_values.each do |name, value|
    Rails.configuration.send("#{key}=", value)
  end
end