bzproxies 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +40 -9
- data/lib/bzproxies/array_proxy.rb +37 -0
- data/lib/bzproxies/base.rb +27 -5
- data/lib/bzproxies/basic_object.rb +1 -1
- data/lib/bzproxies/core_ext.rb +23 -2
- data/lib/bzproxies/owner.rb +21 -11
- data/lib/bzproxies/version.rb +1 -1
- data/lib/bzproxies.rb +4 -2
- data/spec/{owner_spec.rb → accessors_spec.rb} +36 -6
- data/spec/array_proxy_spec.rb +94 -0
- data/spec/base_spec.rb +46 -2
- data/spec/fixtures/{owner.rb → accessors.rb} +10 -4
- data/spec/fixtures/array_proxy.rb +7 -0
- data/spec/fixtures/base.rb +1 -1
- data/spec/matchers.rb +46 -0
- data/spec/spec_helper.rb +1 -0
- metadata +39 -43
data/README.md
CHANGED
@@ -3,37 +3,68 @@ Bz proxies
|
|
3
3
|
|
4
4
|
Description
|
5
5
|
-----------
|
6
|
-
|
6
|
+
Several proxies and it's holder class module Owner
|
7
|
+
This bunch of proxies is just a result of my first steps and experiments with ruby metaprogramming.
|
8
|
+
It has some issues (perfomance and others), so it will be nesessary to fork project if you would like to use it in production.
|
9
|
+
|
10
|
+
Simple proxies use
|
11
|
+
------------------
|
12
|
+
First of all make a require call:
|
7
13
|
|
8
|
-
Use
|
9
|
-
----
|
10
14
|
require 'bzproxies'
|
11
15
|
|
16
|
+
Then, write your custom proxy (if needed), or just use Proxies::Base
|
17
|
+
|
12
18
|
class MyProxy < Proxies::Base #alias Proxy
|
13
19
|
def additional_methods
|
14
20
|
"additional from proxy"
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
24
|
+
You can use some objects that mimics objects covered by proxies:
|
25
|
+
|
18
26
|
class SameFunctionalityClass
|
19
27
|
include Proxies::Stub
|
20
28
|
def additional_methods
|
21
29
|
"additional from stub"
|
22
30
|
end
|
23
31
|
end
|
24
|
-
|
32
|
+
|
33
|
+
#TODO: create global function creting stub for concrete proxy (as same one in Delegate class).
|
34
|
+
|
35
|
+
Than you may use proxy_accessor to specify attribute that will cover some given values with proxy:
|
36
|
+
|
25
37
|
class MyProxyOwner
|
26
|
-
include Proxies::Owner #alias Owner
|
27
|
-
|
28
38
|
proxy_accessor :test, :proxy => MyProxy
|
29
39
|
end
|
30
40
|
|
31
|
-
|
32
41
|
owner = MyProxyOwner.new
|
33
42
|
|
34
43
|
owner.test = "test"
|
35
44
|
owner.test.additional # => "additional from proxy"
|
36
|
-
owner.test.
|
45
|
+
owner.test.proxy? # => true
|
37
46
|
owner.test = SameFunctionalityClass.new
|
38
47
|
owner.test.additional # => "additional from stub"
|
39
|
-
owner.test.
|
48
|
+
owner.test.proxy? # => false
|
49
|
+
|
50
|
+
Array proxy use
|
51
|
+
---------------
|
52
|
+
Array proxy is an example of how you can implement your own proxy derived from Proxies::Base.
|
53
|
+
This proxy covers each element with other proxy on initialization, push, unshift, << and other operations:
|
54
|
+
|
55
|
+
class MyProxyOwner
|
56
|
+
proxy_accessor :children, :proxies => [ArrayProxy, MyProxy]
|
57
|
+
def initialize
|
58
|
+
self.children = []
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
owner = MyProxyOwner.new
|
63
|
+
owner.children << "some test" << 123 << true
|
64
|
+
owner.children.map{|i| i.proxy?} # => [true,true,true]
|
65
|
+
|
66
|
+
Limitations
|
67
|
+
-----------
|
68
|
+
- You can't use proxied boolean and nil objects in boolean expressions.
|
69
|
+
Ruby doesn't support weak references so covered object will always return true even if it's target is nil or false.
|
70
|
+
- To setup object variables in methods use self.<accessor_name>= to stay them covered by proxy.
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bzproxies/base'
|
2
|
+
module Proxies
|
3
|
+
class ArrayProxy < Base
|
4
|
+
|
5
|
+
def initialize *args
|
6
|
+
super
|
7
|
+
raise ::ArgumentError, "expected Array, given #{@target.class}" unless @target.kind_of? ::Array
|
8
|
+
unless @proxies.empty? || @target.nil?
|
9
|
+
proxy = @proxies.first
|
10
|
+
@target = @target.map do |i|
|
11
|
+
unless i.respond_to? :stub?
|
12
|
+
proxy.new i, :proxies => @proxies[1..-1]
|
13
|
+
else
|
14
|
+
i
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
[:concat, :fill, :flatten!, :insert, :map!, :push, :replace, :unshift, :<<].each do |meth|
|
21
|
+
define_method meth do |*args, &block|
|
22
|
+
@target.send meth, *args, &block
|
23
|
+
unless @proxies.empty? || @target.nil?
|
24
|
+
proxy = @proxies.first
|
25
|
+
@target = @target.map do |i|
|
26
|
+
unless i.respond_to? :stub?
|
27
|
+
proxy.new i, :proxies => @proxies[1..-1]
|
28
|
+
else
|
29
|
+
i
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/bzproxies/base.rb
CHANGED
@@ -1,32 +1,54 @@
|
|
1
1
|
require 'bzproxies/stub'
|
2
2
|
require 'bzproxies/basic_object'
|
3
|
+
require 'bzproxies/core_ext'
|
3
4
|
|
4
5
|
module Proxies
|
5
6
|
class Base < BasicObject
|
6
7
|
include Stub
|
7
8
|
|
8
9
|
attr_accessor :target
|
10
|
+
attr_reader :proxies
|
9
11
|
|
10
12
|
alias non_recursive_target target
|
11
13
|
|
12
14
|
def target
|
13
15
|
begin
|
14
16
|
@target.target
|
15
|
-
rescue
|
17
|
+
rescue ::NoMethodError
|
16
18
|
non_recursive_target
|
17
|
-
end
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
def proxy?
|
21
23
|
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def respond_to? meth, hidden = false
|
27
|
+
metaclass = class << self; self; end
|
28
|
+
(metaclass.method_defined? meth) || (@target.respond_to? meth, hidden)
|
22
29
|
end
|
23
30
|
|
24
|
-
def
|
25
|
-
|
31
|
+
def eql? any
|
32
|
+
class1 = (any.respond_to? :proxy?) ? (class << any; self; end).superclass : any.class
|
33
|
+
class2 = (class << self; self; end).superclass
|
34
|
+
(self == any) && (class1 == class2)
|
35
|
+
end
|
36
|
+
|
37
|
+
def == any
|
38
|
+
(any.respond_to? :proxy?) ? @target == any.target : @target == any
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize *args
|
42
|
+
@target = args.first
|
43
|
+
@proxies = []
|
44
|
+
@proxies << args.last[:proxy] << args.last[:proxies] if (args.last.kind_of?(::Hash) && (args.length > 1))
|
45
|
+
@proxies.flatten!
|
46
|
+
@proxies.compact!
|
26
47
|
end
|
27
48
|
|
28
49
|
def method_missing m, *args, &block
|
29
|
-
@target.
|
50
|
+
@target.__send__ m, *args, &block
|
30
51
|
end
|
52
|
+
|
31
53
|
end
|
32
54
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
if RUBY_VERSION.gsub(/\D/, "").to_i < 190
|
2
2
|
class BasicObject
|
3
|
-
instance_methods.each { |m| undef_method m unless m =~ /(^__|^
|
3
|
+
instance_methods.each { |m| undef_method m unless m =~ /(^__|^send$|^object_id$|^equal?$)/ }
|
4
4
|
end
|
5
5
|
end
|
data/lib/bzproxies/core_ext.rb
CHANGED
@@ -1,5 +1,26 @@
|
|
1
|
+
require 'bzproxies/owner'
|
2
|
+
|
1
3
|
class Object
|
2
|
-
|
3
|
-
|
4
|
+
include Proxies::Owner
|
5
|
+
end
|
6
|
+
|
7
|
+
class NilClass
|
8
|
+
alias old_equality ==
|
9
|
+
def == any
|
10
|
+
(any.respond_to? :target) ? old_equality(any.target) : old_equality(any)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class TrueClass
|
15
|
+
alias old_equality ==
|
16
|
+
def == any
|
17
|
+
(any.respond_to? :target) ? old_equality(any.target) : old_equality(any)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class FalseClass
|
22
|
+
alias old_equality ==
|
23
|
+
def == any
|
24
|
+
(any.respond_to? :target) ? old_equality(any.target) : old_equality(any)
|
4
25
|
end
|
5
26
|
end
|
data/lib/bzproxies/owner.rb
CHANGED
@@ -1,28 +1,39 @@
|
|
1
|
-
require "bzproxies/base"
|
2
1
|
|
3
2
|
module Proxies
|
4
3
|
module Owner
|
5
4
|
|
6
5
|
def self.included(base)
|
7
|
-
base.send :extend,
|
6
|
+
base.send :extend, Accessors
|
8
7
|
end
|
9
8
|
|
10
|
-
module
|
9
|
+
module Accessors
|
10
|
+
|
11
11
|
def proxy_reader(*args)
|
12
12
|
args.pop if args.last.kind_of? Hash
|
13
13
|
attr_reader *args
|
14
14
|
end
|
15
15
|
|
16
16
|
def proxy_writer(*args)
|
17
|
-
|
18
|
-
|
17
|
+
proxies = []
|
18
|
+
if (args.last.kind_of?(::Hash) && (args.length > 1))
|
19
|
+
opts = args.pop
|
20
|
+
proxies << opts[:proxy] << opts[:proxies]
|
21
|
+
end
|
22
|
+
proxies.flatten!
|
23
|
+
proxies.compact!
|
24
|
+
proxy = proxies.shift || Proxies::Base
|
25
|
+
unless proxy.instance_methods.include? :proxy?
|
26
|
+
raise ArgumentError, "Expected proxy, given #{proxy.inspect} #{proxy.class}"
|
27
|
+
end
|
19
28
|
args.each do |name|
|
20
|
-
|
29
|
+
unless name.kind_of? String or name.kind_of? Symbol
|
30
|
+
raise ArgumentError, "Expected String or Symbol, given #{name.inspect} #{name.class}"
|
31
|
+
end
|
21
32
|
define_method("#{name}=") do |v|
|
22
|
-
if v.stub?
|
33
|
+
if v.respond_to? :stub?
|
23
34
|
val = v
|
24
35
|
else
|
25
|
-
val = proxy.send :new, v
|
36
|
+
val = proxy.send :new, v, :proxies => proxies
|
26
37
|
end
|
27
38
|
instance_variable_set("@#{name}", val)
|
28
39
|
end
|
@@ -32,9 +43,8 @@ module Proxies
|
|
32
43
|
def proxy_accessor(*args)
|
33
44
|
proxy_reader(*args)
|
34
45
|
proxy_writer(*args)
|
35
|
-
end
|
46
|
+
end
|
36
47
|
|
37
48
|
end
|
38
|
-
|
39
49
|
end
|
40
|
-
end
|
50
|
+
end
|
data/lib/bzproxies/version.rb
CHANGED
data/lib/bzproxies.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
|
4
|
-
describe Proxies::Owner do
|
4
|
+
describe Proxies::Owner::Accessors do
|
5
5
|
|
6
6
|
it "works when options hash ommited" do
|
7
7
|
expect {Ex2.new}.not_to raise_error
|
@@ -11,7 +11,7 @@ describe Proxies::Owner do
|
|
11
11
|
it "creates proxy object attr_accessor" do
|
12
12
|
a = "source"
|
13
13
|
owner = Ex1.new
|
14
|
-
owner.methods.should
|
14
|
+
owner.methods.should include_one_of :test, "test"
|
15
15
|
owner.test = Proxy.new(a)
|
16
16
|
owner.test.proxy?.should be_true #testing method
|
17
17
|
end
|
@@ -20,7 +20,7 @@ describe Proxies::Owner do
|
|
20
20
|
describe "proxy_writer" do
|
21
21
|
it "creates attr write method" do
|
22
22
|
owner = Ex2.new
|
23
|
-
owner.methods.should
|
23
|
+
owner.methods.should include_one_of :test=, "test="
|
24
24
|
end
|
25
25
|
|
26
26
|
it "covers non-proxy object with proxy" do
|
@@ -39,17 +39,47 @@ describe Proxies::Owner do
|
|
39
39
|
owner.test = b
|
40
40
|
owner.test.equal?(b).should be_true
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should raise an exception while non-proxy class given" do
|
44
|
+
expect do
|
45
|
+
class Ex4
|
46
|
+
include Proxies::Owner
|
47
|
+
proxy_writer :test, :proxy => Array
|
48
|
+
end
|
49
|
+
end.to raise_exception(ArgumentError)
|
50
|
+
end
|
42
51
|
end
|
43
52
|
|
44
|
-
it "
|
53
|
+
it "have it's own proxy for each attribute" do
|
45
54
|
owner = Ex3.new
|
46
55
|
owner.test1 = "test"
|
47
56
|
owner.test2 = "test"
|
48
|
-
|
49
57
|
owner.test1.check.should == MyProxy1
|
50
58
|
owner.test2.check.should == MyProxy2
|
51
|
-
|
52
59
|
end
|
53
60
|
|
61
|
+
it "parse plural proxies option form" do
|
62
|
+
owner = Ex4.new
|
63
|
+
owner.test1 = "test"
|
64
|
+
owner.test1.check.should == MyProxy1
|
65
|
+
end
|
66
|
+
|
67
|
+
it "parse multiple proxies" do
|
68
|
+
owner = Ex4.new
|
69
|
+
owner.test2 = "test"
|
70
|
+
owner.test2.check.should == MyProxy1
|
71
|
+
end
|
72
|
+
|
73
|
+
it "passes additional proxies hash options to proxy instance" do
|
74
|
+
owner = Ex4.new
|
75
|
+
owner.test2 = "test"
|
76
|
+
owner.test2.proxies.should == [MyProxy2]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "works properly with array proxy" do
|
80
|
+
owner = Ex5.new
|
81
|
+
owner.children = [1,2]
|
82
|
+
owner.children.should each_respond_to :check
|
83
|
+
end
|
54
84
|
|
55
85
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Proxies::ArrayProxy do
|
4
|
+
|
5
|
+
describe "initialization" do
|
6
|
+
it "raises an exception when initializing with non array" do
|
7
|
+
expect {Proxies::ArrayProxy.new "test"}.to raise_exception(ArgumentError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "doesn't raise an exception while initializing with array" do
|
11
|
+
expect {Proxies::ArrayProxy.new ["test"]}.not_to raise_exception
|
12
|
+
end
|
13
|
+
|
14
|
+
it "covers each element of given array with proxy" do
|
15
|
+
test = Proxies::ArrayProxy.new [1, 'two', :three], :proxies => TestCovering
|
16
|
+
test.should each_respond_to :test?
|
17
|
+
test.should_not each_respond_to :testother?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def check any_array_proxy
|
22
|
+
|
23
|
+
end
|
24
|
+
context "if proxies" do
|
25
|
+
before(:all) do
|
26
|
+
@test = [1,2,3]
|
27
|
+
@proxy = Proxies::ArrayProxy.new @test, :proxies => TestCovering
|
28
|
+
end
|
29
|
+
|
30
|
+
it "have a copy of given array" do
|
31
|
+
@test.each do |i|
|
32
|
+
expect {i.proxy?}.to raise_exception(NoMethodError)
|
33
|
+
end
|
34
|
+
@test.should_not be_equal @proxy.target
|
35
|
+
end
|
36
|
+
|
37
|
+
it "covers with this proxy each element that inserted into array" do
|
38
|
+
# [:replace, :unshift]
|
39
|
+
@proxy.should each_respond_to :test?
|
40
|
+
test1 = ["one", :two, [3]]
|
41
|
+
|
42
|
+
@proxy.concat test1
|
43
|
+
@proxy.should each_respond_to :test?
|
44
|
+
|
45
|
+
@proxy << "four"
|
46
|
+
@proxy.should each_respond_to :test?
|
47
|
+
|
48
|
+
@proxy.fill "five"
|
49
|
+
@proxy.should each_respond_to :test?
|
50
|
+
|
51
|
+
@proxy.insert 33, 33
|
52
|
+
@proxy.should each_respond_to :test?
|
53
|
+
|
54
|
+
@proxy << [[["ababa"]]]
|
55
|
+
@proxy.flatten!
|
56
|
+
@proxy.should each_respond_to :test?
|
57
|
+
|
58
|
+
@proxy.uniq!
|
59
|
+
(@proxy == ["five", nil, 33, "ababa"]).should be_true
|
60
|
+
(["five", nil, 33, "ababa"] == @proxy).should be_true
|
61
|
+
@proxy.should each_respond_to :test?
|
62
|
+
|
63
|
+
@proxy.push "six"
|
64
|
+
@proxy.should each_respond_to :test?
|
65
|
+
|
66
|
+
@proxy.unshift 7
|
67
|
+
@proxy.should each_respond_to :test?
|
68
|
+
|
69
|
+
@proxy.map! {|i| i.to_s}
|
70
|
+
(@proxy == ["7", "five", "", "33", "ababa", "six"]).should be_true
|
71
|
+
@proxy.should each_respond_to :test?
|
72
|
+
|
73
|
+
@proxy.replace [1,2,3,4,5]
|
74
|
+
@proxy.should each_respond_to :test?
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "if doesn't proxy" do
|
80
|
+
before(:all) do
|
81
|
+
@test = [1,2,3]
|
82
|
+
@proxy = Proxies::ArrayProxy.new @test
|
83
|
+
end
|
84
|
+
|
85
|
+
it "have a given array" do
|
86
|
+
@test.should be_equal @proxy.target
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not cover elements with proxies" do
|
90
|
+
@proxy.should_not any_respond_to :test?
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
data/spec/base_spec.rb
CHANGED
@@ -9,8 +9,10 @@ describe Proxies::Base do
|
|
9
9
|
((test.methods)+(test.class.methods)).should == meth
|
10
10
|
end
|
11
11
|
|
12
|
-
it "stub? methods returns true" do
|
13
|
-
Proxy.new("source")
|
12
|
+
it "stub? and proxy? methods returns true" do
|
13
|
+
pr = Proxy.new("source")
|
14
|
+
pr.stub?.should be_true
|
15
|
+
pr.proxy?.should be_true
|
14
16
|
end
|
15
17
|
|
16
18
|
it "used by inherited proxy and doesnt proxy its own methods" do
|
@@ -38,4 +40,46 @@ describe Proxies::Base do
|
|
38
40
|
two_level = Inherited.new(Proxy.new(a))
|
39
41
|
a.should be_equal two_level.target
|
40
42
|
end
|
43
|
+
|
44
|
+
it "can take instance proxies hash while creating" do
|
45
|
+
a = "source"
|
46
|
+
test = Inherited.new(a, :proxies => Proxy)
|
47
|
+
test.proxies.should == [Proxy]
|
48
|
+
test2 = Proxy.new(a, :proxies => [Proxy, Proxy])
|
49
|
+
test2.proxies.should == [Proxy, Proxy]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "covers respond_to with it's own" do
|
53
|
+
a = "source"
|
54
|
+
test = Inherited.new a
|
55
|
+
(test.respond_to? :proxy?).should be_true
|
56
|
+
(test.respond_to? :some_other_than_proxy?).should be_false
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
it "should be eql and == for same and equal object proxies" do
|
61
|
+
a = false
|
62
|
+
test1 = Proxy.new a
|
63
|
+
test2 = Proxy.new a
|
64
|
+
test3 = Proxy.new false
|
65
|
+
|
66
|
+
(a == test1).should be_true
|
67
|
+
(a == test3).should be_true
|
68
|
+
(test1 == a).should be_true
|
69
|
+
(test3 == a).should be_true
|
70
|
+
|
71
|
+
a.should_not be_eql test1
|
72
|
+
(test1.eql? a).should be_false
|
73
|
+
|
74
|
+
(test1 == test2).should be_true
|
75
|
+
(test2 == test1).should be_true
|
76
|
+
(test1 == test3).should be_true
|
77
|
+
(test3 == test1).should be_true
|
78
|
+
|
79
|
+
(test1.eql? test2).should be_true
|
80
|
+
(test2.eql? test1).should be_true
|
81
|
+
(test1.eql? test3).should be_true
|
82
|
+
(test3.eql? test1).should be_true
|
83
|
+
end
|
84
|
+
|
41
85
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'bzproxies'
|
2
2
|
|
3
3
|
class Ex1
|
4
|
-
include Proxies::Owner
|
5
4
|
proxy_reader :test, :proxy => Proxies::Base
|
6
5
|
def test= any
|
7
6
|
@test = any
|
@@ -9,14 +8,13 @@ class Ex1
|
|
9
8
|
end
|
10
9
|
|
11
10
|
class Ex2
|
12
|
-
include Proxies::Owner
|
13
11
|
proxy_writer :test
|
14
12
|
def test
|
15
13
|
@test
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
|
-
class MyProxy1 < Proxy
|
17
|
+
class MyProxy1 < Proxy
|
20
18
|
def check
|
21
19
|
return ::MyProxy1
|
22
20
|
end
|
@@ -29,7 +27,15 @@ class MyProxy2 < Proxy
|
|
29
27
|
end
|
30
28
|
|
31
29
|
class Ex3
|
32
|
-
include Proxies::Owner
|
33
30
|
proxy_accessor :test1, :proxy => MyProxy1
|
34
31
|
proxy_accessor :test2, :proxy => MyProxy2
|
32
|
+
end
|
33
|
+
|
34
|
+
class Ex4
|
35
|
+
proxy_accessor :test1, :proxies => MyProxy1
|
36
|
+
proxy_accessor :test2, :proxies => [MyProxy1, MyProxy2]
|
37
|
+
end
|
38
|
+
|
39
|
+
class Ex5
|
40
|
+
proxy_accessor :children, :proxies => [ArrayProxy, MyProxy1]
|
35
41
|
end
|
data/spec/fixtures/base.rb
CHANGED
data/spec/matchers.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :include_one_of do |*params|
|
4
|
+
match do |enum|
|
5
|
+
result = false
|
6
|
+
params.each do |p|
|
7
|
+
if enum.include? p
|
8
|
+
result = true
|
9
|
+
break
|
10
|
+
end
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec::Matchers.define :each_respond_to do |*methods|
|
17
|
+
match do |enum|
|
18
|
+
result = true
|
19
|
+
methods.each do |meth|
|
20
|
+
enum.each do |elem|
|
21
|
+
unless elem.respond_to? meth.to_s
|
22
|
+
result = false
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
break if result == false
|
27
|
+
end
|
28
|
+
result
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec::Matchers.define :any_respond_to do |*methods|
|
33
|
+
match do |enum|
|
34
|
+
result = false
|
35
|
+
methods.each do |meth|
|
36
|
+
enum.each do |elem|
|
37
|
+
if elem.respond_to? meth.to_s
|
38
|
+
result = true
|
39
|
+
break
|
40
|
+
end
|
41
|
+
end
|
42
|
+
break if result == true
|
43
|
+
end
|
44
|
+
result
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,48 +1,44 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bzproxies
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Bombazook
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-10-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: bundler
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &75069720 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: rspec
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *75069720
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &75069470 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
29
|
+
requirements:
|
32
30
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.6'
|
35
33
|
type: :development
|
36
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *75069470
|
37
36
|
description: collection of reusable proxies and accessorsetc.
|
38
37
|
email: bombazook@gmail.com
|
39
38
|
executables: []
|
40
|
-
|
41
39
|
extensions: []
|
42
|
-
|
43
40
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
files:
|
41
|
+
files:
|
46
42
|
- .gitignore
|
47
43
|
- .rspec
|
48
44
|
- Gemfile
|
@@ -50,43 +46,43 @@ files:
|
|
50
46
|
- Rakefile
|
51
47
|
- bzproxies.gemspec
|
52
48
|
- lib/bzproxies.rb
|
49
|
+
- lib/bzproxies/array_proxy.rb
|
53
50
|
- lib/bzproxies/base.rb
|
54
51
|
- lib/bzproxies/basic_object.rb
|
55
52
|
- lib/bzproxies/core_ext.rb
|
56
53
|
- lib/bzproxies/owner.rb
|
57
54
|
- lib/bzproxies/stub.rb
|
58
55
|
- lib/bzproxies/version.rb
|
56
|
+
- spec/accessors_spec.rb
|
57
|
+
- spec/array_proxy_spec.rb
|
59
58
|
- spec/base_spec.rb
|
59
|
+
- spec/fixtures/accessors.rb
|
60
|
+
- spec/fixtures/array_proxy.rb
|
60
61
|
- spec/fixtures/base.rb
|
61
|
-
- spec/
|
62
|
-
- spec/owner_spec.rb
|
62
|
+
- spec/matchers.rb
|
63
63
|
- spec/spec_helper.rb
|
64
64
|
homepage: http://github.com/bombazook/bzproxies
|
65
65
|
licenses: []
|
66
|
-
|
67
66
|
post_install_message:
|
68
67
|
rdoc_options: []
|
69
|
-
|
70
|
-
require_paths:
|
68
|
+
require_paths:
|
71
69
|
- lib
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
71
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
77
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version:
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
84
82
|
requirements: []
|
85
|
-
|
86
83
|
rubyforge_project: bzproxies
|
87
|
-
rubygems_version: 1.8.
|
84
|
+
rubygems_version: 1.8.6
|
88
85
|
signing_key:
|
89
86
|
specification_version: 3
|
90
87
|
summary: collection of reusable proxies and accessors
|
91
88
|
test_files: []
|
92
|
-
|