heredity 0.0.1 → 0.0.2

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.
@@ -0,0 +1,60 @@
1
+ require 'thread'
2
+
3
+ module Heredity
4
+ module InheritableClassInstanceVariables
5
+ def self.included(klass)
6
+ Thread.exclusive do
7
+ klass.extend(::Heredity::InheritableClassInstanceVariables::ClassMethods)
8
+
9
+ klass.class_eval do
10
+ @_inheritable_class_instance_variables = [ :_inheritable_class_instance_variables ]
11
+
12
+ class << self
13
+ alias_method :inheritable_attribute, :inheritable_attributes
14
+ alias_method :class_inheritable_attributes, :inheritable_attributes
15
+ alias_method :class_inheritable_attribute, :inheritable_attributes
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+ def inheritable_attributes(*args)
23
+ Thread.exclusive do
24
+ args.flatten.compact.uniq.each do |class_instance_variable|
25
+ unless @_inheritable_class_instance_variables.include?(class_instance_variable)
26
+ @_inheritable_class_instance_variables << class_instance_variable
27
+ end
28
+ end
29
+
30
+ @_inheritable_class_instance_variables.each do |attr_symbol|
31
+ unless self.respond_to?("#{attr_symbol}")
32
+ class_eval %Q{
33
+ class << self; attr_reader :#{attr_symbol}; end
34
+ }
35
+ end
36
+
37
+ unless self.respond_to?("#{attr_symbol}=")
38
+ class_eval %Q{
39
+ class << self; attr_writer :#{attr_symbol}; end
40
+ }
41
+ end
42
+ end
43
+
44
+ @_inheritable_class_instance_variables
45
+ end
46
+ end
47
+
48
+ def inherited(klass)
49
+ super # ActiveRecord needs the inherited hook to setup fields
50
+
51
+ Thread.exclusive do
52
+ @_inheritable_class_instance_variables.each do |attribute|
53
+ attr_sym = :"@#{attribute}"
54
+ klass.instance_variable_set(attr_sym, self.instance_variable_get(attr_sym))
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module Heredity
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/heredity.rb CHANGED
@@ -1,61 +1,4 @@
1
- require 'thread'
2
1
  require "heredity/version"
3
2
 
4
3
  module Heredity
5
- module InheritableClassInstanceVariables
6
- def self.included(klass)
7
- Thread.exclusive do
8
- klass.extend(::Heredity::InheritableClassInstanceVariables::ClassMethods)
9
-
10
- klass.class_eval do
11
- @_inheritable_class_instance_variables = [ :_inheritable_class_instance_variables ]
12
-
13
- class << self
14
- alias_method :inheritable_attribute, :inheritable_attributes
15
- alias_method :class_inheritable_attributes, :inheritable_attributes
16
- alias_method :class_inheritable_attribute, :inheritable_attributes
17
- end
18
- end
19
- end
20
- end
21
-
22
- module ClassMethods
23
- def inheritable_attributes(*args)
24
- Thread.exclusive do
25
- args.flatten.compact.uniq.each do |class_instance_variable|
26
- unless @_inheritable_class_instance_variables.include?(class_instance_variable)
27
- @_inheritable_class_instance_variables << class_instance_variable
28
- end
29
- end
30
-
31
- @_inheritable_class_instance_variables.each do |attr_symbol|
32
- unless self.respond_to?("#{attr_symbol}")
33
- class_eval %Q{
34
- class << self; attr_reader :#{attr_symbol}; end
35
- }
36
- end
37
-
38
- unless self.respond_to?("#{attr_symbol}=")
39
- class_eval %Q{
40
- class << self; attr_writer :#{attr_symbol}; end
41
- }
42
- end
43
- end
44
-
45
- @_inheritable_class_instance_variables
46
- end
47
- end
48
-
49
- def inherited(klass)
50
- super # ActiveRecord needs the inherited hook to setup fields
51
-
52
- Thread.exclusive do
53
- @_inheritable_class_instance_variables.each do |attribute|
54
- attr_sym = :"@#{attribute}"
55
- klass.instance_variable_set(attr_sym, self.instance_variable_get(attr_sym))
56
- end
57
- end
58
- end
59
- end
60
- end
61
4
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'heredity/inheritable_class_instance_variables'
2
3
 
3
4
  describe Heredity::InheritableClassInstanceVariables do
4
5
 
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.1
4
+ version: 0.0.2
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-08 00:00:00.000000000 Z
12
+ date: 2012-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -105,6 +105,7 @@ files:
105
105
  - Rakefile
106
106
  - heredity.gemspec
107
107
  - lib/heredity.rb
108
+ - lib/heredity/inheritable_class_instance_variables.rb
108
109
  - lib/heredity/version.rb
109
110
  - spec/inheritable_class_instance_variables_spec.rb
110
111
  - spec/spec_helper.rb
@@ -122,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
123
  version: '0'
123
124
  segments:
124
125
  - 0
125
- hash: -1738474534293620341
126
+ hash: 478611459433060419
126
127
  required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  none: false
128
129
  requirements:
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  version: '0'
132
133
  segments:
133
134
  - 0
134
- hash: -1738474534293620341
135
+ hash: 478611459433060419
135
136
  requirements: []
136
137
  rubyforge_project:
137
138
  rubygems_version: 1.8.24