dm-trimmer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ === 0.1.0 / 2009-09-19
2
+
3
+ * Initial version ported from Rails plugin
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Simon Harris
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,15 @@
1
+ = dm-trimmer
2
+
3
+ DataMapper plugin to remove leading and trailing blanks from property values.
4
+
5
+ Leading and trailing spaces on property values can be a problem. They're almost never wanted nor intended. In fact,
6
+ Oracle actually treats empty strings as NULL. That's not to say I necessarily think that the database should be messing
7
+ with our data mind you but it does show that at least someone agrees with me.
8
+
9
+ Here's an example of what happens when the plugin is installed:
10
+
11
+ u = User.new
12
+
13
+ u.name = " Simon Harris " # => "Simon Harris"
14
+
15
+ u.name = " " # => nil
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ Dir["tasks/**/*.rb"].each do |task_file|
2
+ require task_file
3
+ end
4
+
5
+ task :default => [ :spec ]
data/TODO ADDED
File without changes
data/lib/dm-trimmer.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'dm-trimmer/trimmer'
2
+ require 'dm-trimmer/version'
@@ -0,0 +1,24 @@
1
+ require 'dm-core'
2
+
3
+ module DataMapper
4
+
5
+ module Trimmer
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+ alias_method :set_without_trimmer!, :set!
10
+ alias_method :set!, :set_with_trimmer!
11
+ end
12
+ end
13
+
14
+ def set_with_trimmer!(name, value)
15
+ value = value.strip if value.respond_to?(:strip)
16
+ value = nil if value.respond_to?(:empty?) && value.empty?
17
+ set_without_trimmer!(name, value)
18
+ end
19
+
20
+ end
21
+
22
+ Property.send(:include, Trimmer)
23
+
24
+ end
@@ -0,0 +1,7 @@
1
+ module DataMapper
2
+
3
+ module Trimmer
4
+ VERSION = "0.1.0".freeze
5
+ end
6
+
7
+ end
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
4
+
5
+ class Record
6
+ include DataMapper::Resource
7
+ property :id, Serial
8
+ property :name, String
9
+ end
10
+
11
+ describe DataMapper::Trimmer do
12
+
13
+ before do
14
+ Record.auto_migrate!(:default)
15
+ @record = Record.new
16
+ end
17
+
18
+ describe "setting a value" do
19
+
20
+ describe "to text surrounding with blanks" do
21
+
22
+ before do
23
+ @record.name = " Simon Harris "
24
+ end
25
+
26
+ it "removes surrounding blanks" do
27
+ @record.name.should == "Simon Harris"
28
+ end
29
+
30
+ end
31
+
32
+ describe "to all blanks" do
33
+
34
+ before do
35
+ @record.name = " "
36
+ end
37
+
38
+ it "converts to nil" do
39
+ @record.name.should be_nil
40
+ end
41
+
42
+ end
43
+
44
+ describe "to nil" do
45
+
46
+ before do
47
+ @record.name = nil
48
+ end
49
+
50
+ it "leaves the value untouched" do
51
+ @record.name.should be_nil
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --loadby random
3
+ --backtrace
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+
3
+ # Support running specs with "rake spec" and "spec"
4
+ $LOAD_PATH.unshift("lib") unless $LOAD_PATH.include?("lib")
5
+
6
+ require 'dm-trimmer'
7
+
8
+ def load_driver(name, default_uri)
9
+ return false if ENV["ADAPTER"] != name.to_s
10
+
11
+ begin
12
+ DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
13
+ DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
14
+ true
15
+ rescue LoadError => e
16
+ warn "Could not load do_#{name}: #{e}"
17
+ false
18
+ end
19
+ end
20
+
21
+ ENV["ADAPTER"] ||= "sqlite3"
22
+
23
+ HAS_SQLITE3 = load_driver(:sqlite3, "sqlite3::memory:")
24
+ HAS_MYSQL = load_driver(:mysql, "mysql://localhost/dm_core_test")
25
+ HAS_POSTGRES = load_driver(:postgres, "postgres://postgres@localhost/dm_core_test")
data/tasks/spec.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "spec/rake/spectask"
2
+
3
+ desc "Run specifications"
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.spec_opts << "--options" << "spec/spec.opts" if File.exists?("spec/spec.opts")
6
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-trimmer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Harris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-30 00:00:00 +10:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: DataMapper plugin to remove leading and trailing blanks from property values.
26
+ email: haruki.zaemon@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - History.rdoc
34
+ - TODO
35
+ - LICENSE
36
+ files:
37
+ - lib/dm-trimmer/trimmer.rb
38
+ - lib/dm-trimmer/version.rb
39
+ - lib/dm-trimmer.rb
40
+ - spec/dm-trimmer/trimmer_spec.rb
41
+ - spec/spec.opts
42
+ - spec/spec_helper.rb
43
+ - tasks/spec.rb
44
+ - Rakefile
45
+ - README.rdoc
46
+ - History.rdoc
47
+ - TODO
48
+ - LICENSE
49
+ has_rdoc: true
50
+ homepage: http://github.com/harukizaemon/dm-trimmer
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: DataMapper plugin to remove leading and trailing blanks from property values.
77
+ test_files: []
78
+