smart_env 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -5
- data/README.md +1 -1
- data/Rakefile +20 -0
- data/lib/smart_env/uri_proxy.rb +4 -0
- data/lib/smart_env/version.rb +1 -1
- data/lib/smart_env.rb +9 -17
- data/smart_env.gemspec +2 -0
- data/spec/load_unload_spec.rb +27 -8
- data/spec/spec_helper.rb +3 -3
- metadata +32 -6
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1 +1,21 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require
|
1
3
|
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
desc 'Default: run specs.'
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
desc "Run specs"
|
11
|
+
RSpec::Core::RakeTask.new do |t|
|
12
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
13
|
+
# Put spec opts in a file named .rspec in root
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Generate code coverage"
|
17
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
18
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
19
|
+
t.rcov = true
|
20
|
+
t.rcov_opts = ['--exclude', 'spec']
|
21
|
+
end
|
data/lib/smart_env/uri_proxy.rb
CHANGED
@@ -2,6 +2,10 @@ require 'uri'
|
|
2
2
|
require 'cgi'
|
3
3
|
require 'forwardable'
|
4
4
|
|
5
|
+
class BasicObject
|
6
|
+
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval/ }
|
7
|
+
end unless defined?(BasicObject)
|
8
|
+
|
5
9
|
module SmartEnv
|
6
10
|
class UriProxy < BasicObject
|
7
11
|
attr_reader :params
|
data/lib/smart_env/version.rb
CHANGED
data/lib/smart_env.rb
CHANGED
@@ -5,14 +5,10 @@ module SmartEnv
|
|
5
5
|
attr_accessor :registry
|
6
6
|
|
7
7
|
def clear_registry
|
8
|
-
@registry =
|
8
|
+
@registry = empty_registry
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
@registry = default
|
13
|
-
end
|
14
|
-
|
15
|
-
def default
|
11
|
+
def empty_registry
|
16
12
|
[]
|
17
13
|
end
|
18
14
|
|
@@ -25,28 +21,24 @@ module SmartEnv
|
|
25
21
|
end
|
26
22
|
|
27
23
|
def when(&block)
|
28
|
-
raise "Block must take 0 or 2 arguments: key and value" unless (block.arity
|
24
|
+
raise "Block must take 0 or 2 arguments: key and value" unless (block.arity < 1 || block.arity == 2)
|
29
25
|
registry << [@class, block]
|
30
26
|
self
|
31
27
|
end
|
32
28
|
|
33
29
|
def registry
|
34
|
-
@registry ||=
|
35
|
-
end
|
36
|
-
|
37
|
-
def unload!
|
38
|
-
class << self
|
39
|
-
alias_method :[], :get
|
40
|
-
# alias_method :[]=, :set
|
41
|
-
end
|
30
|
+
@registry ||= empty_registry
|
42
31
|
end
|
43
32
|
|
44
33
|
def self.extended(base)
|
34
|
+
raise RuntimeError.new("#{base.inspect} doesn't respond to #[]") \
|
35
|
+
unless base.respond_to? :[]
|
36
|
+
|
45
37
|
class << base
|
46
|
-
alias_method :
|
38
|
+
alias_method :__get, :[]
|
47
39
|
|
48
40
|
def [](key)
|
49
|
-
value =
|
41
|
+
value = __get(key)
|
50
42
|
registry.each do |klass, condition|
|
51
43
|
result = condition.call(key, value) rescue false
|
52
44
|
value = klass.new(key, value) if value && result
|
data/smart_env.gemspec
CHANGED
@@ -17,4 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
|
+
s.add_development_dependency 'rspec', '~> 2.0'
|
21
|
+
s.add_development_dependency 'rcov'
|
20
22
|
end
|
data/spec/load_unload_spec.rb
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SmartEnv, 'load/unload' do
|
4
|
+
before do
|
5
|
+
class PassOne < String
|
6
|
+
attr_accessor :one
|
7
|
+
def initialize(key, value)
|
8
|
+
@one = true
|
9
|
+
super(value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
@env = {}
|
14
|
+
end
|
15
|
+
|
4
16
|
context "on extend" do
|
5
17
|
before do
|
6
|
-
@env = {}
|
7
18
|
@env.extend SmartEnv
|
19
|
+
end
|
8
20
|
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(key, value)
|
12
|
-
@one = true
|
13
|
-
super(value)
|
14
|
-
end
|
15
|
-
end
|
21
|
+
after do
|
22
|
+
@env.clear_registry if @env
|
16
23
|
end
|
17
24
|
|
18
25
|
it "should not bleed" do
|
@@ -24,4 +31,16 @@ describe SmartEnv, 'load/unload' do
|
|
24
31
|
@env['FOO'].one.should be_true
|
25
32
|
end
|
26
33
|
end
|
34
|
+
|
35
|
+
context "::clear_registry" do
|
36
|
+
before do
|
37
|
+
@env.extend SmartEnv
|
38
|
+
@env.use(PassOne).when{ true }
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should clear the hooks" do
|
42
|
+
@env.clear_registry
|
43
|
+
@env['FOO'].should_not respond_to :one
|
44
|
+
end
|
45
|
+
end
|
27
46
|
end
|
data/spec/spec_helper.rb
CHANGED
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: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,30 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
13
|
-
|
14
|
-
|
12
|
+
date: 2011-10-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70126964368960 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70126964368960
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rcov
|
27
|
+
requirement: &70126964368000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70126964368000
|
15
36
|
description: Allows you to register Proxy classes for ENV vars by using blocks to
|
16
37
|
match keys and values
|
17
38
|
email:
|
@@ -34,7 +55,6 @@ files:
|
|
34
55
|
- spec/registry_spec.rb
|
35
56
|
- spec/spec_helper.rb
|
36
57
|
- spec/uri_spec.rb
|
37
|
-
has_rdoc: true
|
38
58
|
homepage: ''
|
39
59
|
licenses: []
|
40
60
|
post_install_message:
|
@@ -47,15 +67,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
67
|
- - ! '>='
|
48
68
|
- !ruby/object:Gem::Version
|
49
69
|
version: '0'
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
hash: 3797767523412485183
|
50
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
74
|
none: false
|
52
75
|
requirements:
|
53
76
|
- - ! '>='
|
54
77
|
- !ruby/object:Gem::Version
|
55
78
|
version: '0'
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
hash: 3797767523412485183
|
56
82
|
requirements: []
|
57
83
|
rubyforge_project: smart_env
|
58
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.8.10
|
59
85
|
signing_key:
|
60
86
|
specification_version: 3
|
61
87
|
summary: Lazily proxy ENV values
|