co_config 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdd0361414b259ee39ac746557ec4ec31801f6ff
4
- data.tar.gz: edf455b9d8e6cdda3b170fb6363e264082f4eca1
3
+ metadata.gz: f69473c9ade95785cfa6f57136d7d6d4615ade60
4
+ data.tar.gz: 584449eabc95751ef58023f35baca8b71978127f
5
5
  SHA512:
6
- metadata.gz: bb5721873020b98fc5899fb5f679fe68469586d6db9bda1f04356c1c22b2fb147a24c98f81f9ddbb03f42dd6bdd8c55b84352df173ba548072452264f6027fd0
7
- data.tar.gz: e1c4d748e0560f20398acfd36103f8359c335aacc491834f56a404ecc53118525f86e7c26a7aa8f1709d7075ffc25850da8c0603781db08eda4c647241290e2a
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/[USERNAME]/co_config.
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/comparaonline/co_config.
66
92
 
67
93
 
68
94
  ## License
@@ -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
- file = config_path('configuration.rb')
24
- Configuration.new(file)
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
@@ -30,11 +30,19 @@ module CoConfig
30
30
  end
31
31
 
32
32
  def load_yaml(file_name)
33
- file = CoConfig.config_path(file_name)
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
@@ -1,3 +1,3 @@
1
1
  module CoConfig
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.1
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-09-16 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport