cupcakinator 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +6 -3
- data/Guardfile +1 -0
- data/lib/cupcakinator.rb +1 -0
- data/lib/cupcakinator/base.rb +18 -1
- data/lib/cupcakinator/version.rb +1 -1
- data/spec/cupcakinator/base_spec.rb +13 -0
- data/spec/el_config.yml +4 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef9ce571b53c125b293184143541e24ec299eadd
|
4
|
+
data.tar.gz: 6d108263870627cbdd02e5ae943112a907cf3997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baf0a1919f69fb660b916cc70f719129f2131cb86bb249404fb51082c7110e7d1b49dd4ab190eb20d5d439f8bce3ba8684cdf7faee5a72dad462caf9c7bf2e54
|
7
|
+
data.tar.gz: 916184623bb21a1186488ee94408fe18ae53643e1d5dc545b63908d99cc319957168070656f17c1ff9718c8c6931a6eb1701f6cccf8c1dcd6833d42bd0a659cd
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
data/Gemfile
CHANGED
@@ -10,12 +10,15 @@ gem 'json', '~> 1.8'
|
|
10
10
|
group :development, :test do
|
11
11
|
gem 'debugger'
|
12
12
|
gem 'guard'
|
13
|
+
gem 'guard-bundler'
|
13
14
|
gem 'guard-rspec'
|
14
15
|
gem 'guard-spork'
|
15
|
-
gem 'rake'
|
16
|
-
gem 'rb-readline'
|
17
16
|
gem 'redcarpet'
|
17
|
+
gem 'yard'
|
18
|
+
end
|
19
|
+
|
20
|
+
group :development, :test, :ci do
|
21
|
+
gem 'rake'
|
18
22
|
gem 'rspec'
|
19
23
|
gem 'simplecov', require: false
|
20
|
-
gem 'yard'
|
21
24
|
end
|
data/Guardfile
CHANGED
data/lib/cupcakinator.rb
CHANGED
@@ -24,6 +24,7 @@ module Cupcakinator
|
|
24
24
|
|
25
25
|
unless @_i18n_initialized_for_cupcakinator
|
26
26
|
locale_file = File.expand_path(File.join(File.dirname(__FILE__), '../config/locales.yml'))
|
27
|
+
I18n.enforce_available_locales = false
|
27
28
|
I18n.load_path << locale_file
|
28
29
|
@_i18n_initialized_for_cupcakinator = true
|
29
30
|
end
|
data/lib/cupcakinator/base.rb
CHANGED
@@ -27,6 +27,7 @@ module Cupcakinator
|
|
27
27
|
# @option options.last [Hash] :dir The directory where the file can be found
|
28
28
|
# @option options.last [Hash] :file The configuration filename
|
29
29
|
# @option options.last [Hash] :method The method used to access the configuration options
|
30
|
+
# @option options.last [Hash] :root_key A key in the top level of the config file that will become the base
|
30
31
|
# @example Default usage - Foo will load ./config/config.yml into a method named 'config'
|
31
32
|
# class Foo
|
32
33
|
# include cupcakinator
|
@@ -55,6 +56,17 @@ module Cupcakinator
|
|
55
56
|
# >> puts Foo.new.config
|
56
57
|
# { :foo => 'bar' }
|
57
58
|
#
|
59
|
+
# @example with Rails - Foo will load config/foo_config.yml relative to Rails root into a method named 'config'
|
60
|
+
# beginning at the root_key based on the Rails.env
|
61
|
+
# class Foo
|
62
|
+
# include cupcakinator
|
63
|
+
# cupcakinate dir: Rails.root.join('config'), file: 'foo_config.yml', root_key: Rails.env
|
64
|
+
# end
|
65
|
+
# >> puts Foo.config
|
66
|
+
# { :foo => 'bar' }
|
67
|
+
# >> puts Foo.new.config
|
68
|
+
# { :foo => 'bar' }
|
69
|
+
#
|
58
70
|
def cupcakinate(*options)
|
59
71
|
if !options.empty?
|
60
72
|
default_options = _cupcakinator_options
|
@@ -82,7 +94,12 @@ module Cupcakinator
|
|
82
94
|
def load_cupcakinator_config
|
83
95
|
filename = File.join(_cupcakinator_options[:dir], _cupcakinator_options[:file])
|
84
96
|
yaml_config = YAML.load_file(filename)
|
85
|
-
|
97
|
+
if _cupcakinator_options.has_key?(:root_key)
|
98
|
+
rk = _cupcakinator_options[:root_key]
|
99
|
+
@cupcakinator_config = Cupcakinator::Config.new(yaml_config[rk])
|
100
|
+
else
|
101
|
+
@cupcakinator_config = Cupcakinator::Config.new(yaml_config)
|
102
|
+
end
|
86
103
|
rescue Errno::ENOENT
|
87
104
|
raise Cupcakinator::ConfigFileNotFoundError.new(filename, _cupcakinator_options)
|
88
105
|
rescue Psych::SyntaxError => e
|
data/lib/cupcakinator/version.rb
CHANGED
@@ -97,6 +97,19 @@ describe Cupcakinator::Base do
|
|
97
97
|
expect{ CupcakinatorBaseSpecBadFile.load_cupcakinator_config }.to raise_error(Cupcakinator::ConfigFileInvalidError)
|
98
98
|
end
|
99
99
|
|
100
|
+
it 'should load the YAML anchored at root_key' do
|
101
|
+
class CupcakinatorBaseSpecRootKey
|
102
|
+
include Cupcakinator
|
103
|
+
|
104
|
+
cupcakinate dir: File.expand_path(File.join(File.dirname(__FILE__), '..')), file: 'el_config.yml', root_key: 'special'
|
105
|
+
end
|
106
|
+
|
107
|
+
subject = CupcakinatorBaseSpecRootKey.new
|
108
|
+
subject.config.has_key?(:special).should be_false
|
109
|
+
subject.config.bacon.chunky.should be_false
|
110
|
+
end
|
111
|
+
|
112
|
+
|
100
113
|
end
|
101
114
|
|
102
115
|
|
data/spec/el_config.yml
CHANGED
metadata
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cupcakinator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.0.0
|
27
|
-
description:
|
27
|
+
description: " Add config from YAML to any class "
|
28
28
|
email:
|
29
29
|
- bcptaylor@gmail.com
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- .gitignore
|
35
|
-
- .rspec
|
36
|
-
- .ruby-version
|
37
|
-
- .travis.yml
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".ruby-version"
|
37
|
+
- ".travis.yml"
|
38
38
|
- Gemfile
|
39
39
|
- Guardfile
|
40
40
|
- LICENSE
|
@@ -63,17 +63,17 @@ require_paths:
|
|
63
63
|
- lib
|
64
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.0
|
76
|
+
rubygems_version: 2.2.0
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Easy to add config from YAML to any class
|