Module: RestGraph::ConfigUtil

Extended by:
ConfigUtil
Included in:
ConfigUtil
Defined in:
lib/rest-graph/config_util.rb

Instance Method Summary collapse

Instance Method Details

#load_config(file, env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rest-graph/config_util.rb', line 24

def load_config file, env
  config   = YAML.load(ERB.new(File.read(file)).result(binding))
  defaults = config[env]
  return unless defaults

  mod = Module.new
  mod.module_eval(defaults.inject([]){ |r, (k, v)|
    # quote strings, leave others free (e.g. false, numbers, etc)
    r << <<-RUBY
      def default_#{k}
        #{v.kind_of?(String) ? "'#{v}'" : v}
      end
    RUBY
  }.join, __FILE__, __LINE__)

  RestGraph.send(:extend, mod)
end

#load_config_for_allObject



10
11
12
13
# File 'lib/rest-graph/config_util.rb', line 10

def load_config_for_all
  RestGraph::ConfigUtil.load_config_for_rails if
    Object.const_defined?(:Rails)
end

#load_config_for_rails(app = Rails) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/rest-graph/config_util.rb', line 15

def load_config_for_rails app=Rails
  root = app.root
  file = ["#{root}/config/rest-graph.yaml", # YAML should use .yaml
          "#{root}/config/rest-graph.yml"].find{|path| File.exist?(path)}
  return unless file

  RestGraph::ConfigUtil.load_config(file, Rails.env)
end