rere_validator 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c70fbcbd80e299b25f84cb8f7eb61ab162e1f975
4
+ data.tar.gz: 3dfe0649cc239aca5fc5f1607cd3d6dc40807c55
5
+ SHA512:
6
+ metadata.gz: 52bb2b120cdd119864b4ceef12b0c7b330c554f7e47678e3bc1b6a43a56de72041044677487f2fe0bd3eda44ba2ae6ea1589f92dc8e2c976d1b5df38f3bda844
7
+ data.tar.gz: f902d5c93dca1940bc94cba507e17c8fdce729c115177bdc86c5e4e963bac8e037c903352c7183fcdc07da33984041b3f3cc612e515132e90b8275bedaac1743
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
11
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rere_validator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Natsuki Tanaka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # RereValidator
2
+
3
+ Custom validator for ActiveModel.
4
+
5
+ Provides regex and reserved words to username.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rere_validator'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rere_validator
22
+
23
+ ## Usage
24
+
25
+ Set the validation to your ActiveModel:
26
+
27
+ ```ruby
28
+ class User < ActiveRecord
29
+ validates :username, regex_reserved: true
30
+ end
31
+ ```
32
+
33
+ If you want to add reserved words:
34
+
35
+ ```ruby
36
+ class User < ActiveRecord
37
+ validates :username, regex_reserved: {
38
+ add_reserved_words: %w[tweet retweet]
39
+ }
40
+ end
41
+ ```
42
+
43
+ ### Error Messages
44
+
45
+ You can define new error messages using the I18n system:
46
+
47
+ ```yaml
48
+ en:
49
+ errors:
50
+ messages:
51
+ invalid_characters: "can't contain invalid characters"
52
+ invalid_characters_at_begin: "can't begin with '.', '-', '_'"
53
+ invalid_characters_at_end: "can't end with '.', '-', '_'"
54
+ reserved_words: "can't be used a reserved words"
55
+ ```
56
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rere_validator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,390 @@
1
+ RESERVED_WORDS = %w[
2
+ about
3
+ access
4
+ acount
5
+ acounts
6
+ activity
7
+ add
8
+ address
9
+ admin
10
+ adult
11
+ ajax
12
+ all
13
+ analytics
14
+ android
15
+ api
16
+ app
17
+ application
18
+ apps
19
+ archive
20
+ article
21
+ as
22
+ asset
23
+ atom
24
+ auth
25
+ authentication
26
+ avatar
27
+ backup
28
+ ban
29
+ beta
30
+ bitch
31
+ blog
32
+ book
33
+ bookmark
34
+ book.mark
35
+ book-mark
36
+ book_mark
37
+ bot
38
+ bots
39
+ bug
40
+ business
41
+ by
42
+ calendar
43
+ call
44
+ case
45
+ categories
46
+ category
47
+ chat
48
+ client
49
+ clitoris
50
+ code
51
+ comment
52
+ comments
53
+ community
54
+ company
55
+ config
56
+ configration
57
+ connect
58
+ contact
59
+ contribute
60
+ contributor
61
+ copyright
62
+ count
63
+ create
64
+ css
65
+ dashboard
66
+ data
67
+ db
68
+ default
69
+ delete
70
+ demo
71
+ design
72
+ designer
73
+ destroy
74
+ dev
75
+ developer
76
+ diary
77
+ dick
78
+ dict
79
+ dictionary
80
+ die
81
+ dildo
82
+ dir
83
+ documentation
84
+ domain
85
+ download
86
+ downloads
87
+ dv
88
+ edit
89
+ edu
90
+ else
91
+ email
92
+ empty
93
+ end
94
+ entry
95
+ error
96
+ errors
97
+ event
98
+ example
99
+ exit
100
+ faq
101
+ favorite
102
+ favorites
103
+ feature
104
+ feed
105
+ feedback
106
+ feed.back
107
+ feed-back
108
+ feed_back
109
+ fellate
110
+ fellatio
111
+ file
112
+ files
113
+ flash
114
+ follow
115
+ form
116
+ forum
117
+ free
118
+ friend
119
+ friends
120
+ fuck
121
+ fucker
122
+ game
123
+ games
124
+ get
125
+ gift
126
+ group
127
+ groups
128
+ guest
129
+ help
130
+ home
131
+ homepage
132
+ home.page
133
+ home-page
134
+ home_page
135
+ host
136
+ hosting
137
+ hostname
138
+ host.name
139
+ host-name
140
+ host_name
141
+ html
142
+ http
143
+ httpd
144
+ https
145
+ i
146
+ icon
147
+ id
148
+ if
149
+ image
150
+ images
151
+ img
152
+ index
153
+ info
154
+ information
155
+ introduction
156
+ invite
157
+ ipad
158
+ iphone
159
+ is
160
+ issue
161
+ it
162
+ item
163
+ jk
164
+ job
165
+ jobs
166
+ js
167
+ language
168
+ license
169
+ link
170
+ links
171
+ list
172
+ lists
173
+ location
174
+ log
175
+ login
176
+ log.in
177
+ log-in
178
+ log_in
179
+ logout
180
+ log.out
181
+ log-out
182
+ log_out
183
+ logs
184
+ mail
185
+ manager
186
+ marketing
187
+ master
188
+ me
189
+ media
190
+ message
191
+ messages
192
+ messenger
193
+ mine
194
+ mobile
195
+ movie
196
+ movies
197
+ msg
198
+ music
199
+ my
200
+ name
201
+ navi
202
+ navigation
203
+ net
204
+ network
205
+ new
206
+ news
207
+ nickname
208
+ nick.name
209
+ nick-name
210
+ nick_name
211
+ nobody
212
+ notify
213
+ null
214
+ oauth
215
+ oauth2
216
+ off
217
+ official
218
+ old
219
+ on
220
+ online
221
+ operator
222
+ or
223
+ order
224
+ owner
225
+ page
226
+ pages
227
+ password
228
+ pass.word
229
+ pass-word
230
+ pass_word
231
+ penis
232
+ photo
233
+ photos
234
+ picture
235
+ plugin
236
+ policies
237
+ policy
238
+ poop
239
+ post
240
+ premium
241
+ privacy
242
+ private
243
+ product
244
+ products
245
+ profile
246
+ project
247
+ projects
248
+ pub
249
+ public
250
+ pussy
251
+ put
252
+ random
253
+ read
254
+ readme
255
+ register
256
+ registration
257
+ remove
258
+ request
259
+ reserved
260
+ return
261
+ returns
262
+ root
263
+ rule
264
+ rules
265
+ sale
266
+ sample
267
+ samples
268
+ school
269
+ script
270
+ scripts
271
+ search
272
+ secure
273
+ security
274
+ select
275
+ self
276
+ send
277
+ server
278
+ service
279
+ services
280
+ session
281
+ sessions
282
+ setting
283
+ settings
284
+ setup
285
+ set.up
286
+ set-up
287
+ set_up
288
+ sex
289
+ share
290
+ shop
291
+ show
292
+ signin
293
+ sign.in
294
+ sign-in
295
+ sign_in
296
+ signup
297
+ sign.up
298
+ sign-up
299
+ sign_up
300
+ site
301
+ sitemap
302
+ site.map
303
+ site-map
304
+ site_map
305
+ smtp
306
+ sql
307
+ ssh
308
+ ssl
309
+ staff
310
+ start
311
+ static
312
+ status
313
+ store
314
+ stores
315
+ support
316
+ survey
317
+ sys
318
+ system
319
+ tablet
320
+ tag
321
+ talk
322
+ task
323
+ task
324
+ tech
325
+ terms
326
+ test
327
+ testuser
328
+ test.user
329
+ test-user
330
+ test_user
331
+ tit
332
+ tmp
333
+ todo
334
+ tool
335
+ tools
336
+ top
337
+ topic
338
+ topics
339
+ tosser
340
+ trends
341
+ tutorial
342
+ tv
343
+ twat
344
+ update
345
+ upload
346
+ url
347
+ usage
348
+ use
349
+ user
350
+ username
351
+ user.name
352
+ user-name
353
+ user_name
354
+ users
355
+ uucp
356
+ vagina
357
+ version
358
+ video
359
+ videos
360
+ visitor
361
+ watch
362
+ web
363
+ webmail
364
+ web.mail
365
+ web-mail
366
+ web_mail
367
+ website
368
+ web.site
369
+ web-site
370
+ web_site
371
+ whore
372
+ wiki
373
+ win
374
+ word
375
+ wtf
376
+ www
377
+ xml
378
+ xpg
379
+ xxx
380
+ xxxx
381
+ you
382
+ yourname
383
+ your.name
384
+ your-name
385
+ your_name
386
+ yourusername
387
+ your.username
388
+ your-username
389
+ your_username
390
+ ]
@@ -0,0 +1,3 @@
1
+ module RereValidator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,38 @@
1
+ require "rere_validator/version"
2
+ require "rere_validator/reserved_words"
3
+
4
+ class RegexReservedValidator < ActiveModel::EachValidator
5
+ DEFAULT_MESSAGE = {
6
+ :invalid_characters => "can't contain invalid characters",
7
+ :invalid_characters_at_begin => "can't begin with '.', '-', '_'",
8
+ :invalid_characters_at_end => "can't end with '.', '-', '_'",
9
+ :reserved_words => "can't be used a reserved words"
10
+ }.freeze
11
+
12
+ def validate_each(record, attribute, value)
13
+ if reserved?(value)
14
+ add_error(record, attribute, :reserved_words)
15
+ end
16
+
17
+ if value !~ /\A[a-zA-Z0-9_.-]+\z/
18
+ add_error(record, attribute, :invalid_characters)
19
+ elsif value.match(/\A[_.-].*\z/)
20
+ add_error(record, attribute, :invalid_characters_at_begin)
21
+ elsif value.match(/\A.*[_.-]\z/)
22
+ add_error(record, attribute, :invalid_characters_at_end)
23
+ end
24
+ end
25
+
26
+ def add_error(record, attr_name, message)
27
+ message_options = {
28
+ default: [DEFAULT_MESSAGE[message], options[:message]],
29
+ scope: [:errors, :messages]
30
+ }
31
+ record.errors.add(attr_name, I18n.t(message, message_options))
32
+ end
33
+
34
+ def reserved?(value)
35
+ add_reserved_words = @options[:add_reserved_words] || []
36
+ (RESERVED_WORDS + add_reserved_words).include?(value.downcase)
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rere_validator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rere_validator"
8
+ spec.version = RereValidator::VERSION
9
+ spec.authors = ["Natsuki Tanaka"]
10
+ spec.email = ["natsukia3@gmail.com"]
11
+
12
+ spec.summary = %q{Provides regex and reserved words to username.}
13
+ spec.description = %q{Provides regex and reserved words to username.}
14
+ spec.homepage = "https://github.com/natsukia3/rere_validator"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'activemodel'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rere_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Natsuki Tanaka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Provides regex and reserved words to username.
70
+ email:
71
+ - natsukia3@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/rere_validator.rb
86
+ - lib/rere_validator/reserved_words.rb
87
+ - lib/rere_validator/version.rb
88
+ - rere_validator.gemspec
89
+ homepage: https://github.com/natsukia3/rere_validator
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.4
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Provides regex and reserved words to username.
113
+ test_files: []