configatron 2.13.0 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -0
- data/.rvmrc +0 -1
- data/.travis.yml +5 -2
- data/Gemfile +5 -1
- data/Gemfile.lock +30 -13
- data/Guardfile +24 -0
- data/LICENSE.txt +22 -0
- data/README.md +122 -112
- data/Rakefile +6 -4
- data/V2-README.md +243 -0
- data/configatron.gemspec +4 -31
- data/lib/configatron/core.rb +3 -94
- data/lib/configatron/deep_clone.rb +69 -0
- data/lib/configatron/errors.rb +5 -9
- data/lib/configatron/rails.rb +8 -8
- data/lib/configatron/store.rb +66 -339
- data/lib/configatron/version.rb +1 -1
- data/lib/configatron.rb +8 -16
- data/lib/generators/configatron/install/install_generator.rb +0 -0
- data/lib/generators/configatron/install/templates/configatron/defaults.rb +0 -0
- data/lib/generators/configatron/install/templates/configatron/development.rb +0 -0
- data/lib/generators/configatron/install/templates/configatron/production.rb +0 -0
- data/lib/generators/configatron/install/templates/configatron/test.rb +0 -0
- data/lib/generators/configatron/install/templates/initializers/configatron.rb +0 -0
- data/test/configatron/store_test.rb +191 -0
- data/test/configatron_test.rb +5 -0
- data/test/test_helper.rb +14 -0
- metadata +27 -54
- data/LICENSE +0 -21
- data/lib/configatron/core_ext/class.rb +0 -25
- data/lib/configatron/core_ext/kernel.rb +0 -8
- data/lib/configatron/core_ext/object.rb +0 -13
- data/lib/configatron/core_ext/string.rb +0 -90
- data/lib/configatron/proc.rb +0 -104
- data/spec/configatron/proc_spec.rb +0 -67
- data/spec/configatron/rails_spec.rb +0 -66
- data/spec/lib/class_spec.rb +0 -46
- data/spec/lib/complex.yml +0 -13
- data/spec/lib/configatron_spec.rb +0 -630
- data/spec/lib/futurama.yml +0 -6
- data/spec/lib/lost.yml +0 -14
- data/spec/lib/math.yml +0 -2
- data/spec/lib/merge.yml +0 -14
- data/spec/spec_helper.rb +0 -4
- data/spec/support/rails.rb +0 -7
metadata
CHANGED
@@ -1,32 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configatron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0.rc1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mark Bates
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0
|
22
|
-
type: :
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0
|
26
|
+
version: '0'
|
30
27
|
description: A powerful Ruby configuration system.
|
31
28
|
email:
|
32
29
|
- mark@markbates.com
|
@@ -39,18 +36,16 @@ files:
|
|
39
36
|
- .travis.yml
|
40
37
|
- Gemfile
|
41
38
|
- Gemfile.lock
|
42
|
-
-
|
39
|
+
- Guardfile
|
40
|
+
- LICENSE.txt
|
43
41
|
- README.md
|
44
42
|
- Rakefile
|
43
|
+
- V2-README.md
|
45
44
|
- configatron.gemspec
|
46
45
|
- lib/configatron.rb
|
47
46
|
- lib/configatron/core.rb
|
48
|
-
- lib/configatron/
|
49
|
-
- lib/configatron/core_ext/kernel.rb
|
50
|
-
- lib/configatron/core_ext/object.rb
|
51
|
-
- lib/configatron/core_ext/string.rb
|
47
|
+
- lib/configatron/deep_clone.rb
|
52
48
|
- lib/configatron/errors.rb
|
53
|
-
- lib/configatron/proc.rb
|
54
49
|
- lib/configatron/rails.rb
|
55
50
|
- lib/configatron/store.rb
|
56
51
|
- lib/configatron/version.rb
|
@@ -60,56 +55,34 @@ files:
|
|
60
55
|
- lib/generators/configatron/install/templates/configatron/production.rb
|
61
56
|
- lib/generators/configatron/install/templates/configatron/test.rb
|
62
57
|
- lib/generators/configatron/install/templates/initializers/configatron.rb
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
|
67
|
-
|
68
|
-
-
|
69
|
-
|
70
|
-
- spec/lib/math.yml
|
71
|
-
- spec/lib/merge.yml
|
72
|
-
- spec/spec_helper.rb
|
73
|
-
- spec/support/rails.rb
|
74
|
-
homepage: http://www.metabates.com
|
75
|
-
licenses: []
|
58
|
+
- test/configatron/store_test.rb
|
59
|
+
- test/configatron_test.rb
|
60
|
+
- test/test_helper.rb
|
61
|
+
homepage: https://github.com/markbates/configatron
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
76
65
|
post_install_message:
|
77
66
|
rdoc_options: []
|
78
67
|
require_paths:
|
79
68
|
- lib
|
80
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
70
|
requirements:
|
83
|
-
- -
|
71
|
+
- - '>='
|
84
72
|
- !ruby/object:Gem::Version
|
85
73
|
version: '0'
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
hash: -1505577042870860442
|
89
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
75
|
requirements:
|
92
|
-
- -
|
76
|
+
- - '>'
|
93
77
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
hash: -1505577042870860442
|
78
|
+
version: 1.3.1
|
98
79
|
requirements: []
|
99
80
|
rubyforge_project:
|
100
|
-
rubygems_version:
|
81
|
+
rubygems_version: 2.0.3
|
101
82
|
signing_key:
|
102
|
-
specification_version:
|
83
|
+
specification_version: 4
|
103
84
|
summary: A powerful Ruby configuration system.
|
104
85
|
test_files:
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
108
|
-
- spec/lib/complex.yml
|
109
|
-
- spec/lib/configatron_spec.rb
|
110
|
-
- spec/lib/futurama.yml
|
111
|
-
- spec/lib/lost.yml
|
112
|
-
- spec/lib/math.yml
|
113
|
-
- spec/lib/merge.yml
|
114
|
-
- spec/spec_helper.rb
|
115
|
-
- spec/support/rails.rb
|
86
|
+
- test/configatron/store_test.rb
|
87
|
+
- test/configatron_test.rb
|
88
|
+
- test/test_helper.rb
|
data/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2009 Mark Bates
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class Class
|
2
|
-
|
3
|
-
# Returns access to configuration parameters named after the class.
|
4
|
-
#
|
5
|
-
# Examples:
|
6
|
-
# configatron.foo.bar = :bar
|
7
|
-
# configatron.a.b.c.d = 'D'
|
8
|
-
#
|
9
|
-
# class Foo
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# module A
|
13
|
-
# module B
|
14
|
-
# class C
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# Foo.to_configatron.bar # => :bar
|
20
|
-
# A::B::C.to_configatron.d # => 'D'
|
21
|
-
def to_configatron(*args)
|
22
|
-
self.name.to_configatron(*args)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class Object # :nodoc:
|
2
|
-
|
3
|
-
def send_with_chain(methods, *args) # :nodoc:
|
4
|
-
obj = self
|
5
|
-
[methods].flatten.each {|m| obj = obj.send(m, *args)}
|
6
|
-
obj
|
7
|
-
end
|
8
|
-
|
9
|
-
def blank? # ported ActiveSupport method
|
10
|
-
respond_to?(:empty?) ? empty? : !self
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
class String # :nodoc:
|
2
|
-
|
3
|
-
def to_configatron(*args)
|
4
|
-
name_spaces = (args + self.split("::")).flatten
|
5
|
-
name_spaces.collect!{|s| s.to_s.methodize}
|
6
|
-
configatron.send_with_chain(name_spaces)
|
7
|
-
end
|
8
|
-
|
9
|
-
def underscore # :nodoc:
|
10
|
-
self.to_s.gsub(/::/, '/').
|
11
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
12
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
13
|
-
tr("-", "_").
|
14
|
-
downcase
|
15
|
-
end
|
16
|
-
|
17
|
-
def methodize # :nodoc:
|
18
|
-
x = self
|
19
|
-
|
20
|
-
# if we get down to a nil or an empty string raise an exception!
|
21
|
-
raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
|
22
|
-
|
23
|
-
# get rid of the big stuff in the front/back
|
24
|
-
x.strip!
|
25
|
-
|
26
|
-
# if we get down to a nil or an empty string raise an exception!
|
27
|
-
raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
|
28
|
-
|
29
|
-
x = x.underscore
|
30
|
-
|
31
|
-
# get rid of spaces and make the _
|
32
|
-
x.gsub!(' ', '_')
|
33
|
-
# get rid of everything that isn't 'safe' a-z, 0-9, ?, !, =, _
|
34
|
-
x.gsub!(/([^ a-zA-Z0-9\_\?\!\=]+)/n, '_')
|
35
|
-
|
36
|
-
# if we get down to a nil or an empty string raise an exception!
|
37
|
-
raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
|
38
|
-
|
39
|
-
# condense multiple 'safe' non a-z chars to just one.
|
40
|
-
# ie. ___ becomes _ !!!! becomes ! etc...
|
41
|
-
[' ', '_', '?', '!', "="].each do |c|
|
42
|
-
x.squeeze!(c)
|
43
|
-
end
|
44
|
-
|
45
|
-
# if we get down to a nil or an empty string raise an exception!
|
46
|
-
raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
|
47
|
-
|
48
|
-
#down case the whole thing
|
49
|
-
x.downcase!
|
50
|
-
|
51
|
-
# get rid of any characters at the beginning that aren't a-z
|
52
|
-
while !x.match(/^[a-z]/)
|
53
|
-
x.slice!(0)
|
54
|
-
|
55
|
-
# if we get down to a nil or an empty string raise an exception!
|
56
|
-
raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
|
57
|
-
end
|
58
|
-
|
59
|
-
# let's trim this bad boy down a bit now that we've cleaned it up, somewhat.
|
60
|
-
# we should do this before cleaning up the end character, because it's possible to end up with a
|
61
|
-
# bad char at the end if you trim too late.
|
62
|
-
x = x[0..100] if x.length > 100
|
63
|
-
|
64
|
-
# get rid of any characters at the end that aren't safe
|
65
|
-
while !x.match(/[a-z0-9\?\!\=]$/)
|
66
|
-
x.slice!(x.length - 1)
|
67
|
-
# if we get down to a nil or an empty string raise an exception!
|
68
|
-
raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
|
69
|
-
end
|
70
|
-
|
71
|
-
# if we get down to a nil or an empty string raise an exception!
|
72
|
-
raise NameError.new("#{self} cannot be converted to a valid method name!") if x.nil? || x == ''
|
73
|
-
|
74
|
-
# let's get rid of characters that don't belong in the 'middle' of the method.
|
75
|
-
orig_middle = x[1..(x.length - 2)]
|
76
|
-
n_middle = orig_middle.dup
|
77
|
-
|
78
|
-
['?', '!', "="].each do |c|
|
79
|
-
n_middle.gsub!(c, "_")
|
80
|
-
end
|
81
|
-
|
82
|
-
# the previous gsub can leave us with multiple underscores that need cleaning up.
|
83
|
-
n_middle.squeeze!("_")
|
84
|
-
|
85
|
-
x.gsub!(orig_middle, n_middle)
|
86
|
-
x.gsub!("_=", "=")
|
87
|
-
x
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
data/lib/configatron/proc.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
class Configatron
|
2
|
-
# This class can be used to give special powers to a Configatron setting.
|
3
|
-
# See Configatron::Delayed and Configatron::Dynamic as examples of how this
|
4
|
-
# works.
|
5
|
-
#
|
6
|
-
# This class can be subclassed easily. The key is to override the <tt>finalize?</tt>
|
7
|
-
# method.
|
8
|
-
#
|
9
|
-
# Example:
|
10
|
-
# class RunThreeTimes < Configatron::Proc
|
11
|
-
# def finalize?
|
12
|
-
# self.execution_count == 3
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# configatron.some.rand.generator = RunThreeTimes.new do
|
17
|
-
# rand
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# configatron.some.rand.generator # => 0.169280668547299
|
21
|
-
# configatron.some.rand.generator # => 0.298880544243205
|
22
|
-
# configatron.some.rand.generator # => 0.421091617110779
|
23
|
-
# configatron.some.rand.generator # => 0.421091617110779
|
24
|
-
# configatron.some.rand.generator # => 0.421091617110779
|
25
|
-
class Proc
|
26
|
-
|
27
|
-
# The number of times this Proc has been executed
|
28
|
-
attr_accessor :execution_count
|
29
|
-
# The block that you want executed when you call the <tt>execute</tt> method.
|
30
|
-
attr_accessor :block
|
31
|
-
|
32
|
-
# Requires a block to be passed into it.
|
33
|
-
def initialize(&block)
|
34
|
-
self.execution_count = 0
|
35
|
-
self.block = block
|
36
|
-
end
|
37
|
-
|
38
|
-
# Executes the <tt>block</tt> attribute, ticks up the
|
39
|
-
# <tt>execution_count</tt> attribute by one and then
|
40
|
-
# returns the value of the executed <tt>block</tt>
|
41
|
-
def execute
|
42
|
-
val = self.block.call
|
43
|
-
self.execution_count += 1
|
44
|
-
return val
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns <tt>true</tt> if Configatron should cache the
|
48
|
-
# results of the <tt>execute</tt> method, thereby never calling
|
49
|
-
# it again.
|
50
|
-
def finalize?
|
51
|
-
self.execution_count == 1
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
# Tells Configatron to always execute the block at runtime.
|
57
|
-
# The results will never be cached.
|
58
|
-
#
|
59
|
-
# Example:
|
60
|
-
# configatron.letters = 'a-b-c-d'
|
61
|
-
# configatron.my.letters = Configatron::Delayed.new do
|
62
|
-
# "My letters are: #{configatron.letters}"
|
63
|
-
# end
|
64
|
-
# configatron.my.other.letters = Configatron::Dynamic.new do
|
65
|
-
# "My letters are: #{configatron.a.b.c.d}"
|
66
|
-
# end
|
67
|
-
#
|
68
|
-
# configatron.my.letters # => 'My letters are: a-b-c-d'
|
69
|
-
# configatron.my.other.letters # => 'My letters are: a-b-c-d'
|
70
|
-
#
|
71
|
-
# configatron.letters = 'a-b-c-d-e'
|
72
|
-
#
|
73
|
-
# configatron.my.letters # => 'My letters are: a-b-c-d'
|
74
|
-
# configatron.my.other.letters # => 'My letters are: a-b-c-d-e'
|
75
|
-
class Dynamic < Configatron::Proc
|
76
|
-
def finalize?
|
77
|
-
false
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# Tells Configatron to delay execution of the block until
|
82
|
-
# runtime. Once run the results of the block will be cached,
|
83
|
-
# never to be run again.
|
84
|
-
#
|
85
|
-
# Example:
|
86
|
-
# configatron.letters = 'a-b-c-d'
|
87
|
-
# configatron.my.letters = Configatron::Delayed.new do
|
88
|
-
# "My letters are: #{configatron.letters}"
|
89
|
-
# end
|
90
|
-
# configatron.my.other.letters = Configatron::Dynamic.new do
|
91
|
-
# "My letters are: #{configatron.a.b.c.d}"
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# configatron.my.letters # => 'My letters are: a-b-c-d'
|
95
|
-
# configatron.my.other.letters # => 'My letters are: a-b-c-d'
|
96
|
-
#
|
97
|
-
# configatron.letters = 'a-b-c-d-e'
|
98
|
-
#
|
99
|
-
# configatron.my.letters # => 'My letters are: a-b-c-d'
|
100
|
-
# configatron.my.other.letters # => 'My letters are: a-b-c-d-e'
|
101
|
-
class Delayed < Configatron::Proc
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Configatron::Proc do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
configatron.temp_start
|
7
|
-
end
|
8
|
-
|
9
|
-
after(:each) do
|
10
|
-
configatron.temp_end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Configatron::Dynamic do
|
14
|
-
|
15
|
-
it 'should execute the code at a later date' do
|
16
|
-
configatron.tv.shows = ['seinfeld', 'simpsons']
|
17
|
-
configatron.my.tv.shows = Configatron::Dynamic.new do
|
18
|
-
"My shows are: #{configatron.tv.shows.join(', ')}"
|
19
|
-
end
|
20
|
-
configatron.my.tv.shows.should == 'My shows are: seinfeld, simpsons'
|
21
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage']
|
22
|
-
configatron.my.tv.shows.should == 'My shows are: seinfeld, simpsons, entourage'
|
23
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage', 'office']
|
24
|
-
configatron.my.tv.shows.should == 'My shows are: seinfeld, simpsons, entourage, office'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should work with retrieve' do
|
28
|
-
configatron.tv.shows = ['seinfeld', 'simpsons']
|
29
|
-
configatron.my.tv.shows = Configatron::Dynamic.new do
|
30
|
-
"My shows are: #{configatron.tv.shows.join(', ')}"
|
31
|
-
end
|
32
|
-
configatron.my.tv.retrieve(:shows).should == 'My shows are: seinfeld, simpsons'
|
33
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage']
|
34
|
-
configatron.my.tv.retrieve(:shows).should == 'My shows are: seinfeld, simpsons, entourage'
|
35
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage', 'office']
|
36
|
-
configatron.my.tv.retrieve(:shows).should == 'My shows are: seinfeld, simpsons, entourage, office'
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
describe Configatron::Delayed do
|
42
|
-
|
43
|
-
it 'should execute the code once at a later date' do
|
44
|
-
configatron.tv.shows = ['seinfeld', 'simpsons']
|
45
|
-
configatron.my.tv.shows = Configatron::Delayed.new do
|
46
|
-
"My shows are: #{configatron.tv.shows.join(', ')}"
|
47
|
-
end
|
48
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage']
|
49
|
-
configatron.my.tv.shows.should == 'My shows are: seinfeld, simpsons, entourage'
|
50
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage', 'office']
|
51
|
-
configatron.my.tv.shows.should == 'My shows are: seinfeld, simpsons, entourage'
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should work with retrieve' do
|
55
|
-
configatron.tv.shows = ['seinfeld', 'simpsons']
|
56
|
-
configatron.my.tv.shows = Configatron::Delayed.new do
|
57
|
-
"My shows are: #{configatron.tv.shows.join(', ')}"
|
58
|
-
end
|
59
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage']
|
60
|
-
configatron.my.tv.retrieve(:shows).should == 'My shows are: seinfeld, simpsons, entourage'
|
61
|
-
configatron.tv.shows = ['seinfeld', 'simpsons', 'entourage', 'office']
|
62
|
-
configatron.my.tv.retrieve(:shows).should == 'My shows are: seinfeld, simpsons, entourage'
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Configatron::Rails do
|
4
|
-
|
5
|
-
%w{development test production cucumber}.each do |env|
|
6
|
-
|
7
|
-
describe env do
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
Object.send(:remove_const, 'Rails') rescue nil
|
11
|
-
load File.expand_path(File.join(File.dirname(__FILE__), '..', 'support', 'rails.rb'))
|
12
|
-
::Rails.env = env
|
13
|
-
::Rails.root = File.join(File.dirname(__FILE__), '..', "tmp_rails_root_#{env}")
|
14
|
-
@configatron_path = File.join(Rails.root, 'config', 'configatron')
|
15
|
-
@defaults_file_loc = File.join(@configatron_path, 'defaults.rb')
|
16
|
-
@env_file_loc = File.join(@configatron_path, "#{env}.rb")
|
17
|
-
@env_folder_loc = File.join(@configatron_path, env)
|
18
|
-
@env_bar_loc = File.join(@env_folder_loc, 'bar.rb')
|
19
|
-
@env_foo_loc = File.join(@env_folder_loc, 'foo.rb')
|
20
|
-
|
21
|
-
FileUtils.mkdir_p(@env_folder_loc)
|
22
|
-
|
23
|
-
File.open(@defaults_file_loc, 'w') do |f|
|
24
|
-
f.puts 'configatron.fooa = :foo'
|
25
|
-
f.puts 'configatron.bara = :bar'
|
26
|
-
f.puts 'configatron.env = :default'
|
27
|
-
f.puts 'configatron.something.else = 1'
|
28
|
-
f.puts 'configatron.and.another.thing = 42'
|
29
|
-
end
|
30
|
-
|
31
|
-
File.open(@env_file_loc, 'w') do |f|
|
32
|
-
f.puts "configatron.env = :#{env}"
|
33
|
-
f.puts 'configatron.something.else = 2'
|
34
|
-
end
|
35
|
-
|
36
|
-
File.open(@env_bar_loc, 'w') do |f|
|
37
|
-
f.puts "configatron.bara = 'BAR!!'"
|
38
|
-
f.puts 'configatron.something.else = 3'
|
39
|
-
end
|
40
|
-
|
41
|
-
File.open(@env_foo_loc, 'w') do |f|
|
42
|
-
f.puts "configatron.fooa = :fubar"
|
43
|
-
f.puts 'configatron.something.else = 4'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
after(:each) do
|
48
|
-
FileUtils.rm_rf(::Rails.root)
|
49
|
-
Object.send(:remove_const, 'Rails')
|
50
|
-
# configatron.reset!
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should read the defaults first and then the env file' do
|
54
|
-
Configatron::Rails.init
|
55
|
-
configatron.fooa.should == :fubar
|
56
|
-
configatron.bara.should == 'BAR!!'
|
57
|
-
configatron.env.should == env.to_sym
|
58
|
-
configatron.something.else.should == 4
|
59
|
-
configatron.and.another.thing.should == 42
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
data/spec/lib/class_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
-
|
3
|
-
configatron.foo.bar = :bar
|
4
|
-
configatron.a.b.c.d = 'D'
|
5
|
-
|
6
|
-
configatron.cachetastic.foo.bar = 'cachetastic-fubar'
|
7
|
-
configatron.l.m.n.o.p = 'P'
|
8
|
-
|
9
|
-
class Foo
|
10
|
-
end
|
11
|
-
|
12
|
-
module A
|
13
|
-
module B
|
14
|
-
class C
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module N
|
20
|
-
class O
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe Class do
|
25
|
-
|
26
|
-
if Class.respond_to?(:to_configatron)
|
27
|
-
describe 'to_configatron' do
|
28
|
-
|
29
|
-
it 'should return a Configatron::Store object based on the name of the class' do
|
30
|
-
Foo.to_configatron.should be_kind_of(Configatron::Store)
|
31
|
-
Foo.to_configatron.bar.should == :bar
|
32
|
-
A::B::C.to_configatron.d.should == 'D'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should take an array to prepend to the object' do
|
36
|
-
Foo.to_configatron(:cachetastic).bar.should == 'cachetastic-fubar'
|
37
|
-
N::O.to_configatron(:l, 'm').p.should == 'P'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should convert a string to a Store object' do
|
41
|
-
'A::B::C'.to_configatron.d.should == configatron.a.b.c.d
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/spec/lib/complex.yml
DELETED