diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4040c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.gem +.bundle +Gemfile.lock +pkg/* diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f28ea28 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in sanitize_attributes.gemspec +gemspec diff --git a/Rakefile b/Rakefile index 60c38ba..4fe65ba 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ require 'rake' require 'rake/testtask' require 'rake/rdoctask' +require 'bundler/gem_tasks' desc 'Default: run unit tests.' task :default => :test @@ -31,4 +32,4 @@ rescue LoadError task :rcov do abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" end -end \ No newline at end of file +end diff --git a/init.rb b/init.rb index ff0e67d..a4460fd 100644 --- a/init.rb +++ b/init.rb @@ -1,2 +1,2 @@ require 'sanitize_attributes' -ActiveRecord::Base.class_eval { extend SanitizeAttributes } \ No newline at end of file +SanitizeAttributes.hook! diff --git a/lib/sanitize_attributes.rb b/lib/sanitize_attributes.rb index ac4d59d..f906edd 100644 --- a/lib/sanitize_attributes.rb +++ b/lib/sanitize_attributes.rb @@ -7,8 +7,18 @@ module SanitizeAttributes class << self attr_accessor :default_sanitization_method + + def hook! + ActiveSupport.on_load(:active_record) { extend SanitizeAttributes } + end end # Thrown when sanitize! is called without a defined sanitization method at the class or global level class NoSanitizationMethodDefined < StandardError ; end -end \ No newline at end of file + + if defined?(Rails) + class Railtie < Rails::Railtie + initializer("sanitize_attirbutes") { SanitizeAttributes.hook! } + end + end +end diff --git a/lib/sanitize_attributes/version.rb b/lib/sanitize_attributes/version.rb new file mode 100644 index 0000000..f09c75f --- /dev/null +++ b/lib/sanitize_attributes/version.rb @@ -0,0 +1,3 @@ +module SanitizeAttributes + VERSION = "0.0.1" +end diff --git a/sanitize_attributes.gemspec b/sanitize_attributes.gemspec new file mode 100644 index 0000000..45bf0b6 --- /dev/null +++ b/sanitize_attributes.gemspec @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "sanitize_attributes/version" + +Gem::Specification.new do |s| + s.name = "sanitize_attributes" + s.version = SanitizeAttributes::VERSION + s.authors = ["Dev Purkayastha", "Paul McMahon"] + s.email = ["dev@forgreatjustice.net"] + s.homepage = "https://github.com/devp/sanitize_attributes" + s.summary = %q{This is a simple plugin for ActiveRecord models to define sanitizable attributes.} + s.description = %q{This is a simple plugin for ActiveRecord models to define sanitizable attributes. When an object is saved, those attributes will be run through whatever filter you’ve defined. You can define a default filter for all sanitizations.} + + s.rubyforge_project = "sanitize_attributes" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] + + s.add_dependency 'rails', '>= 3.0.0' + s.add_development_dependency 'rake' + s.add_development_dependency 'sqlite3' + s.add_development_dependency 'thoughtbot-shoulda' + s.add_development_dependency 'mocha' +end diff --git a/test/test_helper.rb b/test/test_helper.rb index deea706..0a35bf7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,7 @@ require 'set' require 'rubygems' require 'active_record' -ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:") +ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") gem 'thoughtbot-shoulda' require 'shoulda' gem 'mocha' @@ -10,4 +10,4 @@ $:.unshift "#{File.dirname(__FILE__)}/../lib" -require "#{File.dirname(__FILE__)}/../init" \ No newline at end of file +require "#{File.dirname(__FILE__)}/../init"