multiple_table_inheritance 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ 0.2.1
2
+
3
+ * Ensure the subtype value is always set to the child class name even when a
4
+ new record is being built.
5
+
1
6
  0.2.0
2
7
 
3
8
  * Child model records can now inherit parent model methods via the :methods
data/README.md CHANGED
@@ -25,7 +25,7 @@ From the command line:
25
25
 
26
26
  From your Gemfile:
27
27
 
28
- gem 'multiple_table_inheritance', '~> 0.2.0'
28
+ gem 'multiple_table_inheritance', '~> 0.2.1'
29
29
 
30
30
  Usage
31
31
  =====
@@ -25,15 +25,11 @@ module MultipleTableInheritance
25
25
  self.parent_association_name = association_name.to_sym
26
26
  self.primary_key = "#{parent_association_name}_id"
27
27
 
28
- # Ensure parent association is always returned.
29
- define_method("#{parent_association_name}_with_autobuild") do
30
- send("#{parent_association_name}_without_autobuild") || send("build_#{parent_association_name}")
31
- end
28
+ define_parent_association_builder
32
29
 
33
30
  # Bind relationship, handle validation, and save properly.
34
31
  belongs_to parent_association_name, options
35
32
  alias_method_chain parent_association_name, :autobuild
36
- before_validation :set_association_subtype
37
33
  validate :parent_association_must_be_valid
38
34
  before_save :parent_association_must_be_saved
39
35
  end
@@ -47,6 +43,17 @@ module MultipleTableInheritance
47
43
 
48
44
  private
49
45
 
46
+ def define_parent_association_builder
47
+ subtype_column = parent_association_class.subtype_column
48
+ define_method("#{parent_association_name}_with_autobuild") do
49
+ unless association = send("#{parent_association_name}_without_autobuild")
50
+ association = send("build_#{parent_association_name}")
51
+ association.send("#{subtype_column}=", self.class.to_s)
52
+ end
53
+ association
54
+ end
55
+ end
56
+
50
57
  def inherited_columns_and_associations
51
58
  # Get the associated columns and relationship names
52
59
  inherited_columns = parent_association_class.column_names - column_names
@@ -129,13 +136,6 @@ module MultipleTableInheritance
129
136
  send("#{parent_association_name}=", record)
130
137
  end
131
138
 
132
- def set_association_subtype
133
- association = parent_association
134
- if association.attribute_names.include?(association.class.subtype_column)
135
- association[association.class.subtype_column] = self.class.to_s
136
- end
137
- end
138
-
139
139
  def parent_association_must_be_valid
140
140
  association = parent_association
141
141
 
@@ -1,3 +1,3 @@
1
1
  module MultipleTableInheritance
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiple_table_inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-31 00:00:00.000000000Z
12
+ date: 2012-04-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2152938260 !ruby/object:Gem::Requirement
16
+ requirement: &2152995060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152938260
24
+ version_requirements: *2152995060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2152937760 !ruby/object:Gem::Requirement
27
+ requirement: &2152994600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152937760
35
+ version_requirements: *2152994600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &2152937240 !ruby/object:Gem::Requirement
38
+ requirement: &2152994060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.8.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152937240
46
+ version_requirements: *2152994060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec_tag_matchers
49
- requirement: &2152936760 !ruby/object:Gem::Requirement
49
+ requirement: &2152993380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152936760
57
+ version_requirements: *2152993380
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3-ruby
60
- requirement: &2152936300 !ruby/object:Gem::Requirement
60
+ requirement: &2152992060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.3.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2152936300
68
+ version_requirements: *2152992060
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: database_cleaner
71
- requirement: &2152935840 !ruby/object:Gem::Requirement
71
+ requirement: &2152991520 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 0.7.1
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2152935840
79
+ version_requirements: *2152991520
80
80
  description: ActiveRecord plugin designed to allow simple multiple table inheritance.
81
81
  email:
82
82
  - matt@matthuggins.com