dm-sanitizer 0.1.1 → 0.1.4

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.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg
2
+ pkg/*
3
+ doc
4
+ coverage
5
+ */coverage
6
+ *.db
data/History.txt CHANGED
@@ -1,3 +1,17 @@
1
+ == 0.1.4 2010-08-28
2
+ * 1 enhancement
3
+ * integrated with jeweler
4
+
5
+ == 0.1.3 2009-11-10
6
+
7
+ * 1 bug fix
8
+ * Changes to meet dm-core 0.10.1 requirements
9
+
10
+ == 0.1.2 2009-06-03
11
+
12
+ * 1 enhancement
13
+ * Sanitize dirty properties if you want (:with_dirty => true)
14
+
1
15
  == 0.1.1 2009-06-01
2
16
 
3
17
  * 2 enhancements
@@ -78,21 +78,4 @@ sudo gem install dm-sanitizer
78
78
 
79
79
  Copyright (c) 2009 Sergei Zimakov
80
80
 
81
- Permission is hereby granted, free of charge, to any person obtaining
82
- a copy of this software and associated documentation files (the
83
- 'Software'), to deal in the Software without restriction, including
84
- without limitation the rights to use, copy, modify, merge, publish,
85
- distribute, sublicense, and/or sell copies of the Software, and to
86
- permit persons to whom the Software is furnished to do so, subject to
87
- the following conditions:
88
-
89
- The above copyright notice and this permission notice shall be
90
- included in all copies or substantial portions of the Software.
91
-
92
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
93
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
94
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
95
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
96
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
97
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
98
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81
+ See LICENSE for details.
data/Rakefile CHANGED
@@ -2,80 +2,39 @@ require 'pathname'
2
2
  require 'rubygems'
3
3
  require 'rake'
4
4
  require "rake/clean"
5
- require "rake/gempackagetask"
6
5
 
7
- ROOT = Pathname(__FILE__).dirname.expand_path
8
- JRUBY = RUBY_PLATFORM =~ /java/
9
- WINDOWS = Gem.win_platform?
10
- SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
6
+ begin
7
+ gem 'jeweler', '~> 1.4'
8
+ require 'jeweler'
11
9
 
12
- require ROOT + 'lib/dm-sanitizer/version'
10
+ Jeweler::Tasks.new do |gem|
11
+ gem.name = 'dm-sanitizer'
12
+ gem.summary = 'DataMapper plugin for automated/configurable user input sanitization.'
13
+ gem.description = 'DataMapper plugin for automated/configurable user input sanitization.'
14
+ gem.email = 'zimakov@gmail.com'
15
+ gem.homepage = "http://github.com/pat/dm-sanitizer/tree/master/"
16
+ gem.authors = [ 'Sergei Zimakov' ]
13
17
 
14
- AUTHOR = 'Sergei Zimakov'
15
- EMAIL = 'zimakov@gmail.com'
16
- GEM_NAME = 'dm-sanitizer'
17
- GEM_VERSION = DataMapper::Sanitizer::VERSION
18
- GEM_DEPENDENCIES = [['dm-core', '>= 0.9.4'], ['sanitize', '>= 1.0.0']]
19
- GEM_CLEAN = %w[ log pkg coverage ]
20
- GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE History.txt ] }
18
+ gem.rubyforge_project = 'dm-sanitizer'
21
19
 
22
- PROJECT_NAME = 'dm-sanitizer'
23
- PROJECT_URL = "http://github.com/pat/#{GEM_NAME}/tree/master/"
24
- PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin for automated/configurable user input sanitization.'
20
+ gem.add_dependency 'dm-core', '>= 0.10.1'
21
+ gem.add_dependency 'sanitize', '>= 1.0.0'
25
22
 
26
- [ ROOT ].each do |dir|
27
- Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
28
- end
29
- #
30
- # spec = Gem::Specification.new do |s|
31
- # s.name = GEM_NAME
32
- # s.version = GEM_VERSION
33
- # s.platform = Gem::Platform::RUBY
34
- # s.author = AUTHOR
35
- # s.email = EMAIL
36
- # s.homepage = PROJECT_URL
37
- # s.summary = PROJECT_SUMMARY
38
- # s.description = PROJECT_DESCRIPTION
39
- # s.require_path = 'lib'
40
- # s.files = %w[ LICENSE README.txt Rakefile History.txt TODO ] + Dir['lib/**/*'] + Dir['spec/**/*']
41
- # s.rubyforge_project = GEM_NAME
42
- #
43
- # # rdoc
44
- # s.has_rdoc = false
45
- # s.extra_rdoc_files = %w[ LICENSE README.txt History.txt ]
46
- #
47
- # # Dependencies
48
- # GEM_DEPENDENCIES.each {|dep| s.add_dependency( dep[0], dep[1] )}
49
- # end
50
- #
51
- # Rake::GemPackageTask.new(spec) do |package|
52
- # package.gem_spec = spec
53
- # end
54
- #
55
- # Specs
23
+ gem.add_development_dependency 'rspec', '~> 1.3'
24
+ gem.add_development_dependency 'jeweler', '~> 1.4'
25
+ end
56
26
 
57
- begin
58
- gem 'rspec', '~>1.2'
59
- require 'spec'
60
- require 'spec/rake/spectask'
27
+ Jeweler::GemcutterTasks.new
61
28
 
62
- task :default => [ :spec ]
29
+ FileList['tasks/**/*.rake'].each { |task| import task }
63
30
 
64
- desc 'Run specifications'
65
- Spec::Rake::SpecTask.new(:spec) do |t|
66
- t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
67
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
31
+ rescue LoadError => e
32
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
33
+ puts '-----------------------------------------------------------------------------'
34
+ puts e.backtrace # Let's help by actually showing *which* dependency is missing
35
+ end
68
36
 
69
- begin
70
- gem 'rcov', '~>0.8'
71
- t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
72
- t.rcov_opts << '--exclude' << 'spec'
73
- t.rcov_opts << '--text-summary'
74
- t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
75
- rescue LoadError
76
- # rcov not installed
77
- end
78
- end
79
- rescue LoadError
80
- # rspec not installed
81
- end
37
+ gem 'rspec', '~>1.3'
38
+ require 'spec'
39
+ require 'spec/rake/spectask'
40
+ Spec::Rake::SpecTask.new(:spec)
data/TODO CHANGED
@@ -4,5 +4,4 @@ TODO list
4
4
  * add options for before :valid? hooking
5
5
  * add options for redefining properties filtering method
6
6
  * add spec heplers for testing property sanitization options
7
- * add possibility for sanitizing dirty properties
8
7
  * validate options
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.4
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dm-sanitizer}
8
+ s.version = "0.1.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sergei Zimakov"]
12
+ s.date = %q{2010-08-28}
13
+ s.description = %q{DataMapper plugin for automated/configurable user input sanitization.}
14
+ s.email = %q{zimakov@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc",
18
+ "TODO"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "History.txt",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "TODO",
27
+ "VERSION",
28
+ "dm-sanitizer.gemspec",
29
+ "lib/dm-sanitizer.rb",
30
+ "spec/dm-sanitizer_spec.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/pat/dm-sanitizer/tree/master/}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubyforge_project = %q{dm-sanitizer}
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{DataMapper plugin for automated/configurable user input sanitization.}
40
+ s.test_files = [
41
+ "spec/dm-sanitizer_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<dm-core>, [">= 0.10.1"])
51
+ s.add_runtime_dependency(%q<sanitize>, [">= 1.0.0"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 1.3"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.4"])
54
+ else
55
+ s.add_dependency(%q<dm-core>, [">= 0.10.1"])
56
+ s.add_dependency(%q<sanitize>, [">= 1.0.0"])
57
+ s.add_dependency(%q<rspec>, ["~> 1.3"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.4"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<dm-core>, [">= 0.10.1"])
62
+ s.add_dependency(%q<sanitize>, [">= 1.0.0"])
63
+ s.add_dependency(%q<rspec>, ["~> 1.3"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.4"])
65
+ end
66
+ end
67
+
data/lib/dm-sanitizer.rb CHANGED
@@ -1,9 +1,6 @@
1
- require 'pathname'
2
1
  require 'rubygems'
3
2
 
4
- require Pathname(__FILE__).dirname.expand_path + 'dm-sanitizer/version'
5
-
6
- gem 'dm-core', '>= 0.9.4'
3
+ gem 'dm-core', '>= 0.10.1'
7
4
  require 'dm-core'
8
5
 
9
6
  gem 'sanitize', '>= 1.0.0'
@@ -19,7 +16,8 @@ module DataMapper
19
16
  :basic => Sanitize::Config::BASIC,
20
17
  :relaxed => Sanitize::Config::RELAXED
21
18
  },
22
- :default_mode => :default
19
+ :default_mode => :default,
20
+ :with_dirty => false
23
21
  }
24
22
  end
25
23
  module_function :default_options
@@ -44,7 +42,7 @@ module DataMapper
44
42
  remap_sanitization_modes!
45
43
  check_sanitization_modes
46
44
 
47
- before :save, :sanitize! unless hooks_with_scope(:instance)[:save][:before].include?({:name => :sanitize!, :from => self})
45
+ before :save, :sanitize! unless hooks_with_scope(:instance)[:update_hook][:before].include?({:name => :sanitize!, :from => self})
48
46
  end
49
47
 
50
48
  def disable_sanitization
@@ -82,7 +80,7 @@ module DataMapper
82
80
  property_name = property.name.to_sym
83
81
 
84
82
  next unless property.type == String || property.type == DataMapper::Types::Text
85
- next if !new_record? && !attribute_dirty?(property.name.to_sym)
83
+ next if !new? && !options[:with_dirty] && !attribute_dirty?(property.name.to_sym)
86
84
  next if options[:exclude] && options[:exclude].include?(property_name)
87
85
 
88
86
  property_mode = options[:modes] ? options[:modes][property_name] || options[:default_mode] : options[:default_mode]
@@ -108,4 +106,4 @@ module DataMapper
108
106
  end
109
107
  end
110
108
 
111
- DataMapper::Resource.append_inclusions DataMapper::Sanitizer
109
+ DataMapper::Model.append_inclusions DataMapper::Sanitizer
@@ -101,6 +101,15 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
101
101
  @object.title = 'Really new <strong>value</strong>'
102
102
  @object.save
103
103
  end
104
+
105
+ it "should_receive sanitize dirty properties if this option forced" do
106
+ @object.class.sanitize :with_dirty => true
107
+ @object.should_receive(:sanitize_property!).with(:title,anything).twice
108
+ @object.should_receive(:sanitize_property!).with(:story,anything).twice
109
+ @object.save
110
+ @object.title = 'Really new <strong>value</strong>'
111
+ @object.save
112
+ end
104
113
  end
105
114
 
106
115
  describe "DataMapper::Model sanitize_property! method" do
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'pathname'
2
2
  require 'rubygems'
3
3
 
4
- gem 'rspec', '~>1.2'
4
+ gem 'rspec', '~>1.3'
5
5
  require 'spec'
6
6
 
7
- gem 'dm-core', '>= 0.9.4'
7
+ gem 'dm-core', '= 0.10.1'
8
8
  require 'dm-core'
9
9
 
10
10
  gem 'sanitize', '>= 1.0.0'
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 4
10
+ version: 0.1.4
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sergei Zimakov
@@ -9,79 +15,128 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-06-02 00:00:00 +04:00
18
+ date: 2010-08-28 00:00:00 +04:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: dm-core
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
23
- version: 0.9.4
24
- version:
29
+ hash: 53
30
+ segments:
31
+ - 0
32
+ - 10
33
+ - 1
34
+ version: 0.10.1
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: sanitize
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
33
50
  version: 1.0.0
34
- version:
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 9
62
+ segments:
63
+ - 1
64
+ - 3
65
+ version: "1.3"
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: jeweler
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 7
77
+ segments:
78
+ - 1
79
+ - 4
80
+ version: "1.4"
81
+ type: :development
82
+ version_requirements: *id004
35
83
  description: DataMapper plugin for automated/configurable user input sanitization.
36
- email:
37
- - zimakov@gmail.com
84
+ email: zimakov@gmail.com
38
85
  executables: []
39
86
 
40
87
  extensions: []
41
88
 
42
89
  extra_rdoc_files:
43
- - README.txt
44
90
  - LICENSE
45
- - History.txt
91
+ - README.rdoc
92
+ - TODO
46
93
  files:
94
+ - .gitignore
47
95
  - History.txt
48
96
  - LICENSE
49
- - Manifest.txt
97
+ - README.rdoc
50
98
  - Rakefile
51
- - README.txt
52
99
  - TODO
100
+ - VERSION
101
+ - dm-sanitizer.gemspec
53
102
  - lib/dm-sanitizer.rb
54
- - lib/dm-sanitizer/version.rb
55
103
  - spec/dm-sanitizer_spec.rb
56
104
  - spec/spec.opts
57
105
  - spec/spec_helper.rb
58
- - tasks/hoe.rb
59
106
  has_rdoc: true
60
107
  homepage: http://github.com/pat/dm-sanitizer/tree/master/
108
+ licenses: []
109
+
61
110
  post_install_message:
62
111
  rdoc_options:
63
- - --main
64
- - README.txt
112
+ - --charset=UTF-8
65
113
  require_paths:
66
114
  - lib
67
115
  required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
68
117
  requirements:
69
118
  - - ">="
70
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
71
123
  version: "0"
72
- version:
73
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
74
126
  requirements:
75
127
  - - ">="
76
128
  - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
77
132
  version: "0"
78
- version:
79
133
  requirements: []
80
134
 
81
135
  rubyforge_project: dm-sanitizer
82
- rubygems_version: 1.3.1
136
+ rubygems_version: 1.3.7
83
137
  signing_key:
84
- specification_version: 2
138
+ specification_version: 3
85
139
  summary: DataMapper plugin for automated/configurable user input sanitization.
86
- test_files: []
87
-
140
+ test_files:
141
+ - spec/dm-sanitizer_spec.rb
142
+ - spec/spec_helper.rb
data/Manifest.txt DELETED
@@ -1,12 +0,0 @@
1
- History.txt
2
- LICENSE
3
- Manifest.txt
4
- Rakefile
5
- README.txt
6
- TODO
7
- lib/dm-sanitizer.rb
8
- lib/dm-sanitizer/version.rb
9
- spec/dm-sanitizer_spec.rb
10
- spec/spec.opts
11
- spec/spec_helper.rb
12
- tasks/hoe.rb
@@ -1,5 +0,0 @@
1
- module DataMapper
2
- module Sanitizer
3
- VERSION = '0.1.1'
4
- end
5
- end
data/tasks/hoe.rb DELETED
@@ -1,46 +0,0 @@
1
- require 'hoe'
2
-
3
- @config_file = "~/.rubyforge/user-config.yml"
4
- @config = nil
5
- RUBYFORGE_USERNAME = "unknown"
6
- def rubyforge_username
7
- unless @config
8
- begin
9
- @config = YAML.load(File.read(File.expand_path(@config_file)))
10
- rescue
11
- puts <<-EOS
12
- ERROR: No rubyforge config file found: #{@config_file}
13
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
14
- - See http://newgem.rubyforge.org/rubyforge.html for more details
15
- EOS
16
- exit
17
- end
18
- end
19
- RUBYFORGE_USERNAME.replace @config["username"]
20
- end
21
-
22
- # Remove hoe dependency
23
- class Hoe
24
- def extra_dev_deps
25
- @extra_dev_deps.reject! { |dep| dep[0] == "hoe" }
26
- @extra_dev_deps
27
- end
28
- end
29
-
30
- hoe = Hoe.new(GEM_NAME, GEM_VERSION) do |p|
31
-
32
- p.developer(AUTHOR, EMAIL)
33
-
34
- p.description = PROJECT_DESCRIPTION
35
- p.summary = PROJECT_SUMMARY
36
- p.url = PROJECT_URL
37
-
38
- p.rubyforge_name = PROJECT_NAME if PROJECT_NAME
39
- p.clean_globs |= GEM_CLEAN
40
- p.spec_extras = GEM_EXTRAS if GEM_EXTRAS
41
-
42
- GEM_DEPENDENCIES.each do |dep|
43
- p.extra_deps << dep
44
- end
45
-
46
- end