heredity 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/heredity/version.rb +1 -1
- data/lib/heredity.rb +28 -1
- data/spec/heredity_spec.rb +15 -1
- metadata +4 -4
data/lib/heredity/version.rb
CHANGED
data/lib/heredity.rb
CHANGED
@@ -4,6 +4,33 @@ require "heredity/version"
|
|
4
4
|
|
5
5
|
module Heredity
|
6
6
|
def self.included(klass)
|
7
|
-
klass.
|
7
|
+
klass.class_eval do
|
8
|
+
extend ::Heredity::ClassMethods
|
9
|
+
include ::Heredity::InheritableClassInstanceVariables
|
10
|
+
|
11
|
+
class << self
|
12
|
+
alias_method :inheritance_eval, :on_inherit
|
13
|
+
alias_method :inherited_eval, :on_inherit
|
14
|
+
alias_method :when_inherited, :on_inherit
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
def _heredity_inherited_hooks
|
21
|
+
@_heredity_inherited_hooks ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def inherited(klass)
|
25
|
+
super
|
26
|
+
|
27
|
+
_heredity_inherited_hooks.each do |block|
|
28
|
+
klass.class_eval(&block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_inherit(&block)
|
33
|
+
_heredity_inherited_hooks << block
|
34
|
+
end
|
8
35
|
end
|
9
36
|
end
|
data/spec/heredity_spec.rb
CHANGED
@@ -10,4 +10,18 @@ describe Heredity do
|
|
10
10
|
HeredityTestClass.should respond_to :inheritable_attributes
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
|
+
describe ".on_inherit" do
|
15
|
+
it "captures a block and eval's it when the class is inherited" do
|
16
|
+
HeredityTestClass.on_inherit do
|
17
|
+
def self.hello_world!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Child < HeredityTestClass
|
22
|
+
end
|
23
|
+
|
24
|
+
Child.should respond_to(:hello_world!)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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
|
4
|
+
version: 0.1.0
|
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:
|
12
|
+
date: 2013-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
segments:
|
126
126
|
- 0
|
127
|
-
hash:
|
127
|
+
hash: -1055722602779099653
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
version: '0'
|
134
134
|
segments:
|
135
135
|
- 0
|
136
|
-
hash:
|
136
|
+
hash: -1055722602779099653
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
139
|
rubygems_version: 1.8.24
|