complex_config 0.4.0 → 0.5.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: ce05b6145a1404ee49c681b56299be1ea31fb1e4
4
- data.tar.gz: 8056f3a0946139f199c27d2f72bfef27f9b7c4eb
3
+ metadata.gz: c0f60e08a3a290db243d83585edac94e0c62bd4c
4
+ data.tar.gz: 8bd5bbe19ba7f8001ab5ba4b2bf16f6efd43fad8
5
5
  SHA512:
6
- metadata.gz: 0e333940bdbf7bc28857ecddde5986b754cc90e388ed077faa53608fee1e9440b64890893581a906da8e0b53d4eb50459b25afeef382dc8eaef87cef5d696842
7
- data.tar.gz: 2cc771c28cdbdb6ada774b87f63b20b8f46b94074571b808c5179dc52ce55a2fb7d8c9b057b25f7e98f047aff893404879fac80b14a835fe2dccc454eb8e82e2
6
+ metadata.gz: 338b9417076107d634da170a25bcebe833762efcc197099c1fe87bd0621a04403fd901b85639b89accdcf7401cd6929d60687ea636b82371cba0c4d828e5594c
7
+ data.tar.gz: 60865b2f017981a53a09b4e0b7e7a430cc1c7c8cbc39c51dddcba93b0b3bd24eb47ab877a1ecafc2ecd5fccab29837fc30650571a660f66913ef18412bf4e82e
data/.gitignore CHANGED
@@ -1,7 +1,9 @@
1
1
  .*.sw[pon]
2
2
  .AppleDouble
3
3
  .DS_Store
4
+ .byebug_history
4
5
  .rvmrc
5
6
  Gemfile.lock
6
7
  coverage
8
+ errors.lst
7
9
  pkg
data/README.md CHANGED
@@ -88,12 +88,39 @@ namespacing via the `RAILS_ENV` environment, so
88
88
  `complex_config(:products).test.flux_capacitor` returns the same settings
89
89
  object.
90
90
 
91
+ ### Configuration
92
+
93
+ You can complex\_config by passing a block to its configure method, which you
94
+ can for example do in a rails config/initializers file:
95
+
96
+ ComplexConfig.configure do |config|
97
+ config.deep_freeze = !Rails.env.test? # allow modification during tests b/c of stubs etc.
98
+
99
+ # config.env = 'some_environment'
100
+
101
+ # config.config_dir = Rails.root + 'config'
102
+
103
+ config.add_plugin -> id do
104
+ if base64_string = ask_and_send("#{id}_base64")
105
+ Base64.decode64 base64_string
106
+ else
107
+ skip
108
+ end
109
+ end
110
+ end
111
+
91
112
  ### Adding plugins
92
113
 
93
114
  You can add your own plugins by calling
94
115
 
95
116
  ComplexConfig::Provider.add_plugin SomeNamespace::PLUGIN
96
117
 
118
+ or in the configuration block by calling
119
+
120
+ ComplexConfig.configure do |config|
121
+ config.add_plugin SomeNamespace::PLUGIN
122
+ end
123
+
97
124
  ### Implementing your own plugins
98
125
 
99
126
  A plugin is just a lambda expression with a single argument `id` which
@@ -116,6 +143,9 @@ Here is the `ComplexConfig::Plugins::MONEY` plugin for example:
116
143
  end
117
144
 
118
145
  ## Changes
146
+ * 2015-11-19 Release 0.5.0
147
+ * Support rails reloading behaviour.
148
+ * Allow configuration via ComplexConfig.configure(&block) method.
119
149
  * 2015-11-17 Release 0.4.0
120
150
  * Add root object for configuration, e. g. cc.name instead of cc(name).
121
151
  * 2015-11-03 Release 0.3.1
data/Rakefile CHANGED
@@ -10,7 +10,9 @@ GemHadar do
10
10
  summary 'configuration library'
11
11
  description 'This library allows you to access configuration files via a simple interface'
12
12
  test_dir 'spec'
13
- ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc', '.AppleDouble', '.DS_Store'
13
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
14
+ '.AppleDouble', '.DS_Store', '.byebug_history', 'errors.lst'
15
+
14
16
  readme 'README.md'
15
17
  title "#{name.camelize} -- configuration library"
16
18
  licenses << 'Apache-2.0'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -1,24 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: complex_config 0.4.0 ruby lib
2
+ # stub: complex_config 0.5.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "complex_config"
6
- s.version = "0.4.0"
6
+ s.version = "0.5.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Florian Frank"]
11
- s.date = "2015-11-17"
11
+ s.date = "2015-11-19"
12
12
  s.description = "This library allows you to access configuration files via a simple interface"
13
13
  s.email = "flori@ping.de"
14
- s.extra_rdoc_files = ["README.md", "lib/complex_config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/proxy.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb"]
15
- s.files = [".gitignore", ".rspec", ".travis.yml", ".utilsrc", "COPYING", "Gemfile", "README.md", "Rakefile", "TODO.md", "VERSION", "complex_config.gemspec", "config/products.yml", "lib/complex_config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/proxy.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb", "spec/complex_config/plugins_spec.rb", "spec/complex_config/provider_spec.rb", "spec/complex_config/settings_spec.rb", "spec/complex_config/shortcuts_spec.rb", "spec/config/broken_config.yml", "spec/config/config.yml", "spec/spec_helper.rb"]
14
+ s.extra_rdoc_files = ["README.md", "lib/complex_config.rb", "lib/complex_config/config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/proxy.rb", "lib/complex_config/railtie.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb"]
15
+ s.files = [".gitignore", ".rspec", ".travis.yml", ".utilsrc", "COPYING", "Gemfile", "README.md", "Rakefile", "TODO.md", "VERSION", "complex_config.gemspec", "config/products.yml", "lib/complex_config.rb", "lib/complex_config/config.rb", "lib/complex_config/errors.rb", "lib/complex_config/plugins.rb", "lib/complex_config/plugins/enable.rb", "lib/complex_config/plugins/money.rb", "lib/complex_config/plugins/uri.rb", "lib/complex_config/provider.rb", "lib/complex_config/proxy.rb", "lib/complex_config/railtie.rb", "lib/complex_config/rude.rb", "lib/complex_config/settings.rb", "lib/complex_config/shortcuts.rb", "lib/complex_config/version.rb", "spec/complex_config/config_spec.rb", "spec/complex_config/plugins_spec.rb", "spec/complex_config/provider_spec.rb", "spec/complex_config/settings_spec.rb", "spec/complex_config/shortcuts_spec.rb", "spec/config/broken_config.yml", "spec/config/config.yml", "spec/spec_helper.rb"]
16
16
  s.homepage = "https://github.com/flori/complex_config"
17
17
  s.licenses = ["Apache-2.0"]
18
18
  s.rdoc_options = ["--title", "ComplexConfig -- configuration library", "--main", "README.md"]
19
19
  s.rubygems_version = "2.5.0"
20
20
  s.summary = "configuration library"
21
- s.test_files = ["spec/complex_config/plugins_spec.rb", "spec/complex_config/provider_spec.rb", "spec/complex_config/settings_spec.rb", "spec/complex_config/shortcuts_spec.rb", "spec/spec_helper.rb"]
21
+ s.test_files = ["spec/complex_config/config_spec.rb", "spec/complex_config/plugins_spec.rb", "spec/complex_config/provider_spec.rb", "spec/complex_config/settings_spec.rb", "spec/complex_config/shortcuts_spec.rb", "spec/spec_helper.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  s.specification_version = 4
@@ -7,4 +7,8 @@ require 'complex_config/version'
7
7
  require 'complex_config/errors'
8
8
  require 'complex_config/proxy'
9
9
  require 'complex_config/settings'
10
+ require 'complex_config/config'
10
11
  require 'complex_config/provider'
12
+ defined? Rails and require 'complex_config/railtie'
13
+
14
+
@@ -0,0 +1,32 @@
1
+ module ComplexConfig
2
+ Config = Struct.new('Config', :config_dir, :env, :deep_freeze, :plugins) do
3
+ def initialize(*)
4
+ super
5
+ self.plugins = []
6
+ end
7
+
8
+ def configure(provider)
9
+ each_pair do |name, value|
10
+ value.nil? and next
11
+ name == :plugins and next
12
+ provider.__send__("#{name}=", value)
13
+ end
14
+ plugins.each do |code|
15
+ provider.add_plugin(code)
16
+ end
17
+ self
18
+ end
19
+
20
+ def add_plugin(code)
21
+ plugins << code
22
+ self
23
+ end
24
+ end
25
+
26
+ def self.configure
27
+ config = Config.new
28
+ yield config
29
+ ComplexConfig::Provider.configure_with config
30
+ config
31
+ end
32
+ end
@@ -11,6 +11,11 @@ class ComplexConfig::Provider
11
11
  @deep_freeze = true
12
12
  end
13
13
 
14
+ def configure_with(config)
15
+ config.configure(self)
16
+ flush_cache
17
+ end
18
+
14
19
  attr_reader :plugins
15
20
 
16
21
  def add_plugin(plugin)
@@ -33,8 +38,20 @@ class ComplexConfig::Provider
33
38
  end
34
39
  end
35
40
 
41
+ def config_dir=(dir)
42
+ if dir.nil?
43
+ @config_dir = nil
44
+ else
45
+ @config_dir = Pathname.new(dir)
46
+ end
47
+ end
48
+
49
+ def config_dir
50
+ @config_dir || (defined?(Rails) && Rails.root || Pathname.pwd) + 'config'
51
+ end
52
+
36
53
  def pathname(name)
37
- root + "config/#{name}.yml"
54
+ config_dir + "#{name}.yml"
38
55
  end
39
56
 
40
57
  def config(pathname, name = nil)
@@ -70,15 +87,9 @@ class ComplexConfig::Provider
70
87
  erb.result
71
88
  end
72
89
 
73
- attr_writer :root
74
-
75
- def root
76
- @root || defined?(Rails) && Rails.root || Pathname.pwd
77
- end
78
-
79
- attr_writer :env
80
-
81
90
  def env
82
91
  @env || defined?(Rails) && Rails.env || ENV['RAILS_ENV'] || 'development'
83
92
  end
93
+
94
+ attr_writer :env
84
95
  end
@@ -0,0 +1,7 @@
1
+ module ComplexConfig
2
+ class Railtie < Rails::Railtie
3
+ config.to_prepare do
4
+ ComplexConfig::Provider.flush_cache
5
+ end
6
+ end
7
+ end
@@ -1,6 +1,6 @@
1
1
  module ComplexConfig
2
2
  # ComplexConfig version
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ComplexConfig::Config do
4
+ let :plugin_code do
5
+ -> id { skip }
6
+ end
7
+
8
+ it 'configures' do
9
+ ComplexConfig.configure do |config|
10
+ config.config_dir = 'foo'
11
+ config.env = 'bar'
12
+ config.add_plugin plugin_code
13
+ end
14
+ expect(ComplexConfig::Provider.config_dir).to eq Pathname.new('foo')
15
+ expect(ComplexConfig::Provider.env).to eq 'bar'
16
+ expect(ComplexConfig::Provider.plugins).to include plugin_code
17
+ end
18
+ end
19
+
@@ -34,28 +34,22 @@ RSpec.describe ComplexConfig::Provider do
34
34
  end
35
35
 
36
36
  context 'pathnames' do
37
- module ::Rails
38
- def self.root
39
- end unless respond_to?(:root)
40
- end
41
-
42
- after do
43
- provider.root = nil
44
- end
45
-
46
- it 'can compute default pathname' do
47
- provider.root = Pathname.new('bar')
48
- expect(provider.pathname('foo')).to eq Pathname.new('bar/config/foo.yml')
37
+ before do
38
+ module ::Rails
39
+ def self.root
40
+ end
41
+ end
42
+ provider.config_dir = nil
49
43
  end
50
44
 
51
45
  it 'can derive rails root from Rails.root if present' do
52
- dir = Pathname.new('bar')
53
- expect(Rails).to receive(:root).and_return(dir)
54
- expect(provider.root).to eq dir
46
+ allow(::Rails).to receive(:root).and_return Pathname.new('bar')
47
+ dir = Pathname.new('bar/config')
48
+ expect(provider.config_dir).to eq dir
55
49
  end
56
50
 
57
51
  it 'falls back to current working directory by default' do
58
- expect(provider.root).to eq Pathname.pwd
52
+ expect(provider.config_dir).to eq Pathname.pwd + 'config'
59
53
  end
60
54
  end
61
55
 
@@ -94,7 +88,7 @@ RSpec.describe ComplexConfig::Provider do
94
88
 
95
89
  context 'handling configuration files with []' do
96
90
  before do
97
- provider.root = Pathname.new(__FILE__).dirname.dirname
91
+ provider.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
98
92
  end
99
93
 
100
94
  it 'returns the correct configuration' do
@@ -7,7 +7,7 @@ RSpec.describe 'shortcuts' do
7
7
  end
8
8
 
9
9
  before do
10
- provider.root = Pathname.new(__FILE__).dirname.dirname
10
+ provider.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
11
11
  end
12
12
 
13
13
  it 'returns a proxy object for the shortcuts' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: complex_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -129,6 +129,7 @@ extensions: []
129
129
  extra_rdoc_files:
130
130
  - README.md
131
131
  - lib/complex_config.rb
132
+ - lib/complex_config/config.rb
132
133
  - lib/complex_config/errors.rb
133
134
  - lib/complex_config/plugins.rb
134
135
  - lib/complex_config/plugins/enable.rb
@@ -136,6 +137,7 @@ extra_rdoc_files:
136
137
  - lib/complex_config/plugins/uri.rb
137
138
  - lib/complex_config/provider.rb
138
139
  - lib/complex_config/proxy.rb
140
+ - lib/complex_config/railtie.rb
139
141
  - lib/complex_config/rude.rb
140
142
  - lib/complex_config/settings.rb
141
143
  - lib/complex_config/shortcuts.rb
@@ -154,6 +156,7 @@ files:
154
156
  - complex_config.gemspec
155
157
  - config/products.yml
156
158
  - lib/complex_config.rb
159
+ - lib/complex_config/config.rb
157
160
  - lib/complex_config/errors.rb
158
161
  - lib/complex_config/plugins.rb
159
162
  - lib/complex_config/plugins/enable.rb
@@ -161,10 +164,12 @@ files:
161
164
  - lib/complex_config/plugins/uri.rb
162
165
  - lib/complex_config/provider.rb
163
166
  - lib/complex_config/proxy.rb
167
+ - lib/complex_config/railtie.rb
164
168
  - lib/complex_config/rude.rb
165
169
  - lib/complex_config/settings.rb
166
170
  - lib/complex_config/shortcuts.rb
167
171
  - lib/complex_config/version.rb
172
+ - spec/complex_config/config_spec.rb
168
173
  - spec/complex_config/plugins_spec.rb
169
174
  - spec/complex_config/provider_spec.rb
170
175
  - spec/complex_config/settings_spec.rb
@@ -201,6 +206,7 @@ signing_key:
201
206
  specification_version: 4
202
207
  summary: configuration library
203
208
  test_files:
209
+ - spec/complex_config/config_spec.rb
204
210
  - spec/complex_config/plugins_spec.rb
205
211
  - spec/complex_config/provider_spec.rb
206
212
  - spec/complex_config/settings_spec.rb