global 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93e3427e1eb0655bda5b432903488038d53ffa6f
4
- data.tar.gz: 8dd72fdd5856a96a15e9cf0c4b63448e45298b9a
3
+ metadata.gz: bf9612fdc8fa99d0ccb806cdd8f6c997d5341fd2
4
+ data.tar.gz: 2fb51ee37ba5a8a8a84030d3a9ca88c659b92546
5
5
  SHA512:
6
- metadata.gz: 55e64a30578abff796bc7305095857a624e5af9bf3defe5da465461fdb0db316f7d29e42497d76d1ef8e1a36646c3527adfb46b551b4b06542ed73b464d447b9
7
- data.tar.gz: 0d4f0672ce23acadeb374cf3dbf3695e5828b2d53718a956c52886d5bb5b547072e53e39d88a5f13525c2e645a4595a91c9717b6ab214b7abaeeb7ad6f3c7e8f
6
+ metadata.gz: 3c4cd0806d42bc1c84225b93c70d9ce64c6b4d4de551605d0686144b2c1c6acb62a7b99edeecedc08a0253c1764940f3e123f8959cd17eec5a455d1b3748c98f
7
+ data.tar.gz: e7c5106419074bd61dbba4ea5ba80f23b237a0a05b6e40aafc1cba80e57588e786f46b87d2777388dd1513cc2983f0415506c064c8b99f72218c2ff59386b494
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # global [![Build Status](https://travis-ci.org/paladiy/global.png)](https://travis-ci.org/paladiy/global) [![Code Climate](https://codeclimate.com/github/paladiy/global.png)](https://codeclimate.com/github/paladiy/global)
1
+ # global [![Build Status](https://travis-ci.org/railsware/global.png)](https://travis-ci.org/railsware/global) [![Code Climate](https://codeclimate.com/github/railsware/global.png)](https://codeclimate.com/github/railsware/global)
2
2
 
3
3
  ## Description
4
4
 
@@ -17,24 +17,104 @@ gem 'global'
17
17
  > Global.config_directory = "PATH_TO_DIRECTORY_WITH_FILES"
18
18
  ```
19
19
 
20
- ##Usage
20
+ For rails put initialization into `config/initializers/global.rb`
21
21
 
22
- Loading configuration from: `PATH_TO_DIRECTORY_WITH_FILES/hosts.yml`
22
+ ```ruby
23
+ Global.environment = Rails.env.to_s
24
+ Global.config_directory = Rails.root.join('config/global').to_s
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ### General
30
+
31
+ Config file `config/global/hosts.yml`:
32
+
33
+ ```yml
34
+ test:
35
+ web: localhost
36
+ api: api.localhost
37
+ development:
38
+ web: localhost
39
+ api: api.localhost
40
+ production:
41
+ web: myhost.com
42
+ api: api.myhost.com
43
+ ```
44
+
45
+ Now for development environment we have next data:
23
46
 
24
47
  ```ruby
25
48
  > Global.hosts
26
- => { "api" => "api.localhost.dev", "app" => "localhost.dev" }
49
+ => { "api" => "api.localhost", "web" => "localhost" }
27
50
  > Global.hosts.api
28
- => { "api" => "api.localhost.dev" }
51
+ => "api.localhost"
52
+ ```
53
+
54
+ ### Namespacing
55
+
56
+ Config file `config/global/web/basic_auth.yml` with:
57
+
58
+ ```yml
59
+ test:
60
+ username: user
61
+ password: secret
62
+ development:
63
+ username: user
64
+ password: secret
65
+ production:
66
+ username: production_user
67
+ password: supersecret
68
+ ```
69
+
70
+ After that in development environment we have:
71
+
72
+ ```ruby
73
+ > Global.web.basic_auth
74
+ => { "username" => "development_user", "password" => "secret" }
75
+ > Global.web.basic_auth.username
76
+ => "development_user"
77
+ ```
78
+
79
+ ### Default section
80
+
81
+ Config file example:
82
+
83
+ ```yml
84
+ default:
85
+ web: localhost
86
+ api: api.localhost
87
+ production:
88
+ web: myhost.com
89
+ api: api.myhost.com
90
+ ```
91
+
92
+ Data from default section uses until it's overridden in specific environment.
93
+
94
+ ### ERB support
95
+
96
+ Config file 'global/file_name.yml' with:
97
+
98
+ ```yml
99
+ test:
100
+ key: <%=1+1%>
101
+ development:
102
+ key: <%=2+2%>
103
+ production:
104
+ key: <%=3+3%>
105
+ ```
106
+
107
+ As a result in development environment we have:
108
+
109
+ ```ruby
110
+ > Global.file_name.key
111
+ => 4
29
112
  ```
30
113
 
31
- Loading recursive from: `PATH_TO_DIRECTORY_WITH_FILES/sites/api.yml`
114
+ ### Reload configuration data
32
115
 
33
116
  ```ruby
34
- > Global.sites.api
35
- => { "host" => "api.localhost.dev", "port" => 3000 }
36
- > Global.sites.api.host
37
- => "api.localhost.dev"
117
+ > Global.reload!
38
118
  ```
39
119
 
40
120
  ## Contributing to global
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.homepage = "http://github.com/paladiy/global"
20
+ s.homepage = "https://github.com/railsware/global"
21
21
  s.licenses = ["MIT"]
22
22
 
23
23
  s.add_development_dependency "rspec", "~> 2.14.1"
@@ -2,15 +2,19 @@ require "erb"
2
2
 
3
3
  module Global
4
4
  module Base
5
- def configuration(env = nil)
6
- @configuration = nil if env
7
- @configuration ||= load_configuration(config_directory, env.is_a?(String) ? env : environment)
5
+ def configuration
6
+ @configuration ||= load_configuration(config_directory, environment)
7
+ end
8
+
9
+ def reload!
10
+ @configuration = nil
11
+ configuration
8
12
  end
9
13
 
10
14
  def environment=(env)
11
15
  @environment = env
12
16
  end
13
-
17
+
14
18
  def config_directory=(dir)
15
19
  @config_directory = dir
16
20
  end
@@ -24,10 +28,10 @@ module Global
24
28
  end
25
29
 
26
30
  protected
27
-
31
+
28
32
  def load_configuration(dir, env)
29
33
  config = load_from_file(dir, env)
30
-
34
+
31
35
  config.deep_merge!(load_from_directory(dir, env))
32
36
 
33
37
  Configuration.new(config)
@@ -35,10 +39,10 @@ module Global
35
39
 
36
40
  def load_from_file(dir, env)
37
41
  config = {}
38
-
42
+
39
43
  if File.exists?(file = "#{dir}.yml")
40
44
  configurations = YAML::load(ERB.new(IO.read(file)).result)
41
- config = configurations[:default] || {}
45
+ config = configurations[:default] || configurations["default"] || {}
42
46
  config.deep_merge!(configurations[env] || {})
43
47
  end
44
48
 
@@ -47,7 +51,7 @@ module Global
47
51
 
48
52
  def load_from_directory(dir, env)
49
53
  config = {}
50
-
54
+
51
55
  if File.directory?(dir)
52
56
  Dir["#{dir}/*"].each do |entry|
53
57
  namespace = entry.gsub(/^#{dir}\/?/, '').gsub(/\.yml$/, '')
@@ -55,9 +59,9 @@ module Global
55
59
  end
56
60
  end
57
61
 
58
- config
62
+ config
59
63
  end
60
-
64
+
61
65
  def method_missing(method, *args, &block)
62
66
  configuration.key?(method) ? configuration[method] : super
63
67
  end
@@ -1,3 +1,3 @@
1
1
  module Global
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,4 +1,8 @@
1
1
  :default:
2
2
  default_value: "default value"
3
+
3
4
  test:
4
- test_value: "test value"
5
+ test_value: "test value"
6
+
7
+ development:
8
+ test_value: "development value"
@@ -50,6 +50,23 @@ describe Global do
50
50
  end
51
51
  end
52
52
 
53
+ context ".reload!" do
54
+ subject{ described_class.reload! }
55
+
56
+ before do
57
+ described_class.configuration
58
+ described_class.environment = "development"
59
+ end
60
+
61
+ after do
62
+ described_class.environment = "test"
63
+ described_class.reload!
64
+ end
65
+
66
+ it{ should be_instance_of(Global::Configuration) }
67
+ its("rspec_config.to_hash"){ should == {"default_value"=>"default value", "test_value"=>"development value"} }
68
+ end
69
+
53
70
  describe ".method_missing" do
54
71
  context "when file exists" do
55
72
  subject{ described_class.rspec_config }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - paladiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-18 00:00:00.000000000 Z
11
+ date: 2013-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -90,7 +90,7 @@ files:
90
90
  - spec/global/configuration_spec.rb
91
91
  - spec/global_spec.rb
92
92
  - spec/spec_helper.rb
93
- homepage: http://github.com/paladiy/global
93
+ homepage: https://github.com/railsware/global
94
94
  licenses:
95
95
  - MIT
96
96
  metadata: {}