mm-sanitize 0.1.0

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.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +48 -0
  3. data/Rakefile +76 -0
  4. data/lib/mm-sanitize.rb +40 -0
  5. metadata +112 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Richard Livsey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = MongoMapper::Plugins::Sanitize
2
+
3
+ Tiny plugin for MongoMapper to sanitize strings before validation.
4
+
5
+ == Requires
6
+
7
+ * MongoMapper
8
+ * Sanitize
9
+
10
+ == Usage
11
+
12
+ Either load it into all models, or individual models:
13
+
14
+ # add to all models
15
+ MongoMapper::Document.append_inclusions(MongoMapper::Plugins::Sanitize)
16
+
17
+ # add to a specific model
18
+ plugin MongoMapper::Plugins::Sanitize
19
+
20
+ Once it's loaded into a model, configure with 'sanitize'
21
+
22
+ sanitize :list, :of, :keys
23
+
24
+ This will use the default Sanitize config, if you want to override then set the :config option:
25
+
26
+ # Use the built-in Sanitize::Config::RESTRICTED configuration
27
+ sanitize :title, :config => Sanitize::Config::RESTRICTED
28
+
29
+ # Use a custom configuration
30
+ sanitize :description, :config => {:elements => ['a', 'span']}
31
+
32
+ See the Sanitize Docs (https://github.com/rgrove/sanitize) for more details on the different configuration options.
33
+
34
+ == Note on Patches/Pull Requests
35
+
36
+ * Fork the project.
37
+ * Make your feature addition or bug fix.
38
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
39
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
40
+ * Send me a pull request. Bonus points for topic branches.
41
+
42
+ == Install
43
+
44
+ $ gem install mm-sanitize
45
+
46
+ == Copyright
47
+
48
+ See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,76 @@
1
+ require "rubygems"
2
+ require "rake/gempackagetask"
3
+ require "rake/rdoctask"
4
+
5
+ require "spec"
6
+ require "spec/rake/spectask"
7
+ Spec::Rake::SpecTask.new do |t|
8
+ t.spec_opts = %w(--format specdoc --colour)
9
+ t.libs = ["spec"]
10
+ end
11
+
12
+
13
+ task :default => ["spec"]
14
+
15
+ # This builds the actual gem. For details of what all these options
16
+ # mean, and other ones you can add, check the documentation here:
17
+ #
18
+ # http://rubygems.org/read/chapter/20
19
+ #
20
+ spec = Gem::Specification.new do |s|
21
+
22
+ # Change these as appropriate
23
+ s.name = "mm-sanitize"
24
+ s.version = "0.1.0"
25
+ s.summary = "Tiny plugin for MongoMapper to sanitize strings before validation."
26
+ s.author = "Richard Livsey"
27
+ s.email = "youremail@example.com"
28
+ s.homepage = "http://github.com/rlivsey/mm-sanitize"
29
+
30
+ s.has_rdoc = true
31
+ s.extra_rdoc_files = %w(README.rdoc)
32
+ s.rdoc_options = %w(--main README.rdoc)
33
+
34
+ # Add any extra files to include in the gem
35
+ s.files = %w(LICENSE Rakefile README.rdoc) + Dir.glob("{spec,lib/**/*}")
36
+ s.require_paths = ["lib"]
37
+
38
+ # If you want to depend on other gems, add them here, along with any
39
+ # relevant versions
40
+ s.add_dependency("mongo_mapper")
41
+ s.add_dependency("sanitize")
42
+
43
+ # If your tests use any gems, include them here
44
+ s.add_development_dependency("rspec")
45
+ end
46
+
47
+ # This task actually builds the gem. We also regenerate a static
48
+ # .gemspec file, which is useful if something (i.e. GitHub) will
49
+ # be automatically building a gem for this project. If you're not
50
+ # using GitHub, edit as appropriate.
51
+ #
52
+ # To publish your gem online, install the 'gemcutter' gem; Read more
53
+ # about that here: http://gemcutter.org/pages/gem_docs
54
+ Rake::GemPackageTask.new(spec) do |pkg|
55
+ pkg.gem_spec = spec
56
+ end
57
+
58
+ desc "Build the gemspec file #{spec.name}.gemspec"
59
+ task :gemspec do
60
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
61
+ File.open(file, "w") {|f| f << spec.to_ruby }
62
+ end
63
+
64
+ task :package => :gemspec
65
+
66
+ # Generate documentation
67
+ Rake::RDocTask.new do |rd|
68
+ rd.main = "README.rdoc"
69
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
70
+ rd.rdoc_dir = "rdoc"
71
+ end
72
+
73
+ desc 'Clear out RDoc and generated packages'
74
+ task :clean => [:clobber_rdoc, :clobber_package] do
75
+ rm "#{spec.name}.gemspec"
76
+ end
@@ -0,0 +1,40 @@
1
+ require 'mongo_mapper'
2
+ require 'sanitize'
3
+
4
+ module MongoMapper
5
+ module Plugins
6
+ module Sanitize
7
+ def self.included(model)
8
+ model.plugin self
9
+ end
10
+
11
+ def self.configure(base)
12
+ base.before_validation :sanitize_attributes
13
+ end
14
+
15
+ module ClassMethods
16
+ def sanitize(*keys)
17
+ options = keys.pop if keys.last.is_a?(Hash)
18
+ options ||= {}
19
+
20
+ @sanitize_keys ||= {}
21
+ keys.each do |key|
22
+ @sanitize_keys[key] = options[:config]
23
+ end
24
+ end
25
+
26
+ class_eval do
27
+ attr_reader :sanitize_keys
28
+ end
29
+ end
30
+
31
+ module InstanceMethods
32
+ def sanitize_attributes
33
+ self.class.sanitize_keys.each do |key, config|
34
+ self[key] = ::Sanitize.clean(self[key], config || {})
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mm-sanitize
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Richard Livsey
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-25 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: mongo_mapper
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: sanitize
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description:
64
+ email: youremail@example.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - README.rdoc
71
+ files:
72
+ - LICENSE
73
+ - Rakefile
74
+ - README.rdoc
75
+ - lib/mm-sanitize.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/rlivsey/mm-sanitize
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --main
83
+ - README.rdoc
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.3.7
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Tiny plugin for MongoMapper to sanitize strings before validation.
111
+ test_files: []
112
+