bzproxies 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,21 +9,20 @@ module Proxies
9
9
 
10
10
  module ClassMethods
11
11
  def proxy_reader(*args)
12
- (load_options args.pop) if args.last.kind_of? Hash
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
- load_options :proxy => Proxy
18
- (load_options args.pop) if args.last.kind_of? Hash
19
- raise ArgumentError, "Unexpected proxy class. Expected 'Class'" unless @proxy.respond_to? :new
17
+ proxy = (args.pop[:proxy] if args.last.kind_of? Hash) || Proxies::Base
18
+ raise ArgumentError, "Unexpected proxy class. Expected class, given #{proxy.inspect}" unless proxy.respond_to? :new
20
19
  args.each do |name|
21
20
  raise ArgumentError, "Unexpected argument. Expected String or Symbol" unless name.kind_of? String or name.kind_of? Symbol
22
21
  define_method("#{name}=") do |v|
23
22
  if v.stub?
24
23
  val = v
25
24
  else
26
- val = (self.class.instance_variable_get :@proxy).send :new, v
25
+ val = proxy.send :new, v
27
26
  end
28
27
  instance_variable_set("@#{name}", val)
29
28
  end
@@ -35,17 +34,6 @@ module Proxies
35
34
  proxy_writer(*args)
36
35
  end
37
36
 
38
- protected
39
-
40
- def load_options opts
41
- opts.each_pair do |key, val|
42
- metaclass = class << self; self; end
43
- metaclass.send :attr_reader, key
44
- instance_variable_set "@#{key}", val
45
- end
46
- self
47
- end
48
-
49
37
  end
50
38
 
51
39
  end
@@ -1,3 +1,3 @@
1
1
  module Bzproxies
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -16,15 +16,20 @@ class Ex2
16
16
  end
17
17
  end
18
18
 
19
- class Ex3
20
- include Proxies::Owner
21
- proxy_accessor :test
19
+ class MyProxy1 < Proxy
20
+ def check
21
+ return ::MyProxy1
22
+ end
22
23
  end
23
-
24
- class Ex4
25
- include Proxies::Owner
24
+
25
+ class MyProxy2 < Proxy
26
+ def check
27
+ return ::MyProxy2
28
+ end
26
29
  end
27
30
 
28
- class Ex5
29
- include Proxies::Stub
31
+ class Ex3
32
+ include Proxies::Owner
33
+ proxy_accessor :test1, :proxy => MyProxy1
34
+ proxy_accessor :test2, :proxy => MyProxy2
30
35
  end
data/spec/owner_spec.rb CHANGED
@@ -7,19 +7,6 @@ describe Proxies::Owner do
7
7
  expect {Ex2.new}.not_to raise_error
8
8
  end
9
9
 
10
- it "creates singleton private class attr_reader and variables from hash" do
11
- Ex4.send :load_options, :test => "test"
12
- (Ex4.send :test).should == "test"
13
- end
14
-
15
- it "sets new value, when variable exists" do
16
- a = "test"
17
- Ex4.send :load_options, :test => "test"
18
- (Ex4.send :test).should == "test"
19
- Ex4.send :load_options, :test => "test2"
20
- (Ex4.send :test).should == "test2"
21
- end
22
-
23
10
  describe "proxy_reader" do
24
11
  it "creates proxy object attr_accessor" do
25
12
  a = "source"
@@ -28,14 +15,10 @@ describe Proxies::Owner do
28
15
  owner.test = Proxy.new(a)
29
16
  owner.test.proxy?.should be_true #testing method
30
17
  end
31
-
32
- it "gets options hash" do
33
- (Ex1.send :proxy).should == Proxies::Base
34
- end
35
18
  end
36
19
 
37
20
  describe "proxy_writer" do
38
- it "creates attr writes method" do
21
+ it "creates attr write method" do
39
22
  owner = Ex2.new
40
23
  owner.methods.should include :test=
41
24
  end
@@ -58,6 +41,15 @@ describe Proxies::Owner do
58
41
  end
59
42
  end
60
43
 
44
+ it "could have it's own proxy for each attribute" do
45
+ owner = Ex3.new
46
+ owner.test1 = "test"
47
+ owner.test2 = "test"
48
+
49
+ owner.test1.check.should == MyProxy1
50
+ owner.test2.check.should == MyProxy2
51
+
52
+ end
61
53
 
62
54
 
63
55
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bzproxies
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bombazook
@@ -57,7 +57,6 @@ files:
57
57
  - lib/bzproxies/stub.rb
58
58
  - lib/bzproxies/version.rb
59
59
  - spec/base_spec.rb
60
- - spec/basic_object_spec.rb
61
60
  - spec/fixtures/base.rb
62
61
  - spec/fixtures/owner.rb
63
62
  - spec/owner_spec.rb
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BasicObject do
4
-
5
- end