configatron 3.0.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f474cf450b19844154759cec03c3423912555cb8
4
- data.tar.gz: 038d893595745eaf98f6d0b31daf04c795a83bdf
3
+ metadata.gz: 84ff6f84518b18e89af32df3249a42d4adde63c6
4
+ data.tar.gz: ed208d199f8334bda0b371098eeaf9f035f390a1
5
5
  SHA512:
6
- metadata.gz: 3d40cf23c2fa1fe15c29311d08d6a92d2afaba80a84e7b09010b7326147bc28221b66ef1bf037e562be42b1bca03a5b21b7aec9d7e094bac2e6c45da4ac3723e
7
- data.tar.gz: bb9ec9e8ebb599af692f84e24e89bac8505709bcc52f52b46ccc644c113630c5c1dde64223df3561417debb2133748e07688c83813acae78f0087910fd490b03
6
+ metadata.gz: 68368a752c61057a128b2a84f610e1d384a2ac198ab104689ec7129fb1723a4183dc864550914a08394fee2bf0301b2a3a33c3cd18ba11cc0ae30fd9ff95df5e
7
+ data.tar.gz: 178b8532496c4c85ef94a478073283d333ca37be95ecaa9c811bd996c54a9e0181a0cdbb73cd6970e3d4d6b9500d35f2bcdd4529fc46b82b78da45e9bc6fe9d5
data/.travis.yml CHANGED
@@ -3,5 +3,6 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
+ - 2.1.1
6
7
  install: bundle install
7
8
  script: bundle exec rake
data/Gemfile CHANGED
@@ -7,3 +7,4 @@ gemspec
7
7
  # gem 'rb-fsevent'
8
8
  # gem "guard"
9
9
  # gem 'guard-minitest'
10
+ gem 'm', github: "unmanbearpig/m"
data/README.md CHANGED
@@ -49,7 +49,7 @@ configatron.database.url # => "postgres://localhost/foo"
49
49
 
50
50
  Voila! Simple as can be.
51
51
 
52
- Now you're saying, what if I want to have a 'default' set of options, but then override them later, based on other information? Simple again. Let's use our above example. We've configured our `database.url` option to be @postgres://localhost/foo@. The problem with that is that is our production database url, not our development url. Fair enough, all you have to do is redeclare it:
52
+ Now you're saying, what if I want to have a 'default' set of options, but then override them later, based on other information? Simple again. Let's use our above example. We've configured our `database.url` option to be `postgres://localhost/foo`. The problem with that is that is our production database url, not our development url. Fair enough, all you have to do is redeclare it:
53
53
 
54
54
  ```ruby
55
55
  configatron.database.url = "postgres://localhost/foo_development"
data/configatron.gemspec CHANGED
@@ -19,4 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "mocha"
23
+ gem.add_development_dependency "minitest", '>=5.2.3'
22
24
  end
@@ -1,3 +1,6 @@
1
1
  require_relative "deep_clone"
2
2
  require_relative "store"
3
- require_relative "errors"
3
+ require_relative "errors"
4
+ require_relative "proc"
5
+ require_relative "dynamic"
6
+ require_relative "delayed"
@@ -0,0 +1,2 @@
1
+ class Configatron::Delayed < Configatron::Proc
2
+ end
@@ -0,0 +1,7 @@
1
+ class Configatron::Dynamic < Configatron::Proc
2
+
3
+ def finalize?
4
+ false
5
+ end
6
+
7
+ end
@@ -0,0 +1,30 @@
1
+ class Configatron
2
+
3
+ class Proc
4
+
5
+ attr_accessor :execution_count
6
+ attr_accessor :block
7
+
8
+ def initialize(&block)
9
+ self.execution_count = 0
10
+ self.block = block
11
+ end
12
+
13
+ def call
14
+ unless @val
15
+ val = self.block.call
16
+ self.execution_count += 1
17
+ if finalize?
18
+ @val = val
19
+ end
20
+ end
21
+ return val || @val
22
+ end
23
+
24
+ def finalize?
25
+ true
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -15,12 +15,13 @@ class Configatron
15
15
  end
16
16
 
17
17
  def [](key)
18
- fetch(key.to_sym) do
18
+ val = fetch(key.to_sym) do
19
19
  if @__locked
20
20
  raise Configatron::UndefinedKeyError.new("Key Not Found: #{key}")
21
21
  end
22
22
  ::Configatron::Store.new
23
23
  end
24
+ return val
24
25
  end
25
26
 
26
27
  def store(key, value)
@@ -40,6 +41,9 @@ class Configatron
40
41
  end
41
42
  store(key, val)
42
43
  end
44
+ if val.is_a?(Configatron::Proc)
45
+ val = val.call
46
+ end
43
47
  return val
44
48
  end
45
49
 
@@ -1,3 +1,3 @@
1
1
  class Configatron
2
- VERSION = "3.0.2"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ describe Configatron::Proc do
4
+
5
+ let(:store) { Configatron::Store.new }
6
+ let(:proc) { Configatron::Proc.new {rand} }
7
+
8
+ describe '#call' do
9
+
10
+ it 'executes the block and returns the results' do
11
+ stubs(:rand).returns(4)
12
+ proc.call.must_equal 4
13
+ end
14
+
15
+ it 'caches the result if finalize? return true' do
16
+ proc.stubs(:finalize?).returns(true)
17
+ proc.call.must_equal proc.call
18
+ end
19
+
20
+ it 'does not cache the result if finalize? returns false' do
21
+ proc.stubs(:finalize?).returns(false)
22
+ proc.call.wont_equal proc.call
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -18,6 +18,16 @@ describe Configatron::Store do
18
18
  store["unknown"].must_be_kind_of Configatron::Store
19
19
  end
20
20
 
21
+ context 'Configatron::Proc' do
22
+
23
+ it 'executes the proc' do
24
+ store.a = Configatron::Proc.new {1+1}
25
+ store.a.must_equal 2
26
+ end
27
+
28
+ end
29
+
30
+
21
31
  end
22
32
 
23
33
  context "[]=" do
data/test/test_helper.rb CHANGED
@@ -3,6 +3,8 @@ require 'bundler/setup'
3
3
  require 'configatron' # and any other gems you need
4
4
 
5
5
  require 'minitest/autorun'
6
+ require "mocha/setup"
7
+ require 'mocha/mini_test'
6
8
 
7
9
  class MiniTest::Spec
8
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Bates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 5.2.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 5.2.3
27
55
  description: A powerful Ruby configuration system.
28
56
  email:
29
57
  - mark@markbates.com
@@ -45,8 +73,11 @@ files:
45
73
  - lib/configatron.rb
46
74
  - lib/configatron/core.rb
47
75
  - lib/configatron/deep_clone.rb
76
+ - lib/configatron/delayed.rb
77
+ - lib/configatron/dynamic.rb
48
78
  - lib/configatron/errors.rb
49
79
  - lib/configatron/kernel.rb
80
+ - lib/configatron/proc.rb
50
81
  - lib/configatron/rails.rb
51
82
  - lib/configatron/store.rb
52
83
  - lib/configatron/version.rb
@@ -57,6 +88,7 @@ files:
57
88
  - lib/generators/configatron/install/templates/configatron/test.rb
58
89
  - lib/generators/configatron/install/templates/initializers/configatron.rb
59
90
  - test/configatron/kernel_test.rb
91
+ - test/configatron/proc_test.rb
60
92
  - test/configatron/store_test.rb
61
93
  - test/configatron_test.rb
62
94
  - test/test_helper.rb
@@ -86,6 +118,7 @@ specification_version: 4
86
118
  summary: A powerful Ruby configuration system.
87
119
  test_files:
88
120
  - test/configatron/kernel_test.rb
121
+ - test/configatron/proc_test.rb
89
122
  - test/configatron/store_test.rb
90
123
  - test/configatron_test.rb
91
124
  - test/test_helper.rb