Module: Configs

Defined in:
lib/configs.rb

Overview

Systemwide Singleton, which can be used to store global configurations, like paths or some other settings

Examples:

Usage

Configs.set :foo, 123
Configs.foo #=> 123

Configs.set :foo => 456, :bar => "Hello World"
Configs.foo #=> 456
Configs.bar #=> "Hello World"

Configs.baz #=> nil

List all configs

Configs.attributes #=> { :foo => 456, :bar => "Hello World" }

Real dump of Configs, after setting up DocJs

Configs.attributes #=> [:root, :options, :wdir, :output, :templates, :files, :docs] 

Configs.root       #=> #<Pathname:/path/to/application/root>
Configs.options    #=>  {:files=>["test/js-files/core-doc.js"], :docs=>["test/docs/*.md"], 
                   #     :output=>"out", :templates=>#<Pathname:/path/to/templates>, 
                   #     :appname=>"Doc.js", :loglevel=>"debug"} 
Configs.wdir       #=> "/path/to/working/directory"
Configs.output     #=> "/path/to/output/directory"
Configs.templates  #=> "/path/to/used/template/directory"
Configs.files      #=> ["test/js-files/core-doc.js"] 
Configs.docs       #=> ["test/docs/README.md", "test/docs/README.CONCEPT.md"]

Class Method Summary collapse

Class Method Details

.attributesObject



42
43
44
45
46
# File 'lib/configs.rb', line 42

def self.attributes
  class_variables.map do |var|
    var.to_s.scan(/@@(.*)/).first.first.to_sym
  end
end

.clearObject



52
53
54
55
56
# File 'lib/configs.rb', line 52

def self.clear
  class_variables.each do |var|
    class_variable_set(var, nil)
  end
end

.method_missing(method_name, *args) ⇒ Object



48
49
50
# File 'lib/configs.rb', line 48

def self.method_missing(method_name, *args)
  nil
end

.set(sym_or_hash, value = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/configs.rb', line 31

def self.set(sym_or_hash, value = nil)

  unless sym_or_hash.is_a? Hash
    sym_or_hash = { sym_or_hash => value }  
  end

  sym_or_hash.each_pair do |attr, value|
    set_attribute(attr, value)
  end
end