Module: B1Config

Extended by:
B1Config
Included in:
B1Config
Defined in:
lib/b1_config.rb,
lib/b1_config/loader.rb,
lib/b1_config/options.rb,
lib/b1_config/version.rb,
lib/b1_config/exception.rb,
lib/generators/b1_config/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Exception, Loader, Options

Constant Summary collapse

VERSION =
"1.0"
@@name =
"Settings"
@@env =
"development"
@@load_paths =
[]

Instance Method Summary collapse

Instance Method Details

#add_load_path(path) ⇒ Object

Add directory to config loaded path



39
40
41
42
43
# File 'lib/b1_config.rb', line 39

def add_load_path path
  path = "/" + path.to_s.split("/").reject(&:empty?).join("/") + "/"
  @@load_paths << path.to_s unless @@load_paths.include?(path.to_s)
  self
end

#get_constObject

Get registered constant



34
35
36
# File 'lib/b1_config.rb', line 34

def get_const
  B1Config.name.constantize
end

#load_constantObject

Load constant



21
22
23
24
25
# File 'lib/b1_config.rb', line 21

def load_constant
  Kernel.send(:remove_const, B1Config.name) if Kernel.const_defined?(B1Config.name)
  Kernel.const_set(B1Config.name, B1Config::Options)
  self
end

#load_dataObject Also known as: reload!

Load data from .yml files in load directories



28
29
30
31
# File 'lib/b1_config.rb', line 28

def load_data
  B1Config::Loader.load(@@load_paths)
  self
end

#remove_load_path(path) ⇒ Object

Remove directory from config loaded path



46
47
48
49
# File 'lib/b1_config.rb', line 46

def remove_load_path path
  @@load_paths.reject!{|pth| path==pth}
  self
end

#setup {|_self| ... } ⇒ Object

Setup moduleand set base params

Yields:

  • (_self)

Yield Parameters:

  • _self (B1Config)

    the object that the method was called on



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

def setup &block
  @@env = Rails.env if defined?(::Rails)
  @@load_paths << "#{Rails.root.to_s}/config/configs/"  if defined?(::Rails)
  yield self
  B1Config.load_data
  load_constant
end