smart_env 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/smart_env/version.rb +1 -1
- data/lib/smart_env.rb +21 -34
- data/spec/load_unload_spec.rb +0 -7
- metadata +7 -9
- data/spec/memoize_spec.rb +0 -14
data/lib/smart_env/version.rb
CHANGED
data/lib/smart_env.rb
CHANGED
@@ -4,29 +4,12 @@ require "smart_env/uri_proxy"
|
|
4
4
|
module SmartEnv
|
5
5
|
attr_accessor :registry
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class << base
|
12
|
-
alias_method :__get, :[]
|
13
|
-
alias_method :__set, :[]=
|
14
|
-
|
15
|
-
def []=(key, value)
|
16
|
-
memoized[key] = nil
|
17
|
-
__set(key, value)
|
18
|
-
end
|
7
|
+
def clear_registry
|
8
|
+
@registry = empty_registry
|
9
|
+
end
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
value = __get(key)
|
23
|
-
registry.each do |klass, condition|
|
24
|
-
result = condition.call(key, value) rescue false
|
25
|
-
value = klass.new(key, value) if value && result
|
26
|
-
end
|
27
|
-
memoized[key] = value
|
28
|
-
end
|
29
|
-
end
|
11
|
+
def empty_registry
|
12
|
+
[]
|
30
13
|
end
|
31
14
|
|
32
15
|
def use(klass)
|
@@ -43,22 +26,26 @@ module SmartEnv
|
|
43
26
|
self
|
44
27
|
end
|
45
28
|
|
46
|
-
def clear_registry
|
47
|
-
@registry = empty_registry
|
48
|
-
@memoized = {}
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
def empty_registry
|
53
|
-
[]
|
54
|
-
end
|
55
|
-
|
56
29
|
def registry
|
57
30
|
@registry ||= empty_registry
|
58
31
|
end
|
59
32
|
|
60
|
-
def
|
61
|
-
|
33
|
+
def self.extended(base)
|
34
|
+
raise RuntimeError.new("#{base.inspect} doesn't respond to #[]") \
|
35
|
+
unless base.respond_to? :[]
|
36
|
+
|
37
|
+
class << base
|
38
|
+
alias_method :__get, :[]
|
39
|
+
|
40
|
+
def [](key)
|
41
|
+
value = __get(key)
|
42
|
+
registry.each do |klass, condition|
|
43
|
+
result = condition.call(key, value) rescue false
|
44
|
+
value = klass.new(key, value) if value && result
|
45
|
+
end
|
46
|
+
value
|
47
|
+
end
|
48
|
+
end
|
62
49
|
end
|
63
50
|
end
|
64
51
|
|
data/spec/load_unload_spec.rb
CHANGED
@@ -42,12 +42,5 @@ describe SmartEnv, 'load/unload' do
|
|
42
42
|
@env.clear_registry
|
43
43
|
@env['FOO'].should_not respond_to :one
|
44
44
|
end
|
45
|
-
|
46
|
-
it "should clear memoized values" do
|
47
|
-
@env['FOO'] = 'test'
|
48
|
-
memoized = @env['FOO']
|
49
|
-
@env.clear_registry
|
50
|
-
@env['FOO'].object_id.should_not == memoized.object_id
|
51
|
-
end
|
52
45
|
end
|
53
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &2168469180 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '2.0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2168469180
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rcov
|
28
|
-
requirement: &
|
28
|
+
requirement: &2168468540 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2168468540
|
37
37
|
description: Allows you to register Proxy classes for ENV vars by using blocks to
|
38
38
|
match keys and values
|
39
39
|
email:
|
@@ -53,7 +53,6 @@ files:
|
|
53
53
|
- smart_env.gemspec
|
54
54
|
- spec/decoration_spec.rb
|
55
55
|
- spec/load_unload_spec.rb
|
56
|
-
- spec/memoize_spec.rb
|
57
56
|
- spec/registry_spec.rb
|
58
57
|
- spec/spec_helper.rb
|
59
58
|
- spec/uri_spec.rb
|
@@ -72,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
71
|
version: '0'
|
73
72
|
segments:
|
74
73
|
- 0
|
75
|
-
hash: -
|
74
|
+
hash: -2010000766017814403
|
76
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
76
|
none: false
|
78
77
|
requirements:
|
@@ -81,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
80
|
version: '0'
|
82
81
|
segments:
|
83
82
|
- 0
|
84
|
-
hash: -
|
83
|
+
hash: -2010000766017814403
|
85
84
|
requirements: []
|
86
85
|
rubyforge_project: smart_env
|
87
86
|
rubygems_version: 1.6.2
|
@@ -91,7 +90,6 @@ summary: Lazily proxy ENV values
|
|
91
90
|
test_files:
|
92
91
|
- spec/decoration_spec.rb
|
93
92
|
- spec/load_unload_spec.rb
|
94
|
-
- spec/memoize_spec.rb
|
95
93
|
- spec/registry_spec.rb
|
96
94
|
- spec/spec_helper.rb
|
97
95
|
- spec/uri_spec.rb
|
data/spec/memoize_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SmartEnv, 'memoizing values' do
|
4
|
-
before do
|
5
|
-
@env = {}
|
6
|
-
@env.extend SmartEnv
|
7
|
-
@env.use(SmartEnv::UriProxy)
|
8
|
-
@env['TEST'] = 'http://service.com'
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return the same object after calling" do
|
12
|
-
ENV['TEST'].object_id.should == ENV['TEST'].object_id
|
13
|
-
end
|
14
|
-
end
|