acts_as_strip 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,12 +1,15 @@
1
1
  source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
- gem "activerecord", ">= 2.3.5"
5
4
 
6
5
  # Add dependencies to develop your gem here.
7
6
  # Include everything needed to run rake, tests, features, etc.
8
7
  group :development do
8
+ gem "activerecord", ">= 2.3.5"
9
+ gem "activemodel", ">= 3.0.0"
9
10
  gem "bundler", "~> 1.0.0"
10
- gem "jeweler", "~> 1.5.0.pre5"
11
- gem "rcov", ">= 0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem 'simplecov', '>= 0.3.8', :require => false
13
+ gem "rspec", "~> 2.3.0"
14
+ gem "yard", "~> 0.6.0"
12
15
  end
@@ -2,9 +2,11 @@
2
2
 
3
3
  Plugin to remove spaces on fields
4
4
 
5
- == Dependency
5
+ == Support for
6
6
 
7
- * ActiveRecord
7
+ * ActiveRecord (with auto strip)
8
+ * ActiveModel
9
+ * And other
8
10
 
9
11
  == Install
10
12
 
@@ -14,9 +16,31 @@ Insert into Gemfile
14
16
 
15
17
  == Integration
16
18
 
17
- class Model < ActiveRecord::Base
18
- acts_as_strip :field1, :field2
19
- end
19
+ === ActiveRecord
20
+
21
+ class Model < ActiveRecord::Base
22
+ acts_as_strip :field1, :field2
23
+ end
24
+
25
+ === ActiveModel
26
+
27
+ class Model
28
+ include ActsAsStrip
29
+ attr_accessor :field
30
+ acts_as_strip :field
31
+ end
32
+
33
+ Model.new(data).strip_fields!
34
+
35
+ == History
36
+
37
+ * 1.0 init
38
+ * 1.1 support for active model
39
+
40
+ == Maintainers
41
+
42
+ * Team Phatworx (http://github.com/phatworx)
43
+ * Marco Scholl (http://github.com/traxanos)
20
44
 
21
45
  == Contributing to acts_as_strip
22
46
 
@@ -30,6 +54,5 @@ end
30
54
 
31
55
  == Copyright
32
56
 
33
- Copyright (c) 2010 Marco Scholl. See LICENSE.txt for
34
- further details.
57
+ Copyright (c) 2010 Marco Scholl. See LICENSE.txt for further details.
35
58
 
data/Rakefile CHANGED
@@ -15,41 +15,19 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "acts_as_strip"
16
16
  gem.summary = %Q{Plugin to remove spaces on fields}
17
17
  gem.description = %Q{Plugin to remove spaces on fields}
18
- gem.email = "develop@marco-scholl.de"
19
- gem.homepage = "http://github.com/traxanos/acts_as_strip"
18
+ gem.email = "team@phatworx.de"
19
+ gem.homepage = "http://github.com/phatworx/acts_as_strip"
20
20
  gem.authors = ["Marco Scholl"]
21
- # Include your dependencies below. Runtime dependencies are required when using your gem,
22
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23
- gem.add_runtime_dependency 'activerecord', '>= 0'
24
- # spec.add_development_dependency 'rspec', '> 1.2.3'
25
- gem.add_development_dependency "bundler", "~> 1.0.0"
26
- gem.add_development_dependency "jeweler", "~> 1.5.0.pre5"
27
- gem.add_development_dependency "rcov", ">= 0"
28
21
  end
29
22
  Jeweler::RubygemsDotOrgTasks.new
30
23
 
31
- require 'rake/testtask'
32
- Rake::TestTask.new(:test) do |test|
33
- test.libs << 'lib' << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
24
+ require 'rspec/core'
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new(:spec) do |spec|
27
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
28
  end
37
29
 
38
- require 'rcov/rcovtask'
39
- Rcov::RcovTask.new do |test|
40
- test.libs << 'test'
41
- test.pattern = 'test/**/test_*.rb'
42
- test.verbose = true
43
- end
44
-
45
- task :default => :test
30
+ task :default => :spec
46
31
 
47
- require 'rake/rdoctask'
48
- Rake::RDocTask.new do |rdoc|
49
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
-
51
- rdoc.rdoc_dir = 'rdoc'
52
- rdoc.title = "acts_as_strip #{version}"
53
- rdoc.rdoc_files.include('README*')
54
- rdoc.rdoc_files.include('lib/**/*.rb')
55
- end
32
+ require 'yard'
33
+ YARD::Rake::YardocTask.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -1,17 +1,17 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_strip}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marco Scholl"]
12
- s.date = %q{2010-10-25}
12
+ s.date = %q{2011-02-13}
13
13
  s.description = %q{Plugin to remove spaces on fields}
14
- s.email = %q{develop@marco-scholl.de}
14
+ s.email = %q{team@phatworx.de}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -24,51 +24,50 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "acts_as_strip.gemspec",
27
+ "init.rb",
27
28
  "lib/acts_as_strip.rb",
28
- "test/helper.rb",
29
- "test/test_acts_as_strip.rb"
29
+ "spec/acts_as_strip_spec.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/support/models.rb"
30
32
  ]
31
- s.homepage = %q{http://github.com/traxanos/acts_as_strip}
33
+ s.homepage = %q{http://github.com/phatworx/acts_as_strip}
32
34
  s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.7}
35
+ s.rubygems_version = %q{1.5.0}
34
36
  s.summary = %q{Plugin to remove spaces on fields}
35
37
  s.test_files = [
36
- "test/helper.rb",
37
- "test/test_acts_as_strip.rb"
38
+ "spec/acts_as_strip_spec.rb",
39
+ "spec/spec_helper.rb",
40
+ "spec/support/models.rb"
38
41
  ]
39
42
 
40
43
  if s.respond_to? :specification_version then
41
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
44
  s.specification_version = 3
43
45
 
44
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_runtime_dependency(%q<activerecord>, [">= 2.3.5"])
47
+ s.add_development_dependency(%q<activerecord>, [">= 2.3.5"])
48
+ s.add_development_dependency(%q<activemodel>, [">= 3.0.0"])
46
49
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
48
- s.add_development_dependency(%q<rcov>, [">= 0"])
49
- s.add_runtime_dependency(%q<activerecord>, [">= 0"])
50
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
52
- s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<simplecov>, [">= 0.3.8"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
53
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
53
54
  else
54
55
  s.add_dependency(%q<activerecord>, [">= 2.3.5"])
56
+ s.add_dependency(%q<activemodel>, [">= 3.0.0"])
55
57
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
- s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
57
- s.add_dependency(%q<rcov>, [">= 0"])
58
- s.add_dependency(%q<activerecord>, [">= 0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
- s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_dependency(%q<simplecov>, [">= 0.3.8"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
61
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
62
62
  end
63
63
  else
64
64
  s.add_dependency(%q<activerecord>, [">= 2.3.5"])
65
+ s.add_dependency(%q<activemodel>, [">= 3.0.0"])
65
66
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
67
- s.add_dependency(%q<rcov>, [">= 0"])
68
- s.add_dependency(%q<activerecord>, [">= 0"])
69
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
- s.add_dependency(%q<jeweler>, ["~> 1.5.0.pre5"])
71
- s.add_dependency(%q<rcov>, [">= 0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
68
+ s.add_dependency(%q<simplecov>, [">= 0.3.8"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
70
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
72
71
  end
73
72
  end
74
73
 
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'acts_as_strip'
@@ -1,32 +1,48 @@
1
1
  require 'rubygems'
2
2
  require 'active_record'
3
3
 
4
- module ActiveRecord #:nodoc:
5
- module ActsAsStrip #:nodoc:
4
+ # Plugin to remove spaces on fields
5
+ module ActsAsStrip
6
6
 
7
- def self.included(base)
8
- base.extend ClassMethods
7
+ def self.included(base) # :nodoc:
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ # class methods for active record and active model
12
+ module ClassMethods
13
+
14
+ # activate gem on ar-model to trim spaces on fields
15
+ #
16
+ # -----
17
+ #
18
+ # === Example:
19
+ # class User < ActiveRecord::Base
20
+ # acts_as_strip :field1, :field2
21
+ # end
22
+ #
23
+ def acts_as_strip(*fields)
24
+ include InstanceMethods
25
+ cattr_accessor :strip_fields
26
+ self.strip_fields = fields
27
+ before_validation :strip_fields! if self.respond_to? :before_validation
9
28
  end
10
29
 
11
- module ClassMethods
12
- # activate gem on ar-model to trim spaces on fields
13
- #
14
- # -----
15
- #
16
- # === Example:
17
- # class User
18
- # acts_as_strip :field1, :field2
19
- # end
20
- #
21
- def acts_as_strip(*fields)
22
- before_validation do |model|
23
- fields.each do |n|
24
- model[n] = model[n].strip if model[n].respond_to?('strip')
25
- end
26
- end
30
+ end
31
+
32
+ # instance methods for active record and active model
33
+ module InstanceMethods
34
+ # strip declared fields
35
+ #
36
+ # ----
37
+ #
38
+ # === Example:
39
+ # User.new(data).strip_fields
40
+ def strip_fields!
41
+ strip_fields.each do |n|
42
+ send("#{n}=", send("#{n}").strip) if send("#{n}").respond_to?('strip')
27
43
  end
28
44
  end
29
45
  end
30
46
  end
31
47
 
32
- ActiveRecord::Base.send(:include, ActiveRecord::ActsAsStrip)
48
+ ActiveRecord::Base.send(:include, ActsAsStrip) if defined? ActiveRecord
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe ActsAsStrip do
5
+ describe ActiveRecordDummy do
6
+ before { @dummy = ActiveRecordDummy.new }
7
+ subject { @dummy }
8
+
9
+ context "when fields empty" do
10
+ specify { should be_valid }
11
+
12
+ describe :field1 do
13
+ subject { @dummy.field1 }
14
+ it { should be_blank }
15
+ end
16
+
17
+ describe :field2 do
18
+ subject { @dummy.field2 }
19
+ it { should be_blank }
20
+ end
21
+ end
22
+
23
+ context "when field1 and field2 filled with \" TEST \"" do
24
+ before do
25
+ @dummy.field1 = " TEST "
26
+ @dummy.field2 = " TEST "
27
+ @dummy.valid?
28
+ end
29
+
30
+ describe :field1 do
31
+ subject { @dummy.field1 }
32
+ it { should == "TEST" }
33
+ end
34
+
35
+ describe :field2 do
36
+ subject { @dummy.field2 }
37
+ it { should == "TEST" }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe ActiveModelDummy do
43
+ before { @dummy = ActiveModelDummy.new }
44
+ subject { @dummy }
45
+
46
+ context "when fields empty" do
47
+ before do
48
+ @dummy.strip_fields!
49
+ end
50
+
51
+ describe :field1 do
52
+ subject { @dummy.field1 }
53
+ it { should be_blank }
54
+ end
55
+
56
+ describe :field2 do
57
+ subject { @dummy.field2 }
58
+ it { should be_blank }
59
+ end
60
+ end
61
+
62
+ context "when field1 and field2 filled with \" TEST \"" do
63
+ before do
64
+ @dummy.field1 = " TEST "
65
+ @dummy.field2 = " TEST "
66
+ @dummy.strip_fields!
67
+ end
68
+
69
+ describe :field1 do
70
+ subject { @dummy.field1 }
71
+ it { should == "TEST" }
72
+ end
73
+
74
+ describe :field2 do
75
+ subject { @dummy.field2 }
76
+ it { should == "TEST" }
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'simplecov'
4
+ SimpleCov.start 'rails'
5
+ require 'rspec'
6
+ require 'acts_as_strip'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ RSpec.configure do |c|
13
+
14
+ end
@@ -0,0 +1,24 @@
1
+ class ActiveRecordDummy < ActiveRecord::Base
2
+ class_inheritable_accessor :columns
3
+ self.columns = []
4
+
5
+ def self.column(name, sql_type = nil, default = nil, null = true)
6
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
7
+ end
8
+
9
+ column :field1, :string
10
+ column :field2, :string
11
+
12
+ acts_as_strip :field1, :field2
13
+ end
14
+
15
+ class ActiveModelDummy
16
+ include ActsAsStrip
17
+
18
+ attr_accessor :field1
19
+ attr_accessor :field2
20
+
21
+ acts_as_strip :field1, :field2
22
+ end
23
+
24
+
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_strip
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 0
9
- version: 1.0.0
4
+ prerelease:
5
+ version: 1.1.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Marco Scholl
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-10-25 00:00:00 +02:00
13
+ date: 2011-02-13 00:00:00 +01:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -24,117 +20,78 @@ dependencies:
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 3
30
- - 5
31
23
  version: 2.3.5
32
- type: :runtime
24
+ type: :development
33
25
  prerelease: false
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
36
- name: bundler
28
+ name: activemodel
37
29
  requirement: &id002 !ruby/object:Gem::Requirement
38
30
  none: false
39
31
  requirements:
40
- - - ~>
32
+ - - ">="
41
33
  - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 0
45
- - 0
46
- version: 1.0.0
34
+ version: 3.0.0
47
35
  type: :development
48
36
  prerelease: false
49
37
  version_requirements: *id002
50
38
  - !ruby/object:Gem::Dependency
51
- name: jeweler
39
+ name: bundler
52
40
  requirement: &id003 !ruby/object:Gem::Requirement
53
41
  none: false
54
42
  requirements:
55
43
  - - ~>
56
44
  - !ruby/object:Gem::Version
57
- segments:
58
- - 1
59
- - 5
60
- - 0
61
- - pre5
62
- version: 1.5.0.pre5
45
+ version: 1.0.0
63
46
  type: :development
64
47
  prerelease: false
65
48
  version_requirements: *id003
66
49
  - !ruby/object:Gem::Dependency
67
- name: rcov
50
+ name: jeweler
68
51
  requirement: &id004 !ruby/object:Gem::Requirement
69
52
  none: false
70
53
  requirements:
71
- - - ">="
54
+ - - ~>
72
55
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- version: "0"
56
+ version: 1.5.2
76
57
  type: :development
77
58
  prerelease: false
78
59
  version_requirements: *id004
79
60
  - !ruby/object:Gem::Dependency
80
- name: activerecord
61
+ name: simplecov
81
62
  requirement: &id005 !ruby/object:Gem::Requirement
82
63
  none: false
83
64
  requirements:
84
65
  - - ">="
85
66
  - !ruby/object:Gem::Version
86
- segments:
87
- - 0
88
- version: "0"
89
- type: :runtime
67
+ version: 0.3.8
68
+ type: :development
90
69
  prerelease: false
91
70
  version_requirements: *id005
92
71
  - !ruby/object:Gem::Dependency
93
- name: bundler
72
+ name: rspec
94
73
  requirement: &id006 !ruby/object:Gem::Requirement
95
74
  none: false
96
75
  requirements:
97
76
  - - ~>
98
77
  - !ruby/object:Gem::Version
99
- segments:
100
- - 1
101
- - 0
102
- - 0
103
- version: 1.0.0
78
+ version: 2.3.0
104
79
  type: :development
105
80
  prerelease: false
106
81
  version_requirements: *id006
107
82
  - !ruby/object:Gem::Dependency
108
- name: jeweler
83
+ name: yard
109
84
  requirement: &id007 !ruby/object:Gem::Requirement
110
85
  none: false
111
86
  requirements:
112
87
  - - ~>
113
88
  - !ruby/object:Gem::Version
114
- segments:
115
- - 1
116
- - 5
117
- - 0
118
- - pre5
119
- version: 1.5.0.pre5
89
+ version: 0.6.0
120
90
  type: :development
121
91
  prerelease: false
122
92
  version_requirements: *id007
123
- - !ruby/object:Gem::Dependency
124
- name: rcov
125
- requirement: &id008 !ruby/object:Gem::Requirement
126
- none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- segments:
131
- - 0
132
- version: "0"
133
- type: :development
134
- prerelease: false
135
- version_requirements: *id008
136
93
  description: Plugin to remove spaces on fields
137
- email: develop@marco-scholl.de
94
+ email: team@phatworx.de
138
95
  executables: []
139
96
 
140
97
  extensions: []
@@ -150,11 +107,13 @@ files:
150
107
  - Rakefile
151
108
  - VERSION
152
109
  - acts_as_strip.gemspec
110
+ - init.rb
153
111
  - lib/acts_as_strip.rb
154
- - test/helper.rb
155
- - test/test_acts_as_strip.rb
112
+ - spec/acts_as_strip_spec.rb
113
+ - spec/spec_helper.rb
114
+ - spec/support/models.rb
156
115
  has_rdoc: true
157
- homepage: http://github.com/traxanos/acts_as_strip
116
+ homepage: http://github.com/phatworx/acts_as_strip
158
117
  licenses: []
159
118
 
160
119
  post_install_message:
@@ -167,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
126
  requirements:
168
127
  - - ">="
169
128
  - !ruby/object:Gem::Version
170
- hash: -4457438205387924726
129
+ hash: -1681287196575352078
171
130
  segments:
172
131
  - 0
173
132
  version: "0"
@@ -176,16 +135,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
135
  requirements:
177
136
  - - ">="
178
137
  - !ruby/object:Gem::Version
179
- segments:
180
- - 0
181
138
  version: "0"
182
139
  requirements: []
183
140
 
184
141
  rubyforge_project:
185
- rubygems_version: 1.3.7
142
+ rubygems_version: 1.5.0
186
143
  signing_key:
187
144
  specification_version: 3
188
145
  summary: Plugin to remove spaces on fields
189
146
  test_files:
190
- - test/helper.rb
191
- - test/test_acts_as_strip.rb
147
+ - spec/acts_as_strip_spec.rb
148
+ - spec/spec_helper.rb
149
+ - spec/support/models.rb
@@ -1,17 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
-
12
- $LOAD_PATH.unshift(File.dirname(__FILE__))
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- require 'acts_as_strip'
15
-
16
- class Test::Unit::TestCase
17
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestActsAsStrip < Test::Unit::TestCase
4
- def test_something_for_real
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end