configloader 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -21,28 +21,28 @@ If you need to create a custom config file for you Rails project, ConfigLoader w
21
21
  test:
22
22
  server: localhost
23
23
  port: 5984
24
- database_name: addressbook_development
24
+ database_name: addressbook_test
25
25
 
26
26
  production:
27
27
  server: production.server.com
28
28
  port: 5984
29
- database_name: addressbook_development
29
+ database_name: addressbook_production
30
30
 
31
31
  In order to access the database configuration for your current environment, you'd write, for instance:
32
32
 
33
33
  db_config = ConfigLoader.load('database')
34
- db_config['server'] # localhost
35
- db_config[:server] # localhost
36
- db_config.server # localhost
34
+ db_config['server'] # localhost
35
+ db_config['port'] # 5984
36
+ db_config['database_name'] # addressbook_development
37
37
 
38
38
  We're assuming that your current environment is development.
39
39
 
40
40
  You can get the configuration of a specific running environment writing this:
41
41
 
42
42
  db_config = ConfigLoader.load('database', 'production')
43
- db_config['server'] # production.server.com
44
- db_config[:server] # production.server.com
45
- db_config.server # production.server.com
43
+ db_config['server'] # production.server.com
44
+ db_config['port'] # 5984
45
+ db_config['database_name'] # addressbook_production
46
46
 
47
47
  Finally, you can specify the project root too. If you don't, it will assume the project root is RAILS_ROOT.
48
48
  To change it, write:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/configloader.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{configloader}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Vinicius Teles"]
data/lib/config_loader.rb CHANGED
@@ -13,28 +13,28 @@ module ConfigLoader
13
13
  # test:
14
14
  # server: localhost
15
15
  # port: 5984
16
- # database_name: addressbook_development
16
+ # database_name: addressbook_test
17
17
  #
18
18
  # production:
19
19
  # server: production.server.com
20
20
  # port: 5984
21
- # database_name: addressbook_development
21
+ # database_name: addressbook_production
22
22
  #
23
23
  # In order to access the database configuration for your current environment, you'd write, for instance:
24
24
  #
25
25
  # db_config = ConfigLoader.load('database')
26
- # db_config['server'] # localhost
27
- # db_config[:server] # localhost
28
- # db_config.server # localhost
26
+ # db_config['server'] # localhost
27
+ # db_config['port'] # 5984
28
+ # db_config['database_name'] # addressbook_development
29
29
  #
30
30
  # We're assuming that your current environment is development.
31
31
  #
32
32
  # You can get the configuration of a specific running environment writing this:
33
33
  #
34
34
  # db_config = ConfigLoader.load('database', 'production')
35
- # db_config['server'] # production.server.com
36
- # db_config[:server] # production.server.com
37
- # db_config.server # production.server.com
35
+ # db_config['server'] # production.server.com
36
+ # db_config['port'] # 5984
37
+ # db_config['database_name'] # addressbook_production
38
38
  #
39
39
  # Finally, you can specify the project root too. If you don't, it will assume the project root is RAILS_ROOT. To change it, write:
40
40
  #
@@ -42,9 +42,7 @@ module ConfigLoader
42
42
  # db_config = ConfigLoader.load('database', 'production')
43
43
  # db_config = ConfigLoader.load('database', 'test', '/home/user/my_special_project_root')
44
44
  def self.load(file_name, running_env = Rails.env, project_root = RAILS_ROOT)
45
- map = ConfigLoader::Map.new(file_name, running_env, project_root)
46
- map.populate
47
- map
45
+ ConfigLoader::Map.new(file_name, running_env, project_root).load
48
46
  end
49
47
 
50
48
  end
@@ -1,6 +1,6 @@
1
1
  module ConfigLoader
2
2
 
3
- class Map < Hash
3
+ class Map
4
4
 
5
5
  attr_reader :file_name, :running_env, :project_root
6
6
 
@@ -20,11 +20,8 @@ module ConfigLoader
20
20
  "#{project_root}/config/#{file_name}"
21
21
  end
22
22
 
23
- def populate
24
- file_content[@running_env].each do |key, value|
25
- self[key] = value
26
- self[key.to_sym] = value
27
- end
23
+ def load
24
+ file_content[@running_env]
28
25
  end
29
26
 
30
27
  def method_missing(method_name)
@@ -57,24 +57,15 @@ module ConfigLoader
57
57
 
58
58
  end
59
59
 
60
- describe ".populate" do
60
+ describe ".load" do
61
61
 
62
62
  it "should load config for a specific running environment" do
63
- file_content = { 'development' =>
64
- { 'server' => 'localhost',
65
- 'port' => 5984,
66
- 'name' => 'customers' } }
63
+ development_config = { 'server' => 'localhost',
64
+ 'port' => 5984,
65
+ 'name' => 'customers' }
66
+ file_content = { 'development' => development_config }
67
67
  @config_loader.should_receive(:file_content).and_return(file_content)
68
- @config_loader.populate
69
- @config_loader['server'].should == 'localhost'
70
- @config_loader[:server].should == 'localhost'
71
- @config_loader.server.should == 'localhost'
72
- @config_loader['port'].should == 5984
73
- @config_loader[:port].should == 5984
74
- @config_loader.port.should == 5984
75
- @config_loader['name'].should == 'customers'
76
- @config_loader[:name].should == 'customers'
77
- @config_loader.name.should == 'customers'
68
+ @config_loader.load.should == development_config
78
69
  end
79
70
 
80
71
  end
@@ -7,7 +7,7 @@ describe "ConfigLoader" do
7
7
  def prepare_mocks(running_env, project_root)
8
8
  Rails.stub!(:env).and_return(running_env)
9
9
  ConfigLoader::Map.should_receive(:new).with('database', running_env, project_root).and_return(@map_mock)
10
- @map_mock.should_receive(:populate)
10
+ @map_mock.should_receive(:load).and_return('config')
11
11
  end
12
12
 
13
13
  before(:each) do
@@ -16,17 +16,17 @@ describe "ConfigLoader" do
16
16
 
17
17
  it "should delegate to ConfigLoader::Map.populate" do
18
18
  prepare_mocks('development', '/home/user/project')
19
- ConfigLoader.load('database').should == @map_mock
19
+ ConfigLoader.load('database').should == 'config'
20
20
  end
21
21
 
22
22
  it "should delegate to ConfigLoader::Map.populate with the given running_env" do
23
23
  prepare_mocks('production', '/home/user/project')
24
- ConfigLoader.load('database', 'production').should == @map_mock
24
+ ConfigLoader.load('database', 'production').should == 'config'
25
25
  end
26
26
 
27
27
  it "should delegate to ConfigLoader::Map.populate with the given project_root" do
28
28
  prepare_mocks('development', '/home/user/another_project')
29
- ConfigLoader.load('database', 'development', '/home/user/another_project').should == @map_mock
29
+ ConfigLoader.load('database', 'development', '/home/user/another_project').should == 'config'
30
30
  end
31
31
 
32
32
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Vinicius Teles