Module: ALaChart::Config

Defined in:
lib/a_la_chart/config.rb

Class Method Summary collapse

Class Method Details

.[](make) ⇒ Object



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

def self.[](make)
  self.config[make.to_sym]
end

.[]=(key, value) ⇒ Object



53
54
55
56
# File 'lib/a_la_chart/config.rb', line 53

def self.[]=(key, value)
  self.config unless defined?(@@data) # init the config
  @@data[key.to_sym] = value
end

.configObject

Internally, this config is represented as:

config = {
  :fusion => {
    :default => :v31,
    :v3_1 => {
      :format => 'xml',
      :pie => {
        :data => 'pie.xml.builder',
        :chart_type => 'Pie2D',
        :remote => 'remote.html.erb',
        :inline => 'inline.html.erb'
      }
    }
  }
}

Internal configs can be overridden in rails environment configs. For example, to use a custom :inline ERB template (paths are based on RAILS_ROOT):

ALaChart::Config[:fusion][:v3_1][:pie][:data] = 'app/views/reports/a_la_chart/custom_inline.html.erb'

Then just copy the original template from the gem config dir, and make the desired changes



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/a_la_chart/config.rb', line 24

def self.config
  unless defined?(@@data)
    require 'yaml'

    def self.recursive_symbolize_keys!(hash)
      hash.symbolize_keys!
      hash.values.select{|v| v.is_a?(Hash)}.each{|h| recursive_symbolize_keys!(h)}
    end
    
    @@data = {}

    Dir.foreach(File.expand_path('../../../configs',  __FILE__)) do |dir|
      config_path = File.expand_path("../../../configs/#{dir}/config.yml",  __FILE__)
      if File.exists?(config_path)
        make = dir.to_sym
        yaml_data = YAML.load_file(config_path)
        # Deep clone the yaml data
        @@data[make] = Marshal::load(Marshal.dump(yaml_data))
        self.recursive_symbolize_keys!(@@data[make])
      end
    end
  end
  @@data
end

.keysObject



59
60
61
# File 'lib/a_la_chart/config.rb', line 59

def self.keys
  self.config.keys
end