heredity 0.0.2 → 0.0.3

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.
@@ -3,6 +3,8 @@ require 'thread'
3
3
  module Heredity
4
4
  module InheritableClassInstanceVariables
5
5
  def self.included(klass)
6
+ return if klass.respond_to?(:_inheritable_class_instance_variables)
7
+
6
8
  Thread.exclusive do
7
9
  klass.extend(::Heredity::InheritableClassInstanceVariables::ClassMethods)
8
10
 
@@ -19,6 +21,10 @@ module Heredity
19
21
  end
20
22
 
21
23
  module ClassMethods
24
+ def _inheritable_class_instance_variables
25
+ @_inheritable_class_instance_variables
26
+ end
27
+
22
28
  def inheritable_attributes(*args)
23
29
  Thread.exclusive do
24
30
  args.flatten.compact.uniq.each do |class_instance_variable|
@@ -1,3 +1,3 @@
1
1
  module Heredity
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/heredity.rb CHANGED
@@ -1,4 +1,9 @@
1
+ require "heredity/inheritable_class_instance_variables"
2
+
1
3
  require "heredity/version"
2
4
 
3
5
  module Heredity
6
+ def self.included(klass)
7
+ klass.__send__(:include, ::Heredity::InheritableClassInstanceVariables)
8
+ end
4
9
  end
@@ -1,11 +1,10 @@
1
1
  require 'spec_helper'
2
- require 'heredity/inheritable_class_instance_variables'
3
2
 
4
3
  describe Heredity::InheritableClassInstanceVariables do
5
4
 
6
5
  class TestInheritTop
7
6
  include ::Heredity::InheritableClassInstanceVariables
8
- inheritable_attributes :first, :awesomeness, :bestest
7
+ inheritable_attributes :first, :awesomeness, :bestest
9
8
 
10
9
  @first = {}
11
10
  @awesomeness = [:this, :that, :the_other]
@@ -16,7 +15,7 @@ describe Heredity::InheritableClassInstanceVariables do
16
15
  class TestThirdTier < TestSecondTier; end
17
16
 
18
17
  class TestEditSecondTier < TestInheritTop
19
- @first = "Songs are for Singing"
18
+ @first = "Songs are for Singing"
20
19
  @awesomeness = @first * 3
21
20
  @bestest = "SSSSSOOOOOOOOOONNNNNNNNGGGGGGGSSSSSS"
22
21
  end
@@ -37,25 +36,32 @@ describe Heredity::InheritableClassInstanceVariables do
37
36
  specify { test_class.should respond_to(:class_inheritable_attribute) }
38
37
  end
39
38
 
40
- context "when overiding child class instance varialbes" do
41
- describe "single tier inheritance" do
42
- it "overrides the instance variables with the child defined values" do
39
+ context "when inheritable class instance variables is already included" do
40
+ it "doesn't reset inheritable attributes" do
41
+ TestInheritTop.__send__(:include, ::Heredity::InheritableClassInstanceVariables)
42
+ TestInheritTop.inheritable_attributes.should include :first, :awesomeness, :bestest
43
+ end
44
+ end
45
+
46
+ context "when overriding child class instance variables" do
47
+ describe "single tier inheritance" do
48
+ it "overrides the instance variables with the child defined values" do
43
49
  TestEditSecondTier.first.should eq("Songs are for Singing")
44
50
  TestEditSecondTier.awesomeness.should eq("Songs are for Singing" * 3)
45
51
  TestEditSecondTier.bestest.should eq("SSSSSOOOOOOOOOONNNNNNNNGGGGGGGSSSSSS")
46
52
  end
47
53
  end
48
54
 
49
- describe "second tier inheritance" do
50
- it "overrides the instance variables with the child defined values" do
55
+ describe "second tier inheritance" do
56
+ it "overrides the instance variables with the child defined values" do
51
57
  TestEditThirdTier.first.should eq([])
52
58
  TestEditThirdTier.awesomeness.should eq([])
53
59
  TestEditThirdTier.bestest.should eq([])
54
60
  end
55
61
  end
56
62
 
57
- describe "second tier inheritance without changing first override" do
58
- it "keeps instance variables the same as first override" do
63
+ describe "second tier inheritance without changing first override" do
64
+ it "keeps instance variables the same as first override" do
59
65
  TestEditThirdTierWithoutEdit.first.should eq("Songs are for Singing")
60
66
  TestEditThirdTierWithoutEdit.awesomeness.should eq("Songs are for Singing" * 3)
61
67
  TestEditThirdTierWithoutEdit.bestest.should eq("SSSSSOOOOOOOOOONNNNNNNNGGGGGGGSSSSSS")
@@ -63,46 +69,46 @@ describe Heredity::InheritableClassInstanceVariables do
63
69
  end
64
70
  end
65
71
 
66
- context "without overriding inherited values" do
67
- describe "single tier inheritance" do
72
+ context "without overriding inherited values" do
73
+ describe "single tier inheritance" do
68
74
 
69
- it "creates public attr_readers for inherited attributes" do
75
+ it "creates public attr_readers for inherited attributes" do
70
76
  TestSecondTier.should respond_to(:first)
71
77
  TestSecondTier.should respond_to(:awesomeness)
72
78
  TestSecondTier.should respond_to(:bestest)
73
79
  end
74
80
 
75
- it "inherits the values of hashes" do
81
+ it "inherits the values of hashes" do
76
82
  TestSecondTier.first.should eq({})
77
83
  end
78
84
 
79
- it "inherits the values of arrays" do
85
+ it "inherits the values of arrays" do
80
86
  TestSecondTier.awesomeness.should eq([:this, :that, :the_other])
81
87
  end
82
88
 
83
- it "inherits the values of Objects" do
89
+ it "inherits the values of Objects" do
84
90
  TestSecondTier.bestest.should eq("dirt apple (Po-ta-toes!)")
85
91
  end
86
92
 
87
93
  end
88
94
 
89
- describe "2nd tier inheritance" do
95
+ describe "2nd tier inheritance" do
90
96
 
91
- it "creates public attr_readers for inherited attributes" do
97
+ it "creates public attr_readers for inherited attributes" do
92
98
  TestThirdTier.should respond_to(:first)
93
99
  TestThirdTier.should respond_to(:awesomeness)
94
100
  TestThirdTier.should respond_to(:bestest)
95
101
  end
96
102
 
97
- it "inherits the values of hashes" do
103
+ it "inherits the values of hashes" do
98
104
  TestThirdTier.first.should eq({})
99
105
  end
100
106
 
101
- it "inherits the values of arrays" do
107
+ it "inherits the values of arrays" do
102
108
  TestThirdTier.awesomeness.should eq([:this, :that, :the_other])
103
109
  end
104
110
 
105
- it "inherits the values of Objects" do
111
+ it "inherits the values of Objects" do
106
112
  TestThirdTier.bestest.should eq("dirt apple (Po-ta-toes!)")
107
113
  end
108
114
 
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Heredity do
4
+ class HeredityTestClass
5
+ include Heredity
6
+ end
7
+
8
+ context "when included" do
9
+ it "includes the InhertiableClassInstanceVariables module" do
10
+ HeredityTestClass.should respond_to :inheritable_attributes
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heredity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -107,7 +107,8 @@ files:
107
107
  - lib/heredity.rb
108
108
  - lib/heredity/inheritable_class_instance_variables.rb
109
109
  - lib/heredity/version.rb
110
- - spec/inheritable_class_instance_variables_spec.rb
110
+ - spec/heredity/inheritable_class_instance_variables_spec.rb
111
+ - spec/heredity_spec.rb
111
112
  - spec/spec_helper.rb
112
113
  homepage: ''
113
114
  licenses: []
@@ -123,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
124
  version: '0'
124
125
  segments:
125
126
  - 0
126
- hash: 478611459433060419
127
+ hash: 123508446309984082
127
128
  required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  none: false
129
130
  requirements:
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  version: '0'
133
134
  segments:
134
135
  - 0
135
- hash: 478611459433060419
136
+ hash: 123508446309984082
136
137
  requirements: []
137
138
  rubyforge_project:
138
139
  rubygems_version: 1.8.24
@@ -140,5 +141,6 @@ signing_key:
140
141
  specification_version: 3
141
142
  summary: inherit class instance variables
142
143
  test_files:
143
- - spec/inheritable_class_instance_variables_spec.rb
144
+ - spec/heredity/inheritable_class_instance_variables_spec.rb
145
+ - spec/heredity_spec.rb
144
146
  - spec/spec_helper.rb