schizo 0.1.3 → 0.2.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/.travis.yml CHANGED
@@ -1,10 +1,7 @@
1
- rvm:
2
- - 1.9.2
3
- - 1.9.3
4
- gemfiles:
5
- - .gemfiles/Gemfile.activerecord-3.2
6
- - Gemfile
7
1
  matrix:
2
+ exclude:
3
+ - rvm: ""
4
+ gemfile: ""
8
5
  include:
9
6
  - rvm: 1.9.2
10
7
  gemfile: .gemfiles/Gemfile.activerecord-3.2
data/CHANGELOG CHANGED
@@ -1,11 +1,14 @@
1
+ 0.2.0
2
+ * Support for ActiveSupport::Concern
3
+
1
4
  0.1.3
2
5
  * Specify multiple roles as argument list to #as (andriytyurnikov)
3
6
 
4
7
  0.1.2
5
- * Allow roles to be namespaced
8
+ * Allow roles to be namespaced
6
9
 
7
10
  0.1.1
8
- * Updated gemspec info
11
+ * Updated gemspec info
9
12
 
10
13
  0.1.0
11
- * Initial release
14
+ * Initial release
data/README.rdoc CHANGED
@@ -162,6 +162,19 @@ Alternatively...
162
162
  end
163
163
  end
164
164
 
165
+ == ActiveSupport::Concern
166
+
167
+ You can use <tt>ActiveSupport::Concern</tt> instead of <tt>Schizo::Role</tt>
168
+
169
+ module Baz
170
+ extend ActiveSupport::Concern
171
+ def something; end
172
+ end
173
+
174
+ foo = Foo.new
175
+ baz = foo.as(Baz)
176
+ baz.something
177
+
165
178
  == Documentation
166
179
 
167
180
  {\http://doc.stochasticbytes.com/schizo/index.html}[http://doc.stochasticbytes.com/schizo/index.html]
@@ -19,7 +19,11 @@ module Schizo
19
19
  container_module.const_get(class_name)
20
20
  else
21
21
  klass = Class.new(base){ include Base }
22
- klass.class_eval(&role.extended_block) if role.extended_block
22
+ if defined?(ActiveSupport::Concern) and role.is_a?(ActiveSupport::Concern)
23
+ klass.send :include, role
24
+ elsif role.is_a?(Schizo::Role)
25
+ klass.class_eval(&role.extended_block) if role.extended_block
26
+ end
23
27
  container_module.const_set(class_name, klass)
24
28
  end
25
29
  end
@@ -35,11 +35,15 @@ module Schizo
35
35
  # its role into facade we're building.
36
36
  previous_facade = object
37
37
  while previous_facade.respond_to?(:dci)
38
- facade.extend(previous_facade.dci.role)
38
+ if previous_facade.dci.role.is_a?(Schizo::Role)
39
+ facade.extend(previous_facade.dci.role)
40
+ end
39
41
  previous_facade = previous_facade.dci.object
40
42
  end
41
-
42
- facade.extend(role)
43
+
44
+ if role.is_a?(Schizo::Role)
45
+ facade.extend(role)
46
+ end
43
47
  Schizo::Facade.copy_instance_variables(object, facade)
44
48
  end
45
49
  end
@@ -1,3 +1,3 @@
1
1
  module Schizo #:nodoc:
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -21,17 +21,38 @@ module Schizo
21
21
  end
22
22
  end
23
23
 
24
+ let(:concern) do
25
+ Module.new do
26
+ extend ActiveSupport::Concern
27
+ included do
28
+ @test_concern_var = 1
29
+ end
30
+ end
31
+ end
32
+
24
33
  let(:builder) do
25
34
  ClassBuilder.new(base, role)
26
35
  end
27
36
 
37
+ let(:builder_concern) do
38
+ ClassBuilder.new(base, concern)
39
+ end
40
+
28
41
  it "works with namespaced roles" do
29
42
  role.module_eval do
30
43
  def self.name
31
44
  "Namespaced::Role"
32
45
  end
33
46
  end
47
+
48
+ concern.module_eval do
49
+ def self.name
50
+ "Namespaced::Concern"
51
+ end
52
+ end
53
+
34
54
  builder.product.to_s.should == "Schizo::Facades::Foo::Namespaced::Role"
55
+ builder_concern.product.to_s.should == "Schizo::Facades::Foo::Namespaced::Concern"
35
56
  end
36
57
 
37
58
  context "#initialize" do
@@ -39,6 +60,9 @@ module Schizo
39
60
  it "sets base and role" do
40
61
  builder.base.should == base
41
62
  builder.role.should == role
63
+
64
+ builder_concern.base.should == base
65
+ builder_concern.role.should == concern
42
66
  end
43
67
 
44
68
  end
@@ -51,6 +75,12 @@ module Schizo
51
75
  facade.ancestors.should include(base)
52
76
  facade.ancestors.should include(Base)
53
77
  end
78
+
79
+ builder_concern.product.tap do |facade|
80
+ facade.should be_a(Class)
81
+ facade.ancestors.should include(base)
82
+ facade.ancestors.should include(Base)
83
+ end
54
84
  end
55
85
 
56
86
  end
@@ -20,6 +20,19 @@ module Schizo
20
20
  end
21
21
  end
22
22
 
23
+ let(:concern) do
24
+ Module.new do
25
+ extend ActiveSupport::Concern
26
+ included do
27
+ @test_concern_var = 1
28
+ end
29
+ end
30
+ end
31
+
32
+ let(:concern_builder) do
33
+ ClassBuilder.new(base, concern)
34
+ end
35
+
23
36
  let(:builder) do
24
37
  ClassBuilder.new(base, role)
25
38
  end
@@ -28,26 +41,35 @@ module Schizo
28
41
  builder.product
29
42
  end
30
43
 
44
+ let(:concern_facade) do
45
+ concern_builder.product
46
+ end
47
+
31
48
  it "has the same #name as its superclass" do
32
49
  facade.name.should == "Foo"
50
+ concern_facade.name.should == "Foo"
33
51
  base.name.should == "Foo"
34
52
  end
35
53
 
36
54
  it "#initialize has arity == 2" do
37
55
  base.instance_method(:initialize).arity.should < 2
38
56
  facade.instance_method(:initialize).arity.should == 2
57
+ concern_facade.instance_method(:initialize).arity.should == 2
39
58
  end
40
59
 
41
60
  it "has class evaled the extended block of the role" do
42
61
  facade.should be_instance_variable_defined(:@test_var)
62
+ concern_facade.should be_instance_variable_defined(:@test_concern_var)
43
63
  end
44
64
 
45
65
  it "is defined in Schizo::Facades" do
46
66
  facade.should == Schizo::Facades.const_get(base.name).const_get("AnonRole#{role.object_id}")
67
+ concern_facade.should == Schizo::Facades.const_get(base.name).const_get("AnonRole#{concern.object_id}")
47
68
  end
48
69
 
49
70
  it "is a singleton" do
50
71
  facade.object_id.should == ClassBuilder.new(base, role).product.object_id
72
+ concern_facade.object_id.should == ClassBuilder.new(base, concern).product.object_id
51
73
  end
52
74
 
53
75
  end
@@ -19,6 +19,15 @@ module Schizo
19
19
  end
20
20
  end
21
21
 
22
+ let(:concern) do
23
+ Module.new do
24
+ extend ActiveSupport::Concern
25
+ def bar(v)
26
+ @bar = v
27
+ end
28
+ end
29
+ end
30
+
22
31
  let(:object) do
23
32
  base.new
24
33
  end
@@ -27,11 +36,18 @@ module Schizo
27
36
  ObjectBuilder.new(object, role)
28
37
  end
29
38
 
39
+ let(:concern_builder) do
40
+ ObjectBuilder.new(object, concern)
41
+ end
42
+
30
43
  context "#initialize" do
31
44
 
32
45
  it "sets object and role" do
33
46
  builder.object.should == object
34
47
  builder.role.should == role
48
+
49
+ concern_builder.object.should == object
50
+ concern_builder.role.should == concern
35
51
  end
36
52
 
37
53
  end
@@ -41,6 +57,9 @@ module Schizo
41
57
  it "returns a facade object" do
42
58
  builder.product.should be_a(base)
43
59
  builder.product.should be_instance_of(base)
60
+
61
+ concern_builder.product.should be_a(base)
62
+ concern_builder.product.should be_instance_of(base)
44
63
  end
45
64
 
46
65
  end
@@ -19,6 +19,15 @@ module Schizo
19
19
  end
20
20
  end
21
21
 
22
+ let(:concern) do
23
+ Module.new do
24
+ extend ActiveSupport::Concern
25
+ def baz(v)
26
+ @baz = v
27
+ end
28
+ end
29
+ end
30
+
22
31
  let(:object) do
23
32
  base.new
24
33
  end
@@ -27,22 +36,35 @@ module Schizo
27
36
  ObjectBuilder.new(object, role)
28
37
  end
29
38
 
39
+ let(:concern_builder) do
40
+ ObjectBuilder.new(object, concern)
41
+ end
42
+
30
43
  let(:facade) do
31
44
  builder.product
32
45
  end
33
46
 
47
+ let(:concern_facade) do
48
+ concern_builder.product
49
+ end
50
+
34
51
  it "is not the same as the original object" do
35
52
  facade.should_not == object
53
+ concern_facade.should_not == object
36
54
  end
37
55
 
38
56
  it "responds to methods defined in its role" do
39
57
  facade.should respond_to(:bar)
58
+ concern_facade.should respond_to(:baz)
40
59
  end
41
60
 
42
61
  it "calling methods should not affect original object" do
43
62
  facade.bar("test")
44
63
  facade.instance_variable_get(:@bar).should == "test"
64
+ concern_facade.baz("test")
65
+ concern_facade.instance_variable_get(:@baz).should == "test"
45
66
  object.instance_variable_get(:@bar).should be_nil
67
+ object.instance_variable_get(:@baz).should be_nil
46
68
  end
47
69
 
48
70
  context "#actualize" do
@@ -50,14 +72,19 @@ module Schizo
50
72
  before(:all) do
51
73
  facade.bar("blah")
52
74
  facade.actualize
75
+
76
+ concern_facade.baz("blah")
77
+ concern_facade.actualize
53
78
  end
54
79
 
55
80
  it "returns the original object" do
56
81
  facade.actualize.should == object
82
+ concern_facade.actualize.should == object
57
83
  end
58
84
 
59
85
  it "sets instance variables in the original object" do
60
86
  object.instance_variable_get(:@bar).should == "blah"
87
+ object.instance_variable_get(:@baz).should == "blah"
61
88
  end
62
89
 
63
90
  it "does not set any internal dci instance variables" do
data/spec/nested_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe "a nested facade for ClassA with RoleA, RoleB and RoleC" do
25
25
 
26
26
  let(:role_c) do
27
27
  Module.new do
28
- extend Schizo::Role
28
+ extend ActiveSupport::Concern
29
29
  def set_baz; @baz = "baz"; end
30
30
  end
31
31
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: schizo
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christopher J. Bottaro
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-23 00:00:00.000000000 Z
12
+ date: 2013-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  - !ruby/object:Gem::Version
154
154
  segments:
155
155
  - 0
156
- hash: -3318887318708841529
156
+ hash: -1275366458980579646
157
157
  version: '0'
158
158
  none: false
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  segments:
164
164
  - 0
165
- hash: -3318887318708841529
165
+ hash: -1275366458980579646
166
166
  version: '0'
167
167
  none: false
168
168
  requirements: []