trim_spaces_for 0.1.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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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.md ADDED
@@ -0,0 +1,20 @@
1
+ # TrimSpacesFor
2
+
3
+ TrimSpacesFor gem removes leading and trailing white spaces from the AR attribute values.
4
+
5
+ ## Installing
6
+ gem install trim_spaces_for
7
+
8
+ ## Usage
9
+
10
+ class Article < ActiveRecord::Base
11
+ trim_spaces_for :title
12
+ end
13
+
14
+ > obj = Article.new
15
+ > obj.title = " Article Title "
16
+ > obj.save #=> true
17
+ > obj.title #=> "Article Title"
18
+
19
+
20
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rspec/core/rake_task'
9
+
10
+ begin
11
+ require 'rdoc/task'
12
+ rescue LoadError
13
+ require 'rdoc/rdoc'
14
+ require 'rake/rdoctask'
15
+ RDoc::Task = Rake::RDocTask
16
+ end
17
+
18
+ RDoc::Task.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'TrimSpacesFor'
21
+ rdoc.options << '--line-numbers'
22
+ rdoc.rdoc_files.include('README.rdoc')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+
27
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
28
+ load 'rails/tasks/engine.rake'
29
+
30
+
31
+ Bundler::GemHelper.install_tasks
32
+
33
+
34
+ RSpec::Core::RakeTask.new(:spec)
35
+
36
+ task :test => :spec
37
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :trim_spaces_for do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,25 @@
1
+ module TrimSpacesFor
2
+ def self.hook!
3
+ require 'rails' if rails?
4
+
5
+ require 'trim_spaces_for/string_extension'
6
+ require 'trim_spaces_for/hooks'
7
+ if rails?
8
+ require 'trim_spaces_for/railtie'
9
+ require 'trim_spaces_for/engine'
10
+ else
11
+ TrimSpacesFor::Hooks.init!
12
+ end
13
+ end
14
+
15
+ def self.load!
16
+ hook!
17
+ end
18
+
19
+ private
20
+ def self.rails?
21
+ defined?(::Rails)
22
+ end
23
+ end
24
+
25
+ TrimSpacesFor.load!
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module TrimSpacesFor
4
+ module ActiveRecordExtension
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def trim_spaces_for(*target_attributes)
9
+ before_validation do |model|
10
+ target_attributes.each do |attribute|
11
+ model[attribute] = model[attribute].trim if model[attribute].respond_to?(:trim)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module TrimSpacesFor
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'trim_spaces_for/string_extension'
4
+ require 'trim_spaces_for/active_record_extension'
5
+
6
+ module TrimSpacesFor
7
+ class Hooks
8
+ def self.init!
9
+ ::String.send :include, TrimSpacesFor::StringExtension
10
+
11
+ ActiveSupport.on_load(:active_record) do
12
+ ::ActiveRecord::Base.send :include, TrimSpacesFor::ActiveRecordExtension
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module TrimSpacesFor
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'trim_spaces_for' do |app|
6
+ TrimSpacesFor::Hooks.init!
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module TrimSpacesFor
4
+ module StringExtension
5
+ def trim
6
+ white_spaces_regex = "[\u0020\u0009\u000a\u000d\u3000]+"
7
+ self.gsub(/\A#{white_spaces_regex}|#{white_spaces_regex}\Z/u, "")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module TrimSpacesFor
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trim_spaces_for
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Takumi Miura
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-02-21 00:00:00 +09:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.1.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: sqlite3
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec-rails
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: spork
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 1.0.0.rc
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rb-fsevent
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: guard-rspec
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: guard-spork
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: growl
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *id010
126
+ description: TrimSpacesFor gem removes leading and trailing white spaces from the AR attribute values.
127
+ email:
128
+ - mitaku1104@gmail.com
129
+ executables: []
130
+
131
+ extensions: []
132
+
133
+ extra_rdoc_files: []
134
+
135
+ files:
136
+ - lib/tasks/trim_spaces_for_tasks.rake
137
+ - lib/trim_spaces_for/active_record_extension.rb
138
+ - lib/trim_spaces_for/engine.rb
139
+ - lib/trim_spaces_for/hooks.rb
140
+ - lib/trim_spaces_for/railtie.rb
141
+ - lib/trim_spaces_for/string_extension.rb
142
+ - lib/trim_spaces_for/version.rb
143
+ - lib/trim_spaces_for.rb
144
+ - MIT-LICENSE
145
+ - Rakefile
146
+ - README.md
147
+ has_rdoc: true
148
+ homepage: https://github.com/mitaku/trim_spaces_for
149
+ licenses: []
150
+
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 2921468389528403564
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 2921468389528403564
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.6.2
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: TrimSpacesFor gem removes leading and trailing white spaces from the AR attribute values.
181
+ test_files: []
182
+