Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to Rails 3, converted to RSpec, gemified.
- Loading branch information
Showing
22 changed files
with
248 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--colour | ||
--format nested | ||
--backtrace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
== [2010-10-15] 1.0.0 Major Updates | ||
|
||
* Finally updated to be a Gem | ||
* Internal refactoring | ||
* Converted tests to RSpec | ||
* Added support for Rails 3.0 | ||
|
||
== 0.1.2 Fixed issue with table not existing. | ||
== 0.1.0 Initial Version |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,23 @@ | ||
require 'rubygems' | ||
require 'echoe' | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
require 'spec/rake/spectask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the nilify_blanks plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
desc "Run specs" | ||
Spec::Rake::SpecTask.new do |t| | ||
t.spec_files = Rake::FileList["spec/**/*_spec.rb"] | ||
t.spec_opts = ["-c"] | ||
end | ||
|
||
desc 'Generate documentation for the nilify_blanks plugin.' | ||
task :default => :spec | ||
|
||
desc "Generate documentation for the plugin." | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'NilifyBlanks' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_dir = "rdoc" | ||
rdoc.title = "nilify_blanks" | ||
rdoc.options << "--line-numbers" << "--inline-source" | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
Echoe.new('nilify_blanks', '0.1.2') do |p| | ||
p.description = "Auto-convert blank fields to nil." | ||
p.url = "http://github.com/railsgarden/nilify_blanks" | ||
p.author = "Ben Hughes" | ||
p.email = "ben@railsgarden.com" | ||
p.ignore_pattern = ["tmp/*", "script/*"] | ||
p.development_dependencies = [] | ||
end | ||
|
||
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext } | ||
|
||
Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
require 'nilify_blanks' | ||
require "nilify_blanks" | ||
|
||
NilifyBlanks::Railtie.insert |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,48 @@ | ||
module Rubiety | ||
module NilifyBlanks | ||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
module ClassMethods | ||
def nilify_blanks(options = {}) | ||
return if self.included_modules.include?(NilifyBlanks::InstanceMethods) | ||
return unless self.table_exists? | ||
|
||
include NilifyBlanks::InstanceMethods | ||
|
||
if options[:only] | ||
options[:only] = [options[:only]] unless options[:only].is_a?(Array) | ||
options[:only] = options[:only].map(&:to_s) | ||
end | ||
|
||
if options[:except] | ||
options[:except] = [options[:except]] unless options[:except].is_a?(Array) | ||
options[:except] = options[:except].map(&:to_s) | ||
end | ||
|
||
cattr_accessor :nilify_blanks_columns | ||
|
||
self.nilify_blanks_columns = self.content_columns.reject {|c| !c.null }.map {|c| c.name.to_s } | ||
self.nilify_blanks_columns = self.nilify_blanks_columns.select {|c| options[:only].include?(c) } if options[:only] | ||
self.nilify_blanks_columns -= options[:except] if options[:except] | ||
self.nilify_blanks_columns = self.nilify_blanks_columns.map(&:to_s) | ||
|
||
options[:before] ||= :save | ||
class_eval "before_#{options[:before]} :nilify_blanks" | ||
module NilifyBlanks | ||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
module ClassMethods | ||
def nilify_blanks(options = {}) | ||
return if self.included_modules.include?(NilifyBlanks::InstanceMethods) | ||
return unless self.table_exists? | ||
|
||
include NilifyBlanks::InstanceMethods | ||
|
||
if options[:only] | ||
options[:only] = [options[:only]] unless options[:only].is_a?(Array) | ||
options[:only] = options[:only].map(&:to_s) | ||
end | ||
|
||
if options[:except] | ||
options[:except] = [options[:except]] unless options[:except].is_a?(Array) | ||
options[:except] = options[:except].map(&:to_s) | ||
end | ||
|
||
cattr_accessor :nilify_blanks_columns | ||
|
||
self.nilify_blanks_columns = self.content_columns.reject {|c| !c.null }.map {|c| c.name.to_s } | ||
self.nilify_blanks_columns = self.nilify_blanks_columns.select {|c| options[:only].include?(c) } if options[:only] | ||
self.nilify_blanks_columns -= options[:except] if options[:except] | ||
self.nilify_blanks_columns = self.nilify_blanks_columns.map(&:to_s) | ||
|
||
options[:before] ||= :save | ||
class_eval "before_#{options[:before]} :nilify_blanks" | ||
end | ||
module InstanceMethods | ||
def nilify_blanks | ||
(self.nilify_blanks_columns || []).each do |column| | ||
value = read_attribute(column) | ||
next unless value.is_a?(String) | ||
next unless value.nil? or !value.respond_to?(:blank) | ||
write_attribute(column, nil) if value.blank? | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def nilify_blanks | ||
(self.nilify_blanks_columns || []).each do |column| | ||
value = read_attribute(column) | ||
next unless value.is_a?(String) | ||
next unless value.nil? or !value.respond_to?(:blank) | ||
|
||
write_attribute(column, nil) if value.blank? | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Base.send(:include, Rubiety::NilifyBlanks) | ||
require "nilify_blanks/railtie" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module NilifyBlanks | ||
if defined?(Rails::Railtie) | ||
require "rails" | ||
|
||
class Railtie < Rails::Railtie | ||
initializer "nilify_blanks.extend_active_record" do | ||
ActiveSupport.on_load(:active_record) do | ||
NilifyBlanks::Railtie.insert | ||
end | ||
end | ||
end | ||
end | ||
|
||
class Railtie | ||
def self.insert | ||
ActiveRecord::Base.send(:include, NilifyBlanks) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module NilifyBlanks | ||
VERSION = "1.0.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "nilify_blanks/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = %q{nilify_blanks} | ||
s.version = "0.1.2" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Ben Hughes"] | ||
s.date = %q{2009-09-10} | ||
s.description = %q{Auto-convert blank fields to nil.} | ||
s.email = %q{ben@railsgarden.com} | ||
s.extra_rdoc_files = ["CHANGELOG", "lib/nilify_blanks.rb", "README.rdoc", "tasks/nilify_blanks_tasks.rake"] | ||
s.files = ["CHANGELOG", "init.rb", "install.rb", "lib/nilify_blanks.rb", "Manifest", "MIT-LICENSE", "nilify_blanks.gemspec", "nilify_blanks_plugin.sqlite3", "Rakefile", "README.rdoc", "tasks/nilify_blanks_tasks.rake", "test/config/database.yml", "test/nilify_blanks_plugin.sqlite3", "test/nilify_blanks_test.rb", "test/schema.rb", "test/test_helper.rb", "uninstall.rb"] | ||
s.homepage = %q{http://github.com/railsgarden/nilify_blanks} | ||
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nilify_blanks", "--main", "README.rdoc"] | ||
s.require_paths = ["lib"] | ||
s.rubyforge_project = %q{nilify_blanks} | ||
s.rubygems_version = %q{1.3.4} | ||
s.summary = %q{Auto-convert blank fields to nil.} | ||
s.test_files = ["test/nilify_blanks_test.rb", "test/test_helper.rb"] | ||
|
||
if s.respond_to? :specification_version then | ||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then | ||
else | ||
end | ||
else | ||
end | ||
s.name = "nilify_blanks" | ||
s.version = "1.0.0" | ||
s.author = "Ben Hughes" | ||
s.email = "ben@railsgarden.com" | ||
s.homepage = "http://github.com/rubiety/nilify_blanks" | ||
s.summary = "Auto-convert blank fields to nil." | ||
s.description = "Often times you'll end up with empty strings where you really want nil at the database level. This plugin automatically converts blanks to nil and is configurable." | ||
|
||
s.files = Dir["{lib,spec}/**/*", "[A-Z]*", "init.rb"] | ||
s.require_path = "lib" | ||
|
||
s.rubyforge_project = s.name | ||
s.required_rubygems_version = ">= 1.3.4" | ||
|
||
s.add_dependency("activesupport", [">= 3.0.0"]) | ||
s.add_dependency("activerecord", [">= 3.0.0"]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require "nilify_blanks" | ||
|
||
NilifyBlanks::Railtie.insert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
sqlite: | ||
adapter: sqlite | ||
database: spec/db/test.sqlite | ||
|
||
sqlite3: | ||
adapter: sqlite3 | ||
database: spec/db/test.sqlite3 | ||
|
||
postgresql: | ||
adapter: postgresql | ||
username: postgres | ||
password: postgres | ||
database: nilify_blanks_plugin_test | ||
min_messages: ERROR | ||
|
||
mysql: | ||
adapter: mysql | ||
host: localhost | ||
username: root | ||
password: | ||
database: nilify_blanks_plugin_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
ActiveRecord::Schema.define(:version => 0) do | ||
|
||
create_table :posts, :force => true do |t| | ||
t.string :first_name | ||
t.string :last_name, :null => false | ||
t.string :title | ||
t.text :summary | ||
t.text :body | ||
t.integer :views | ||
end | ||
|
||
end |
Binary file not shown.
Oops, something went wrong.