co_config 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -1
- data/lib/co_config.rb +10 -4
- data/lib/co_config/loader.rb +9 -1
- data/lib/co_config/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f69473c9ade95785cfa6f57136d7d6d4615ade60
|
4
|
+
data.tar.gz: 584449eabc95751ef58023f35baca8b71978127f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99ca5f6ac8bbbe0b8f0eec4c13d3603c5c13e541e779b36a7388c0485a0cc1444d9ef5936925721ff330752271e0cc1fca888750c8aa55716b73f0a07c0c0bba
|
7
|
+
data.tar.gz: 040bb849f4e01aa00f791b7cb12b09e4d005322143fafd370c2d03f1dcb0ba02aaa8a84624292bca89b9f2f417bcac0ead900dd6380483e53ac3a97178b37930
|
data/README.md
CHANGED
@@ -54,6 +54,32 @@ defaults:
|
|
54
54
|
|
55
55
|
To read your configuration you can access the hash (with indifferent access) at `CoConfig::CONFIG_NAME_UPPERCASE`
|
56
56
|
|
57
|
+
## To use on your engine/gem
|
58
|
+
|
59
|
+
If you want to load configuration from a different path (e.g. your engine's directory), you can do this:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# lib/my_engine/railtie.rb
|
63
|
+
require 'rails/railtie'
|
64
|
+
module MyEngine
|
65
|
+
class Railtie < ::Rails::Railtie
|
66
|
+
config.before_configuration do
|
67
|
+
CoConfig.load(MyEngine::Engine.root.join('config'))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# lib/my_engine.rb
|
73
|
+
require 'my_engine/railtie'
|
74
|
+
|
75
|
+
module MyEngine
|
76
|
+
class Engine < ::Rails::Engine
|
77
|
+
end
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
It will load `my_engine/config/configuration.rb`, and in there, `load` method calls will include configuration files in the same directory.
|
82
|
+
|
57
83
|
## Development
|
58
84
|
|
59
85
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -62,7 +88,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
62
88
|
|
63
89
|
## Contributing
|
64
90
|
|
65
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
91
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/comparaonline/co_config.
|
66
92
|
|
67
93
|
|
68
94
|
## License
|
data/lib/co_config.rb
CHANGED
@@ -6,7 +6,8 @@ module CoConfig
|
|
6
6
|
class Configuration
|
7
7
|
include Loader
|
8
8
|
|
9
|
-
def initialize(file)
|
9
|
+
def initialize(file, location = nil)
|
10
|
+
@location = location if location.present?
|
10
11
|
instance_eval(File.read(file.to_s), file.to_s) if file.exist?
|
11
12
|
end
|
12
13
|
end
|
@@ -19,9 +20,14 @@ module CoConfig
|
|
19
20
|
Rails.env
|
20
21
|
end
|
21
22
|
|
22
|
-
def load
|
23
|
-
|
24
|
-
|
23
|
+
def load(location = nil)
|
24
|
+
if location.present?
|
25
|
+
path = Pathname.new(location)
|
26
|
+
Configuration.new(path.join('configuration.rb'), path)
|
27
|
+
else
|
28
|
+
file = config_path('configuration.rb')
|
29
|
+
Configuration.new(file)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
module_function :load, :config_path, :env
|
data/lib/co_config/loader.rb
CHANGED
@@ -30,11 +30,19 @@ module CoConfig
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def load_yaml(file_name)
|
33
|
-
file =
|
33
|
+
file = config_path(file_name)
|
34
34
|
fail MissingFileError.new(file_name.to_s) unless file.exist?
|
35
35
|
::YAML.load_file(file).with_indifferent_access
|
36
36
|
end
|
37
37
|
|
38
|
+
def config_path(file_name)
|
39
|
+
if defined?(@location)
|
40
|
+
@location.join(file_name)
|
41
|
+
else
|
42
|
+
CoConfig.config_path(file_name)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
38
46
|
def full_name(file_name)
|
39
47
|
if /\.yml\Z/ =~ file_name
|
40
48
|
file_name
|
data/lib/co_config/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: co_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezequiel Rabinovich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|