nilly_vanilly 0.1.0 → 0.2.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.
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +30 -0
- data/README.markdown +39 -1
- data/Rakefile +4 -60
- data/lib/nilly_vanilly.rb +1 -0
- data/lib/nilly_vanilly/inspect.rb +35 -0
- data/lib/nilly_vanilly/version.rb +3 -0
- data/lib/tasks/nilly_vanilly.rake +1 -15
- data/nilly_vanilly.gemspec +18 -0
- data/spec/{database.yml → db/database.yml.example} +0 -0
- data/spec/{models.rb → db/models.rb} +0 -0
- data/spec/{schema.rb → db/schema.rb} +0 -0
- data/spec/nilly_vanilly/inspect_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -29
- data/spec/support/database.rb +29 -0
- metadata +30 -75
- data/VERSION +0 -1
- data/rails/init.rb +0 -1
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nilly_vanilly (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activerecord (2.3.12)
|
10
|
+
activesupport (= 2.3.12)
|
11
|
+
activesupport (2.3.12)
|
12
|
+
diff-lcs (1.1.2)
|
13
|
+
rspec (2.6.0)
|
14
|
+
rspec-core (~> 2.6.0)
|
15
|
+
rspec-expectations (~> 2.6.0)
|
16
|
+
rspec-mocks (~> 2.6.0)
|
17
|
+
rspec-core (2.6.4)
|
18
|
+
rspec-expectations (2.6.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.6.0)
|
21
|
+
sqlite3 (1.3.3)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
activerecord (>= 2)
|
28
|
+
nilly_vanilly!
|
29
|
+
rspec
|
30
|
+
sqlite3
|
data/README.markdown
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
NillyVanilly
|
2
2
|
============
|
3
3
|
|
4
|
-
This plugin stores NULL in your database when you try to store an empty string.
|
4
|
+
This Rails gem/plugin stores NULL in your database when you try to store an empty string.
|
5
5
|
|
6
6
|
It only works for columns you explicitly mention inside your model. It comes
|
7
7
|
with a rake task which prints out all the columns eligible for nillification.
|
@@ -25,8 +25,26 @@ Example
|
|
25
25
|
Installation
|
26
26
|
============
|
27
27
|
|
28
|
+
The preferred method of installation is now as a gem.
|
29
|
+
|
30
|
+
config.gem 'nilly_vanilly'
|
31
|
+
|
32
|
+
or, for Rails 3 with Bundler in your Gemfile:
|
33
|
+
|
34
|
+
gem 'nilly_vanilly'
|
35
|
+
|
36
|
+
Previous versions of Nilly Vanilly were distributed as a Rails plugin. For Rails
|
37
|
+
2 apps this might still work, but is not supported. If you absolutely need the
|
38
|
+
Rake task in your Rails 2 app, you can:
|
39
|
+
|
28
40
|
./script/plugin install git://github.com/tilsammans/nilly_vanilly.git
|
29
41
|
|
42
|
+
Installation as a plugin in Rails 2 adds a rake task you can run to find suitable
|
43
|
+
columns for nillification. For Rails 3, I will add this task in a future version.
|
44
|
+
Until then you can find the same information by running:
|
45
|
+
|
46
|
+
./script/runner "NillyVanilly::Inspect.print"
|
47
|
+
|
30
48
|
|
31
49
|
Inspection
|
32
50
|
==========
|
@@ -43,6 +61,26 @@ This does not take into account any validations you might have.
|
|
43
61
|
When a column has already been nillified, it will be indicated with [OK].
|
44
62
|
|
45
63
|
|
64
|
+
But WHY?!!
|
65
|
+
==========
|
66
|
+
|
67
|
+
You: who cares that empty strings are stored in the database?
|
68
|
+
Me: if you don't care, just move along. And would I recommend you nillify
|
69
|
+
every attribute in your application? No. But beside from the fact that NULL
|
70
|
+
is the "correct" value for something you don't know, enforcing this is
|
71
|
+
required if you have a unique index on that column. Unique indexes are the
|
72
|
+
fastest you can have, and they deal great with NULL values. Empty strings?
|
73
|
+
Not so much so.
|
74
|
+
|
75
|
+
|
76
|
+
Contributing
|
77
|
+
============
|
78
|
+
|
79
|
+
Fork and clone the repo and hack away.
|
80
|
+
|
81
|
+
It is very important you *must* run the specs before sending a pull request.
|
82
|
+
|
83
|
+
|
46
84
|
Author
|
47
85
|
======
|
48
86
|
|
data/Rakefile
CHANGED
@@ -1,63 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake/rdoctask'
|
1
|
+
require 'bundler/gem_tasks'
|
3
2
|
|
4
|
-
|
5
|
-
task :default => :spec
|
6
|
-
|
7
|
-
require 'jeweler'
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = "nilly_vanilly"
|
10
|
-
gem.homepage = "http://github.com/tilsammans/nilly_vanilly"
|
11
|
-
gem.summary = %Q{This plugin stores NULL in your database when you try to store an empty string.}
|
12
|
-
gem.email = "joost@spacebabies.nl"
|
13
|
-
gem.authors = ["Joost Baaij"]
|
14
|
-
gem.add_runtime_dependency 'activerecord', '~> 2.3'
|
15
|
-
gem.add_development_dependency 'rspec', '~> 1.3.1'
|
16
|
-
gem.add_development_dependency 'jeweler', '~> 0.5.2'
|
17
|
-
end
|
18
|
-
Jeweler::RubygemsDotOrgTasks.new
|
19
|
-
|
20
|
-
begin
|
21
|
-
# Rspec 1.3.0
|
22
|
-
require 'spec/rake/spectask'
|
23
|
-
|
24
|
-
desc 'Default: run specs'
|
25
|
-
task :default => :spec
|
26
|
-
Spec::Rake::SpecTask.new do |t|
|
27
|
-
t.spec_files = FileList["spec/**/*_spec.rb"]
|
28
|
-
end
|
3
|
+
require 'rspec/core/rake_task'
|
29
4
|
|
30
|
-
|
31
|
-
t.spec_files = FileList["spec/**/*_spec.rb"]
|
32
|
-
t.rcov = true
|
33
|
-
t.rcov_opts = ['--exclude', 'spec']
|
34
|
-
end
|
35
|
-
|
36
|
-
rescue LoadError
|
37
|
-
# Rspec 2.0
|
38
|
-
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new('spec')
|
39
6
|
|
40
|
-
|
41
|
-
task :default => :spec
|
42
|
-
Rspec::Core::RakeTask.new do |t|
|
43
|
-
t.pattern = "spec/**/*_spec.rb"
|
44
|
-
end
|
45
|
-
|
46
|
-
Rspec::Core::RakeTask.new('rcov') do |t|
|
47
|
-
t.pattern = "spec/**/*_spec.rb"
|
48
|
-
t.rcov = true
|
49
|
-
t.rcov_opts = ['--exclude', 'spec']
|
50
|
-
end
|
51
|
-
|
52
|
-
rescue LoadError
|
53
|
-
puts "Rspec not available. Install it with: gem install rspec"
|
54
|
-
end
|
55
|
-
|
56
|
-
desc 'Generate documentation for the nilly_vanilly plugin.'
|
57
|
-
Rake::RDocTask.new(:rdoc) do |rdoc|
|
58
|
-
rdoc.rdoc_dir = 'rdoc'
|
59
|
-
rdoc.title = 'NillyVanilly'
|
60
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
61
|
-
rdoc.rdoc_files.include('README')
|
62
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
63
|
-
end
|
7
|
+
task :default => :spec
|
data/lib/nilly_vanilly.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module NillyVanilly
|
2
|
+
# Inspect the database schema, in a quest to find columns suitable for nillification.
|
3
|
+
class Inspect
|
4
|
+
def initialize
|
5
|
+
@results = []
|
6
|
+
end
|
7
|
+
|
8
|
+
# A nested array with one row for each column suitable for nillification.
|
9
|
+
def results
|
10
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
11
|
+
model = table.classify.constantize rescue next
|
12
|
+
|
13
|
+
model.columns.each do |column|
|
14
|
+
present = model.respond_to?(:nillify_attributes) && model.nillify_attributes.include?(column.name.to_sym)
|
15
|
+
|
16
|
+
@results << [present, model.name, column.name] if include_column(column)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@results
|
21
|
+
end
|
22
|
+
|
23
|
+
# Print an inspection report to stdout.
|
24
|
+
def self.print
|
25
|
+
new.results.each do |result|
|
26
|
+
puts [result[0] ? "[OK]" : "[ ]", result[1].ljust(20), result[2]].join(" ")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def include_column(column)
|
32
|
+
column.text? && column.null && column.default.nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,21 +1,7 @@
|
|
1
1
|
namespace :nilly do
|
2
2
|
namespace :vanilly do
|
3
3
|
task :inspect => :environment do
|
4
|
-
|
5
|
-
model = table.classify.constantize rescue next
|
6
|
-
|
7
|
-
model.columns.each do |column|
|
8
|
-
if model.respond_to?(:nillify_attributes) && model.nillify_attributes.include?(column.name.to_sym)
|
9
|
-
present = "[OK]"
|
10
|
-
else
|
11
|
-
present = "[ ]"
|
12
|
-
end
|
13
|
-
|
14
|
-
if column.text? && column.null && column.default.nil?
|
15
|
-
puts [present, model.name.ljust(20), column.name].join(" ")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
4
|
+
NillyVanilly::Inspect.print
|
19
5
|
end
|
20
6
|
end
|
21
7
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "nilly_vanilly/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "nilly_vanilly"
|
7
|
+
s.version = NillyVanilly::VERSION
|
8
|
+
s.authors = ["Joost Baaij"]
|
9
|
+
s.email = ["joost@spacebabies.nl"]
|
10
|
+
s.homepage = "https://github.com/tilsammans/nilly_vanilly"
|
11
|
+
s.summary = %q{This plugin stores NULL in your database when you try to store an empty string.}
|
12
|
+
s.description = %q{This plugin stores NULL in your database when you try to store an empty string.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,32 +1,12 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
2
3
|
|
3
|
-
require '
|
4
|
-
require File.dirname(__FILE__) + '/../rails/init.rb'
|
4
|
+
require 'nilly_vanilly'
|
5
5
|
|
6
|
-
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
ActiveRecord::Base.establish_connection(active_record_configuration)
|
13
|
-
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
14
|
-
|
15
|
-
ActiveRecord::Base.silence do
|
16
|
-
ActiveRecord::Migration.verbose = false
|
17
|
-
|
18
|
-
load(File.dirname(__FILE__) + '/schema.rb')
|
19
|
-
load(File.dirname(__FILE__) + '/models.rb')
|
20
|
-
end
|
21
|
-
|
22
|
-
else
|
23
|
-
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
24
|
-
end
|
25
|
-
|
26
|
-
def clean_database!
|
27
|
-
[Post, Comment].each do |model|
|
28
|
-
ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
clean_database!
|
10
|
+
RSpec.configure do |config|
|
11
|
+
# some (optional) config here
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
ENV['DB'] ||= 'sqlite3'
|
4
|
+
|
5
|
+
database_yml = File.expand_path('../../db/database.yml', __FILE__)
|
6
|
+
if File.exists?(database_yml)
|
7
|
+
active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
|
8
|
+
|
9
|
+
ActiveRecord::Base.establish_connection(active_record_configuration)
|
10
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "../debug.log"))
|
11
|
+
|
12
|
+
ActiveRecord::Base.silence do
|
13
|
+
ActiveRecord::Migration.verbose = false
|
14
|
+
|
15
|
+
load(File.dirname(__FILE__) + '/../db/schema.rb')
|
16
|
+
load(File.dirname(__FILE__) + '/../db/models.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
else
|
20
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.example"
|
21
|
+
end
|
22
|
+
|
23
|
+
def clean_database!
|
24
|
+
[Post, Comment].each do |model|
|
25
|
+
ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
clean_database!
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nilly_vanilly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Joost Baaij
|
@@ -15,79 +10,42 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-08-12 00:00:00 +02:00
|
19
14
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 5
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 3
|
33
|
-
version: "2.3"
|
34
|
-
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rspec
|
38
|
-
prerelease: false
|
39
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
|
-
requirements:
|
42
|
-
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 25
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 3
|
48
|
-
- 1
|
49
|
-
version: 1.3.1
|
50
|
-
type: :development
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: jeweler
|
54
|
-
prerelease: false
|
55
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 15
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
- 5
|
64
|
-
- 2
|
65
|
-
version: 0.5.2
|
66
|
-
type: :development
|
67
|
-
version_requirements: *id003
|
68
|
-
description:
|
69
|
-
email: joost@spacebabies.nl
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: This plugin stores NULL in your database when you try to store an empty string.
|
18
|
+
email:
|
19
|
+
- joost@spacebabies.nl
|
70
20
|
executables: []
|
71
21
|
|
72
22
|
extensions: []
|
73
23
|
|
74
|
-
extra_rdoc_files:
|
75
|
-
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
76
26
|
files:
|
27
|
+
- .gitignore
|
28
|
+
- .rspec
|
29
|
+
- CHANGELOG.md
|
30
|
+
- Gemfile
|
31
|
+
- Gemfile.lock
|
77
32
|
- README.markdown
|
78
33
|
- Rakefile
|
79
|
-
- VERSION
|
80
34
|
- lib/nilly_vanilly.rb
|
35
|
+
- lib/nilly_vanilly/inspect.rb
|
81
36
|
- lib/nilly_vanilly/nillify.rb
|
37
|
+
- lib/nilly_vanilly/version.rb
|
82
38
|
- lib/tasks/nilly_vanilly.rake
|
83
|
-
-
|
84
|
-
- spec/database.yml
|
85
|
-
- spec/models.rb
|
39
|
+
- nilly_vanilly.gemspec
|
40
|
+
- spec/db/database.yml.example
|
41
|
+
- spec/db/models.rb
|
42
|
+
- spec/db/schema.rb
|
43
|
+
- spec/nilly_vanilly/inspect_spec.rb
|
86
44
|
- spec/nilly_vanilly_spec.rb
|
87
|
-
- spec/schema.rb
|
88
45
|
- spec/spec_helper.rb
|
46
|
+
- spec/support/database.rb
|
89
47
|
has_rdoc: true
|
90
|
-
homepage:
|
48
|
+
homepage: https://github.com/tilsammans/nilly_vanilly
|
91
49
|
licenses: []
|
92
50
|
|
93
51
|
post_install_message:
|
@@ -100,28 +58,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
58
|
requirements:
|
101
59
|
- - ">="
|
102
60
|
- !ruby/object:Gem::Version
|
103
|
-
hash: 3
|
104
|
-
segments:
|
105
|
-
- 0
|
106
61
|
version: "0"
|
107
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
63
|
none: false
|
109
64
|
requirements:
|
110
65
|
- - ">="
|
111
66
|
- !ruby/object:Gem::Version
|
112
|
-
hash: 3
|
113
|
-
segments:
|
114
|
-
- 0
|
115
67
|
version: "0"
|
116
68
|
requirements: []
|
117
69
|
|
118
70
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.6.2
|
120
72
|
signing_key:
|
121
73
|
specification_version: 3
|
122
74
|
summary: This plugin stores NULL in your database when you try to store an empty string.
|
123
75
|
test_files:
|
124
|
-
- spec/
|
76
|
+
- spec/db/database.yml.example
|
77
|
+
- spec/db/models.rb
|
78
|
+
- spec/db/schema.rb
|
79
|
+
- spec/nilly_vanilly/inspect_spec.rb
|
125
80
|
- spec/nilly_vanilly_spec.rb
|
126
|
-
- spec/schema.rb
|
127
81
|
- spec/spec_helper.rb
|
82
|
+
- spec/support/database.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'nilly_vanilly'
|