reserved_for 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d608343647f8681e232c06f79c9bbb7cef54f67
4
+ data.tar.gz: 00c6f6ebc1a9f07cd829f66c28148953a5d738c6
5
+ SHA512:
6
+ metadata.gz: 61015d9e3db612f620ad0ac926dd7fd7b50b957a3b33db5657a3f877ce749f03fed4be0279e11cf6dbaa4597819062491df14701654ff9e0fed8174f12fcc951
7
+ data.tar.gz: 59c663370b00ae5ce21bc2f95f6fca384ac8edc51e27b07b4125d5db9e30d4eca7139312a3b4d94f6e58695fcfe63671b4da1d4b29a3a60b60fc79a65185a4d8
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ script: bundle exec rspec
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reserved_for.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 fukayatsu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,116 @@
1
+ # ReservedFor
2
+
3
+ Make word reserved
4
+
5
+ [![Build Status](https://travis-ci.org/pocake/reserved_for.png?branch=master)](https://travis-ci.org/pocake/reserved_for)
6
+ [![Coverage Status](https://coveralls.io/repos/pocake/reserved_for/badge.png)](https://coveralls.io/r/pocake/reserved_for)
7
+ [![Code Climate](https://codeclimate.com/github/pocake/reserved_for.png)](https://codeclimate.com/github/pocake/reserved_for)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'reserved_for'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install reserved_for
22
+
23
+ ## Usage
24
+
25
+ ### with default username list
26
+ `ReservedFor.usernames` is mostly based on [知見 - 登録されるとつらいユーザー名リスト - Qiita](http://qiita.com/phimcall/items/4c559b70f70ea7f1953b)
27
+
28
+ thanks! [@phimcall](https://github.com/phimcall)
29
+
30
+ ```ruby
31
+ require 'reserved_for'
32
+
33
+ # at anywhere
34
+ ReservedFor.usernames.include?('index') #=> true
35
+ ReservedFor.any.include?('index') #=> true
36
+
37
+ ReservedFor.foo_undefined_list.include?('index') #=> false
38
+ ```
39
+
40
+ ### set your own reserved list
41
+
42
+ ```ruby
43
+ require 'reserved_for'
44
+
45
+ # removes all reserved-list(including default username list) if you want
46
+ ReservedFor.clear_all!
47
+ ReservedFor.usernames.empty? #=> true
48
+
49
+ ReservedFor.your_reserved_list = %w(alice bob)
50
+
51
+ # at anywhere
52
+ ReservedFor.your_reserved_list.include?('alice') #=> true
53
+ ReservedFor.any.include?('alice') #=> true
54
+ ReservedFor.any.include?('charlie') #=> false
55
+ ```
56
+
57
+ ### String extension
58
+ ```ruby
59
+ require 'reserved_for/string' # instead of require 'reserved_for'
60
+
61
+ # at anywhere
62
+ 'index'.reserved_for_usernames? #=> true
63
+ 'index'.reserved_for_any? #=> true
64
+ 'index'.reserved_for? #=> true (a alias of '#reserved_for_any?')
65
+
66
+ 'not_reserved_word'.reserved_for? #=> false
67
+ ```
68
+
69
+ ### Whitelist
70
+
71
+ whitelist affects `ReservedFor.any` and `String#reserved_for_any?`
72
+
73
+ ```ruby
74
+ require 'reserved_for'
75
+
76
+ ReservedFor.clear_all!
77
+ ReservedFor.my_list = %w(a b)
78
+ ReservedFor.whitelist = %w(b)
79
+
80
+ ReservedFor.my_list.include?('b') #=> true
81
+ ReservedFor.whitelist.include?('b') #=> true
82
+ ReservedFor.any.include?('b') #=> false
83
+
84
+ # you can ignore whitelist temporary
85
+ ReservedFor.any(whitelist: false).include?('b') #=> true
86
+
87
+ ```
88
+
89
+ ### Configure(experimental)
90
+ ```ruby
91
+ require 'reserved_for'
92
+
93
+ ReservedFor.configure do |config|
94
+ # use default-list(only .usernames for now) or not
95
+ config.use_default_reserved_list = false # default: true
96
+
97
+ # this option require 'active_support'
98
+ config.check_plural = true # default: false
99
+ end
100
+
101
+
102
+ ReservedFor.usernames.empty? #=> true
103
+
104
+ ReservedFor.fruits = %w(apple)
105
+ ReservedFor.fruits.include?('apple') #=> true
106
+ ReservedFor.fruits.include?('apples') #=> true
107
+ ```
108
+
109
+
110
+ ## Contributing
111
+
112
+ 1. Fork it ( http://github.com/pocake/reserved_for/fork )
113
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
114
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
115
+ 4. Push to the branch (`git push origin my-new-feature`)
116
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,518 @@
1
+ 0
2
+ about
3
+ ac
4
+ account
5
+ activity
6
+ ad
7
+ add
8
+ admin
9
+ ae
10
+ aero
11
+ af
12
+ ag
13
+ ai
14
+ al
15
+ all
16
+ alpha
17
+ am
18
+ an
19
+ analysis
20
+ ao
21
+ api
22
+ app
23
+ aq
24
+ ar
25
+ archive
26
+ arpa
27
+ article
28
+ as
29
+ asct
30
+ asset
31
+ at
32
+ atom
33
+ au
34
+ auth
35
+ aw
36
+ ax
37
+ az
38
+ ba
39
+ balancer-manager
40
+ bb
41
+ bd
42
+ be
43
+ beta
44
+ bf
45
+ bg
46
+ bh
47
+ bi
48
+ biz
49
+ bj
50
+ blog
51
+ bm
52
+ bn
53
+ bo
54
+ book
55
+ bookmark
56
+ bot
57
+ br
58
+ bs
59
+ bt
60
+ bug
61
+ business
62
+ bv
63
+ bw
64
+ by
65
+ bz
66
+ ca
67
+ calendar
68
+ call
69
+ captcha
70
+ career
71
+ cart
72
+ case
73
+ cat
74
+ category
75
+ cc
76
+ cd
77
+ cf
78
+ cg
79
+ cgi
80
+ cgi-bin
81
+ ch
82
+ ci
83
+ ck
84
+ cl
85
+ cm
86
+ cn
87
+ co
88
+ code
89
+ com
90
+ comment
91
+ community
92
+ company
93
+ config
94
+ connect
95
+ contact
96
+ contest
97
+ contribute
98
+ coop
99
+ corp
100
+ count
101
+ cr
102
+ create
103
+ cs
104
+ css
105
+ cu
106
+ cv
107
+ cx
108
+ cy
109
+ cz
110
+ dashboard
111
+ data
112
+ dd
113
+ de
114
+ default
115
+ delete
116
+ design
117
+ destroy
118
+ developer
119
+ dev
120
+ diagram
121
+ diary
122
+ dictionary
123
+ dict
124
+ die
125
+ dir
126
+ dist
127
+ dj
128
+ dk
129
+ dm
130
+ do
131
+ doc
132
+ download
133
+ dz
134
+ ec
135
+ edit
136
+ edu
137
+ ee
138
+ eg
139
+ eh
140
+ else
141
+ empty
142
+ end
143
+ entry
144
+ er
145
+ error
146
+ es
147
+ et
148
+ eu
149
+ eval
150
+ event
151
+ exit
152
+ explore
153
+ faq
154
+ feature
155
+ feed
156
+ fi
157
+ file
158
+ find
159
+ first
160
+ fj
161
+ fk
162
+ flash
163
+ fm
164
+ fo
165
+ forgot
166
+ form
167
+ forum
168
+ fr
169
+ friend
170
+ ga
171
+ game
172
+ gb
173
+ gd
174
+ ge
175
+ get
176
+ gf
177
+ gg
178
+ gh
179
+ gi
180
+ gift
181
+ gl
182
+ gm
183
+ gn
184
+ gov
185
+ gp
186
+ gq
187
+ gr
188
+ graph
189
+ group
190
+ gs
191
+ gt
192
+ gu
193
+ guest
194
+ gw
195
+ gy
196
+ help
197
+ hk
198
+ hm
199
+ hn
200
+ home
201
+ howto
202
+ hr
203
+ ht
204
+ hu
205
+ i
206
+ my
207
+ me
208
+ icon
209
+ id
210
+ ie
211
+ if
212
+ il
213
+ im
214
+ image
215
+ img
216
+ in
217
+ index
218
+ info
219
+ information
220
+ inquiry
221
+ int
222
+ io
223
+ iq
224
+ ir
225
+ is
226
+ issue
227
+ it
228
+ item
229
+ javascript
230
+ je
231
+ jm
232
+ jo
233
+ job
234
+ join
235
+ jp
236
+ js
237
+ json
238
+ jump
239
+ ke
240
+ kg
241
+ kh
242
+ ki
243
+ km
244
+ kn
245
+ kp
246
+ kr
247
+ kw
248
+ ky
249
+ kz
250
+ la
251
+ language
252
+ last
253
+ lb
254
+ lc
255
+ ldap-status
256
+ legal
257
+ li
258
+ license
259
+ lk
260
+ log
261
+ login
262
+ logout
263
+ lr
264
+ ls
265
+ lt
266
+ lu
267
+ lv
268
+ ly
269
+ ma
270
+ mail
271
+ maintenance
272
+ manual
273
+ master
274
+ mc
275
+ md
276
+ member
277
+ message
278
+ msg
279
+ mg
280
+ mh
281
+ mil
282
+ mk
283
+ ml
284
+ mm
285
+ mn
286
+ mo
287
+ mobi
288
+ mobile
289
+ mp
290
+ mq
291
+ mr
292
+ ms
293
+ mt
294
+ mu
295
+ museum
296
+ mv
297
+ mw
298
+ mx
299
+ mz
300
+ na
301
+ name
302
+ nan
303
+ navigation
304
+ navi
305
+ nc
306
+ ne
307
+ net
308
+ new
309
+ news
310
+ nf
311
+ ng
312
+ ni
313
+ nl
314
+ no
315
+ notify
316
+ np
317
+ nr
318
+ nu
319
+ null
320
+ nz
321
+ off
322
+ offer
323
+ official
324
+ old
325
+ om
326
+ on
327
+ or
328
+ order
329
+ org
330
+ organization
331
+ out
332
+ owner
333
+ pa
334
+ page
335
+ password
336
+ pe
337
+ pf
338
+ pg
339
+ ph
340
+ phone
341
+ photo
342
+ pk
343
+ pl
344
+ plan
345
+ pm
346
+ pn
347
+ policy
348
+ popular
349
+ portal
350
+ post
351
+ pr
352
+ premium
353
+ press
354
+ price
355
+ privacy
356
+ private
357
+ pro
358
+ product
359
+ profile
360
+ project
361
+ ps
362
+ pt
363
+ public
364
+ purpose
365
+ put
366
+ pw
367
+ py
368
+ qa
369
+ query
370
+ ranking
371
+ re
372
+ read
373
+ recent
374
+ recruit
375
+ register
376
+ release
377
+ remove
378
+ report
379
+ repository
380
+ request
381
+ req
382
+ reset
383
+ ro
384
+ roc
385
+ root
386
+ rs
387
+ rss
388
+ ru
389
+ rule
390
+ rw
391
+ sa
392
+ sag
393
+ sb
394
+ sc
395
+ school
396
+ script
397
+ sd
398
+ se
399
+ search
400
+ secure
401
+ security
402
+ select
403
+ self
404
+ server-info
405
+ server-status
406
+ service
407
+ session
408
+ setting
409
+ sg
410
+ sh
411
+ share
412
+ shop
413
+ show
414
+ si
415
+ signin
416
+ signout
417
+ signup
418
+ site
419
+ sitemap
420
+ sj
421
+ sk
422
+ sl
423
+ sm
424
+ sn
425
+ so
426
+ source
427
+ spec
428
+ special
429
+ sr
430
+ src
431
+ st
432
+ start
433
+ static
434
+ status
435
+ state
436
+ store
437
+ stylesheet
438
+ style
439
+ su
440
+ support
441
+ sv
442
+ svn
443
+ swf
444
+ switch
445
+ sy
446
+ system
447
+ sys
448
+ sz
449
+ tag
450
+ tc
451
+ td
452
+ tel
453
+ term
454
+ test
455
+ tf
456
+ tg
457
+ th
458
+ theme
459
+ then
460
+ thread
461
+ tj
462
+ tk
463
+ tl
464
+ tm
465
+ tn
466
+ to
467
+ tool
468
+ top
469
+ topic
470
+ tour
471
+ tp
472
+ tr
473
+ travel
474
+ tt
475
+ tutorial
476
+ tux
477
+ tv
478
+ tw
479
+ tz
480
+ ua
481
+ ug
482
+ uk
483
+ um
484
+ undef
485
+ update
486
+ upload
487
+ us
488
+ usage
489
+ user
490
+ uy
491
+ uz
492
+ va
493
+ vc
494
+ ve
495
+ version
496
+ ver
497
+ vg
498
+ vi
499
+ video
500
+ vn
501
+ vu
502
+ watch
503
+ wf
504
+ when
505
+ widget
506
+ wiki
507
+ word
508
+ ws
509
+ www
510
+ xml
511
+ ye
512
+ year
513
+ yt
514
+ yu
515
+ za
516
+ zm
517
+ zr
518
+ zw
@@ -0,0 +1,83 @@
1
+ require "reserved_for/version"
2
+ require 'active_support/inflector'
3
+ require 'ostruct'
4
+
5
+ module ReservedFor
6
+ class InvalidOptionError < StandardError; end
7
+ module ModuleMethods
8
+
9
+ def clear_all!
10
+ @reserved_list_map = { whitelist: Set.new }
11
+ self
12
+ end
13
+
14
+ def reset!(reset_option: true)
15
+ clear_all!
16
+ @options = nil if reset_option
17
+ if options[:use_default_reserved_list]
18
+ plurals = _default_usernames.map{ |word| ActiveSupport::Inflector.pluralize(word) }
19
+ @reserved_list_map[:usernames] = _default_usernames
20
+ @reserved_list_map[:_plurals_usernames] = Set.new(plurals)
21
+ end
22
+ self
23
+ end
24
+
25
+ def configure(options = {}, &block)
26
+ config = OpenStruct.new
27
+ block.call(config)
28
+ @options = _default_config
29
+ .merge(options)
30
+ .merge(Hash[config.each_pair.map{ |k,v| [k, v] }])
31
+
32
+ invalid_options = @options.keys - _default_config.keys
33
+ raise ReservedFor::InvalidOptionError, "invalid options: #{invalid_options}" if invalid_options.size > 0
34
+ reset!(reset_option: false)
35
+ self
36
+ end
37
+
38
+ def options
39
+ @options ||= _default_config
40
+ end
41
+
42
+ def any(whitelist: true)
43
+ set = @reserved_list_map.map{ |k, v|
44
+ next v if options[:check_plural]
45
+ next nil if k =~ /^_plurals_/
46
+ v
47
+ }.compact.inject(:+)
48
+ set -= @reserved_list_map[:whitelist] if whitelist
49
+ set
50
+ end
51
+
52
+ def method_missing(name, *args)
53
+ case name.to_s
54
+ when /(.*)=$/
55
+ args = args.flatten
56
+ plurals = args.map{ |arg| ActiveSupport::Inflector.pluralize(arg) }
57
+ @reserved_list_map[$1.to_sym] = Set.new(args)
58
+ @reserved_list_map["_plurals_#{$1}".to_sym] = Set.new(plurals)
59
+ else
60
+ set = @reserved_list_map[name.to_sym]
61
+ return nil unless set
62
+ set += @reserved_list_map["_plurals_#{name.to_s}".to_sym] if options[:check_plural]
63
+ set
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def _default_usernames
70
+ File.open("#{__dir__}/../config/USERNAMES").read.split("\n")
71
+ end
72
+
73
+ def _default_config
74
+ {
75
+ use_default_reserved_list: true,
76
+ check_plural: false,
77
+ }
78
+ end
79
+ end
80
+
81
+ extend ModuleMethods
82
+ reset!
83
+ end
@@ -0,0 +1,22 @@
1
+ require 'reserved_for'
2
+
3
+ module ReservedFor
4
+ module MethodMissing
5
+ def method_missing(name, *args)
6
+ if name.to_s =~ /^reserved_for_(.*)\?$/
7
+ ReservedFor.public_send($1.to_sym).include?(self)
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ class String
16
+ def reserved_for_any?
17
+ ReservedFor.any.include?(self)
18
+ end
19
+ alias :reserved_for? :reserved_for_any?
20
+
21
+ prepend ReservedFor::MethodMissing
22
+ end
@@ -0,0 +1,3 @@
1
+ module ReservedFor
2
+ VERSION = "0.0.1"
3
+ 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 'reserved_for/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reserved_for"
8
+ spec.version = ReservedFor::VERSION
9
+ spec.authors = ["fukayatsu"]
10
+ spec.email = ["fukayatsu@gmail.com"]
11
+ spec.summary = %q{Make any word to be reserved}
12
+ spec.description = %q{Make any word to be reserved}
13
+ spec.homepage = "https://github.com/pocake/reserved_for"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport", ">= 3.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta2"
26
+ spec.add_development_dependency "coveralls"
27
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+ require 'reserved_for/string'
3
+
4
+ describe "String" do
5
+ before do
6
+ ReservedFor.clear_all!
7
+ ReservedFor.usernames = %w(alice bob charlie david)
8
+ ReservedFor.group_names = %w(root wheel)
9
+ ReservedFor.whitelist = %w(david)
10
+ end
11
+
12
+ describe '#reserved_for?' do
13
+ it 'alice is reserved' do
14
+ expect('alice'.reserved_for?).to be true
15
+ end
16
+ it 'foo is not reserved' do
17
+ expect('foo'.reserved_for?).to be false
18
+ end
19
+ it 'david is whitelisted' do
20
+ expect('david'.reserved_for?).to be false
21
+ end
22
+ it 'alias reserved_for_any' do
23
+ expect('david'.reserved_for_any?).to be false
24
+ end
25
+ end
26
+
27
+ describe '#reserved_for_[defined_list]?' do
28
+ it 'alice is reserved_for_usernames' do
29
+ expect('alice'.reserved_for_usernames?).to be true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,135 @@
1
+ require "spec_helper"
2
+ require 'reserved_for'
3
+
4
+ describe ReservedFor do
5
+ context 'default list' do
6
+ describe 'default usernames' do
7
+ it 'should includes "index"' do
8
+ expect(ReservedFor.reset!.usernames.include?('index')).to be true
9
+ end
10
+ end
11
+ end
12
+
13
+ context 'custom list' do
14
+ before do
15
+ ReservedFor.reset!
16
+ ReservedFor.usernames = %w(alice bob charlie david)
17
+ ReservedFor.group_names = %w(root wheel)
18
+ ReservedFor.whitelist = %w(david)
19
+ end
20
+
21
+ describe '.[definded_list]' do
22
+ it 'should return set of reserved word' do
23
+ expect(ReservedFor.usernames).to eq Set.new(%w(alice bob charlie david))
24
+ end
25
+ end
26
+
27
+ describe '.[undefined_list]' do
28
+ it 'should return nil' do
29
+ expect(ReservedFor.undefined_list_foo).to be_nil
30
+ end
31
+ end
32
+
33
+ describe '.any' do
34
+ it 'should return all reserved word excluding whitelist' do
35
+ expect(ReservedFor.any).to eq Set.new(%w(alice bob charlie root wheel))
36
+ end
37
+ it 'should return all reserved ignoring whitelist' do
38
+ expect(ReservedFor.any(whitelist: false)).to eq Set.new(%w(alice bob charlie david root wheel))
39
+ end
40
+ end
41
+
42
+ describe '.clear_all!' do
43
+ it 'should clear all reserved list and white list' do
44
+ ReservedFor.clear_all!
45
+ expect(ReservedFor.any).to be_empty
46
+ expect(ReservedFor.whitelist).to be_empty
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '.configure' do
52
+ it 'has default config' do
53
+ ReservedFor.configure do |config|
54
+ # do nothing
55
+ end
56
+ expect(ReservedFor.options).to eq({
57
+ use_default_reserved_list: true,
58
+ check_plural: false,
59
+ })
60
+ end
61
+
62
+ it 'can set config' do
63
+ ReservedFor.configure do |config|
64
+ config.use_default_reserved_list = false
65
+ config.check_plural = true
66
+ end
67
+ expect(ReservedFor.options).to eq({
68
+ use_default_reserved_list: false,
69
+ check_plural: true,
70
+ })
71
+ end
72
+
73
+ it 'raise error for invalid option name' do
74
+ expect {
75
+ ReservedFor.configure do |config|
76
+ config.invalid_option_name_foo = true
77
+ end
78
+ }.to raise_error(ReservedFor::InvalidOptionError, 'invalid options: [:invalid_option_name_foo]')
79
+ end
80
+ end
81
+
82
+ context 'use_default_reserved_list' do
83
+ context 'enabled' do
84
+ before do
85
+ ReservedFor.configure do |config|
86
+ config.use_default_reserved_list = true
87
+ end
88
+ end
89
+ it 'should contain something' do
90
+ expect(ReservedFor.any).not_to be_empty
91
+ end
92
+ end
93
+
94
+ context 'disabled' do
95
+ before do
96
+ ReservedFor.configure do |config|
97
+ config.use_default_reserved_list = false
98
+ end
99
+ end
100
+ it 'should be empty' do
101
+ expect(ReservedFor.any).to be_empty
102
+ end
103
+ end
104
+ end
105
+
106
+ context 'plural' do
107
+ context 'enabled' do
108
+ before do
109
+ ReservedFor.configure do |config|
110
+ config.check_plural = true
111
+ end
112
+ ReservedFor.fruits = %(apple)
113
+ end
114
+
115
+ it {
116
+ expect(ReservedFor.fruits.include?('apple')).to be true
117
+ expect(ReservedFor.fruits.include?('apples')).to be true
118
+ }
119
+ end
120
+
121
+ context 'disabled' do
122
+ before do
123
+ ReservedFor.configure do |config|
124
+ config.check_plural = false
125
+ end
126
+ ReservedFor.fruits = %(apple)
127
+ end
128
+
129
+ it {
130
+ expect(ReservedFor.fruits.include?('apple')).to be true
131
+ expect(ReservedFor.fruits.include?('apples')).to be false
132
+ }
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,66 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ RSpec.configure do |config|
5
+ # These two settings work together to allow you to limit a spec run
6
+ # to individual examples or groups you care about by tagging them with
7
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
8
+ # get run.
9
+ config.filter_run :focus
10
+ config.run_all_when_everything_filtered = true
11
+
12
+ # Many RSpec users commonly either run the entire suite or an individual
13
+ # file, and it's useful to allow more verbose output when running an
14
+ # individual spec file.
15
+ if config.files_to_run.one?
16
+ # RSpec filters the backtrace by default so as not to be so noisy.
17
+ # This causes the full backtrace to be printed when running a single
18
+ # spec file (e.g. to troubleshoot a particular spec failure).
19
+ config.full_backtrace = true
20
+
21
+ # Use the documentation formatter for detailed output,
22
+ # unless a formatter has already been configured
23
+ # (e.g. via a command-line flag).
24
+ config.formatter = 'doc' if config.formatters.none?
25
+ end
26
+
27
+ # Print the 10 slowest examples and example groups at the
28
+ # end of the spec run, to help surface which specs are running
29
+ # particularly slow.
30
+ config.profile_examples = 10
31
+
32
+ # Run specs in random order to surface order dependencies. If you find an
33
+ # order dependency and want to debug it, you can fix the order by providing
34
+ # the seed, which is printed after each run.
35
+ # --seed 1234
36
+ config.order = :random
37
+
38
+ # Seed global randomization in this process using the `--seed` CLI option.
39
+ # Setting this allows you to use `--seed` to deterministically reproduce
40
+ # test failures related to randomization by passing the same `--seed` value
41
+ # as the one that triggered the failure.
42
+ Kernel.srand config.seed
43
+
44
+ # rspec-expectations config goes here. You can use an alternate
45
+ # assertion/expectation library such as wrong or the stdlib/minitest
46
+ # assertions if you prefer.
47
+ config.expect_with :rspec do |expectations|
48
+ # Enable only the newer, non-monkey-patching expect syntax.
49
+ # For more details, see:
50
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
51
+ expectations.syntax = :expect
52
+ end
53
+
54
+ # rspec-mocks config goes here. You can use an alternate test double
55
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
56
+ config.mock_with :rspec do |mocks|
57
+ # Enable only the newer, non-monkey-patching expect syntax.
58
+ # For more details, see:
59
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
+ mocks.syntax = :expect
61
+
62
+ # Prevents you from mocking or stubbing a method that does not exist on
63
+ # a real object. This is generally recommended.
64
+ mocks.verify_partial_doubles = true
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reserved_for
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fukayatsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.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.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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.0.beta2
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.0.beta2
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Make any word to be reserved
84
+ email:
85
+ - fukayatsu@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".coveralls.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - config/USERNAMES
99
+ - lib/reserved_for.rb
100
+ - lib/reserved_for/string.rb
101
+ - lib/reserved_for/version.rb
102
+ - reserved_for.gemspec
103
+ - spec/reserved_for/string_spec.rb
104
+ - spec/reserved_for_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/pocake/reserved_for
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.0
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Make any word to be reserved
130
+ test_files:
131
+ - spec/reserved_for/string_spec.rb
132
+ - spec/reserved_for_spec.rb
133
+ - spec/spec_helper.rb