Skip to content
This repository
Browse code

Make it work with Rails ~> 3.0

  • Loading branch information...
commit 5f3fb01a9d5f5adb17665a3bdabffd396d722e61 1 parent 1dd107b
Piotr Solnica authored January 31, 2012
5  Gemfile
@@ -9,7 +9,6 @@ REPO_POSTFIX   = SOURCE == :path ? ''                                : '.git'
9 9
 DATAMAPPER     = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
10 10
 DM_VERSION     = '~> 1.3.0.beta'
11 11
 DO_VERSION     = '~> 0.10.6'
12  
-RAILS_VERSION  = '~> 3.1.0'
13 12
 DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
14 13
 CURRENT_BRANCH = ENV.fetch('GIT_BRANCH', 'master')
15 14
 
@@ -17,10 +16,6 @@ CURRENT_BRANCH = ENV.fetch('GIT_BRANCH', 'master')
17 16
 gem 'dm-core',         DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-core#{REPO_POSTFIX}", :branch => CURRENT_BRANCH
18 17
 gem 'dm-active_model', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-active_model#{REPO_POSTFIX}", :branch => CURRENT_BRANCH
19 18
 
20  
-# Rails dependencies
21  
-gem 'actionpack', RAILS_VERSION, :require => 'action_pack'
22  
-gem 'railties',   RAILS_VERSION, :require => 'rails'
23  
-
24 19
 platforms :mri_18 do
25 20
   group :quality do
26 21
 
4  dm-rails.gemspec
@@ -17,7 +17,9 @@ Gem::Specification.new do |gem|
17 17
   gem.version       = DataMapper::Rails::VERSION
18 18
 
19 19
   gem.add_runtime_dependency('dm-active_model', '~> 1.3.0.beta')
  20
+  gem.add_runtime_dependency('actionpack',      '~> 3.0')
  21
+  gem.add_runtime_dependency('railties',        '~> 3.0')
20 22
 
21 23
   gem.add_development_dependency('rake',      '~> 0.9.2')
22 24
   gem.add_development_dependency('rspec',     '~> 1.3.2')
23  
-end
  25
+end
6  lib/dm-rails/mass_assignment_security.rb
@@ -8,17 +8,17 @@ module MassAssignmentSecurity
8 8
     # Provides a patched version of the Sanitizer used in Rails to handle property
9 9
     # and relationship objects as keys. There is no way to inject a custom sanitizer
10 10
     # without reimplementing the permission sets.
11  
-    module Sanitizer
  11
+    Sanitizer.send(Sanitizer.is_a?(Module) ? :module_eval : :class_eval) do
12 12
       # Returns all attributes not denied by the authorizer.
13 13
       #
14 14
       # @param [Hash{Symbol,String,::DataMapper::Property,::DataMapper::Relationship=>Object}] attributes
15 15
       #   Names and values of attributes to sanitize.
16 16
       # @return [Hash]
17 17
       #   Sanitized hash of attributes.
18  
-      def sanitize(attributes)
  18
+      def sanitize(attributes, authorizer = nil)
19 19
         sanitized_attributes = attributes.reject do |key, value|
20 20
           key_name = key.name rescue key
21  
-          deny?(key_name)
  21
+          authorizer ? authorizer.deny?(key_name) : deny?(key_name)
22 22
         end
23 23
         debug_protected_attribute_removal(attributes, sanitized_attributes)
24 24
         sanitized_attributes

1 note on commit 5f3fb01

Christoph Geschwind

Is railties ~> 3.0 really correct?
I'm using railties ~> 3.2 in my project and therefore can't use dm-rails..

Maybe you meant railties >= 3.0 ?

Postmodern

Wouldn't just module_eval work here?

Please sign in to comment.
Something went wrong with that request. Please try again.