multiple_table_inheritance 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ 0.1.8
2
+
3
+ * Child model records can now inherit parent model methods via the :methods
4
+ option when calling :inherits_from.
5
+ * Added several unit tests.
6
+
7
+ 0.1.7
8
+
9
+ * Fix bug caused by extraneous super call in sanitizer class.
10
+
11
+ 0.1.6
12
+
13
+ * Fix issue with mass assignment sanitizer classes not being loaded
14
+ consistently across different versions of Rails 3.
15
+
1
16
  0.1.5
2
17
 
3
18
  * Fix issue with LoggerSanitizer not being defined in Rails projects.
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.1.5'
28
+ gem 'multiple_table_inheritance', '~> 0.1.7'
29
29
 
30
30
  Usage
31
31
  =====
@@ -254,5 +254,5 @@ option when calling `inherits_from`.
254
254
  @programmer.give_raise!
255
255
  # yields: "Congrats on your well-deserved raise, Mike!"
256
256
 
257
- NOTE: This is not fully implemented yet as of version 0.1.4. Please wait until
257
+ NOTE: This is not fully implemented yet as of version 0.1.7. Please wait until
258
258
  a future release to prior to using this feature.
@@ -39,9 +39,6 @@ module MultipleTableInheritance
39
39
  attr_accessible attr.to_sym
40
40
  end
41
41
 
42
- # Sanitize attributes across parent and child
43
- self.mass_assignment_sanitizer = Child::Sanitizer.new(self)
44
-
45
42
  # Bind relationship, handle validation, and save properly.
46
43
  belongs_to parent_association_name, options
47
44
  alias_method_chain parent_association_name, :autobuild
@@ -94,6 +91,12 @@ module MultipleTableInheritance
94
91
  end
95
92
 
96
93
  module InstanceMethods
94
+ protected
95
+
96
+ def sanitize_for_mass_assignment(attributes, role = :default)
97
+ Child::Sanitizer.new(self.class, role).sanitize(attributes)
98
+ end
99
+
97
100
  private
98
101
 
99
102
  def parent_association
@@ -1,14 +1,12 @@
1
- require 'activemodel/mass_assignment_security/sanitizer' unless defined?(ActiveModel::MassAssignmentSecurity::LoggerSanitizer)
2
-
3
1
  module MultipleTableInheritance
4
2
  module Child
5
- class Sanitizer < ActiveModel::MassAssignmentSecurity::LoggerSanitizer
6
- def initialize(target)
3
+ class Sanitizer
4
+ def initialize(target, role)
7
5
  @target = target
8
- super
6
+ @role = role
9
7
  end
10
8
 
11
- def sanitize(attributes, authorizer)
9
+ def sanitize(attributes)
12
10
  sanitized_attributes = attributes.reject { |key, value| deny?(key) }
13
11
  debug_protected_attribute_removal(attributes, sanitized_attributes)
14
12
  sanitized_attributes
@@ -16,6 +14,25 @@ module MultipleTableInheritance
16
14
 
17
15
  protected
18
16
 
17
+ def debug_protected_attribute_removal(attributes, sanitized_attributes)
18
+ removed_keys = attributes.keys - sanitized_attributes.keys
19
+ process_removed_attributes(removed_keys) if removed_keys.any?
20
+ end
21
+
22
+ private
23
+
24
+ def logger
25
+ @target.logger
26
+ end
27
+
28
+ def logger?
29
+ @target.respond_to?(:logger) && @target.logger
30
+ end
31
+
32
+ def process_removed_attributes(attrs)
33
+ logger.warn "Can't mass-assign protected attributes: #{attrs.join(', ')}" if logger?
34
+ end
35
+
19
36
  def deny?(key)
20
37
  return true if protected_attribute?(key)
21
38
  return !accessible_attribute?(key)
@@ -32,19 +49,27 @@ module MultipleTableInheritance
32
49
  end
33
50
 
34
51
  def protected_attributes
35
- @protected_attributes ||= (@target.protected_attributes + @target.parent_association_class.protected_attributes)
52
+ @protected_attributes ||= (protected_child_attributes + protected_parent_attributes)
36
53
  end
37
54
 
38
55
  def accessible_attributes
39
- @accessible_attributes ||= (@target.accessible_attributes + @target.parent_association_class.accessible_attributes)
56
+ @accessible_attributes ||= (accessible_child_attributes + accessible_parent_attributes)
57
+ end
58
+
59
+ def protected_child_attributes
60
+ @protected_child_attributes ||= @target.protected_attributes(@role)
61
+ end
62
+
63
+ def protected_parent_attributes
64
+ @protected_parent_attributes ||= @target.parent_association_class.protected_attributes(@role)
40
65
  end
41
66
 
42
67
  def accessible_child_attributes
43
- @accessible_child_attributes ||= @target.accessible_attributes
68
+ @accessible_child_attributes ||= @target.accessible_attributes(@role)
44
69
  end
45
70
 
46
71
  def accessible_parent_attributes
47
- @accessible_parent_attributes ||= @target.parent_association_class.accessible_attributes
72
+ @accessible_parent_attributes ||= @target.parent_association_class.accessible_attributes(@role)
48
73
  end
49
74
 
50
75
  def child_attribute_names
@@ -1,3 +1,3 @@
1
1
  module MultipleTableInheritance
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.7"
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.1.5
4
+ version: 0.1.7
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-14 00:00:00.000000000Z
12
+ date: 2012-03-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2153110840 !ruby/object:Gem::Requirement
16
+ requirement: &2153035620 !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: *2153110840
24
+ version_requirements: *2153035620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2153110260 !ruby/object:Gem::Requirement
27
+ requirement: &2153035040 !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: *2153110260
35
+ version_requirements: *2153035040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &2153109680 !ruby/object:Gem::Requirement
38
+ requirement: &2153034460 !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: *2153109680
46
+ version_requirements: *2153034460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec_tag_matchers
49
- requirement: &2153109160 !ruby/object:Gem::Requirement
49
+ requirement: &2153033940 !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: *2153109160
57
+ version_requirements: *2153033940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3-ruby
60
- requirement: &2153108700 !ruby/object:Gem::Requirement
60
+ requirement: &2153033420 !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: *2153108700
68
+ version_requirements: *2153033420
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: database_cleaner
71
- requirement: &2153108140 !ruby/object:Gem::Requirement
71
+ requirement: &2153032860 !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: *2153108140
79
+ version_requirements: *2153032860
80
80
  description: ActiveRecord plugin designed to allow simple multiple table inheritance.
81
81
  email:
82
82
  - matt@matthuggins.com