reserved_word 0.0.1

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: 22df250a4b028930ceae8357e9377e257f133289
4
+ data.tar.gz: 68bf4f8183ec51d36e39cf5a6768a51d02b1927a
5
+ SHA512:
6
+ metadata.gz: 3d64678625c4e22dc03247d735d10da634c27e419d72f8c5f2edf97e87ce80db160422fb1fdd17c40014cb6320d6c9d7e89e25989d13fa6287b35477242c2806
7
+ data.tar.gz: 519598af291f51b775c9e4dc14889d06fc346c703c764124c2fb6c5e181cf20b81772a3cf8f9066902ea2b296fad7e07f57c8612ced69d145502c5fcb6355c98
data/.gitignore ADDED
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reserved_word.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 rono23
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.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # ReservedWord
2
+
3
+ Make your reserved words on Rails.
4
+
5
+ For example, when you make a nickname is used example.com/nickname, you may validate some nicknames (e.g. about, faq etc). ReservedWord reserves a kind of words.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'reserved_word'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install reserved_word
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ # app/model/user.rb
25
+ before_validation { nickname.downcase! } # disable case sensitive if you want
26
+ validates :nickname, exclusion: { in: ReservedWord.list }
27
+
28
+ # Setup your reserved words on config/initializers/reserved_word.rb
29
+ ReservedWord.your_words = %w(foo bar)
30
+
31
+ # then use anywhere
32
+ ReservedWord.your_words.include?("foo") #=> true
33
+
34
+ # model
35
+ validates :nickname, exclusion: { in: ReservedWord.your_words }
36
+
37
+
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module ReservedWord
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,98 @@
1
+ ReservedWord::Word::SITE_SLUG = %w(
2
+ about
3
+ access
4
+ android
5
+ api
6
+ apps
7
+ atom
8
+ blog
9
+ career
10
+ categories
11
+ category
12
+ clients
13
+ communities
14
+ community
15
+ company
16
+ contact
17
+ contact-us
18
+ contact_us
19
+ contactus
20
+ dashboard
21
+ download
22
+ edu
23
+ education
24
+ enterprise
25
+ faq
26
+ feature
27
+ features
28
+ feed
29
+ feedback
30
+ founder
31
+ home
32
+ info
33
+ information
34
+ inquiry
35
+ iphone
36
+ job
37
+ jobs
38
+ language
39
+ languages
40
+ legal
41
+ license
42
+ link
43
+ links
44
+ linux
45
+ log-in
46
+ log-out
47
+ log_in
48
+ log_out
49
+ login
50
+ logout
51
+ mac
52
+ member
53
+ members
54
+ mobile
55
+ news
56
+ overview
57
+ page
58
+ pages
59
+ payment
60
+ plan
61
+ policy
62
+ press
63
+ price
64
+ pricing
65
+ privacy
66
+ privacy-policy
67
+ privacy_policy
68
+ privacypolicy
69
+ rss
70
+ search
71
+ service
72
+ services
73
+ sign-in
74
+ sign-up
75
+ sign_in
76
+ sign_up
77
+ signin
78
+ signup
79
+ sitemap
80
+ smartphone
81
+ staff
82
+ status
83
+ support
84
+ team
85
+ terms
86
+ terms-of-service
87
+ terms_of_service
88
+ termsofservice
89
+ top
90
+ tutorial
91
+ usage
92
+ user
93
+ users
94
+ welcome
95
+ windows
96
+ work
97
+ works
98
+ )
@@ -0,0 +1,6 @@
1
+ module ReservedWord
2
+ module Word
3
+ end
4
+ end
5
+
6
+ Dir[File.dirname(__FILE__) + "/word/*.rb"].each { |file| require file }
@@ -0,0 +1,60 @@
1
+ require "active_support/all"
2
+ require "reserved_word/version"
3
+ require "reserved_word/word"
4
+
5
+ module ReservedWord
6
+ @words = ActiveSupport::OrderedOptions.new
7
+ @words.default_words = ReservedWord::Word::SITE_SLUG
8
+
9
+ def self.include?(word)
10
+ @words.default_words.include?(word)
11
+ end
12
+
13
+ def self.list
14
+ @words.default_words
15
+ end
16
+
17
+ def self.clear
18
+ @words.default_words = Array.new
19
+ end
20
+
21
+ def self.clear_all
22
+ @words = ActiveSupport::OrderedOptions.new
23
+ self.clear
24
+ end
25
+
26
+ def self.word_list
27
+ ReservedWord::Word.constants.map(&:downcase)
28
+ end
29
+
30
+ def self.all
31
+ @words.to_hash
32
+ end
33
+
34
+ def self.load!(type, key=nil)
35
+ if key == nil
36
+ @words.default_words = load_words(type)
37
+ else
38
+ @words[key] = load_words(type)
39
+ end
40
+ end
41
+
42
+ def self.load_words(type)
43
+ ReservedWord::Word.const_get(type.upcase)
44
+ end
45
+
46
+ def self.method_missing(sym, *args, &block)
47
+ sym = $1.to_sym if sym.to_s =~ /(.*)=$/
48
+ super if ReservedWord.singleton_methods.include? sym
49
+
50
+ if @words[sym] == nil
51
+ if args.first.class == Array
52
+ @words[sym] = args.first
53
+ else
54
+ super
55
+ end
56
+ else
57
+ @words[sym]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reserved_word/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reserved_word"
8
+ spec.version = ReservedWord::VERSION
9
+ spec.authors = ["rono23"]
10
+ spec.email = ["rono23@gmail.com"]
11
+ spec.description = %q{Make your reserved words on Rails}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/rono23/reserved_word"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ spec.add_dependency "rails", ">= 3.2.13"
28
+ end
@@ -0,0 +1,105 @@
1
+ require File.join(File.dirname(__FILE__), '../lib/reserved_word')
2
+
3
+ describe "ReservedWord" do
4
+ before do
5
+ ReservedWord.clear_all
6
+ ReservedWord.load!(:site_slug)
7
+ end
8
+
9
+ it "should have default words" do
10
+ ReservedWord.default_words.should be_kind_of(Array)
11
+ end
12
+
13
+ describe ".include?" do
14
+ it "should include a word in default words" do
15
+ ReservedWord.include?('about').should be_true
16
+ end
17
+
18
+ it "should not include a word in default words" do
19
+ ReservedWord.include?('foo').should be_false
20
+ end
21
+ end
22
+
23
+ describe ".list" do
24
+ it "should return default words" do
25
+ ReservedWord.list.should eq ReservedWord.default_words
26
+ end
27
+ end
28
+
29
+ describe ".clear" do
30
+ it "should clear default words" do
31
+ ReservedWord.clear
32
+ ReservedWord.list.should be_empty
33
+ end
34
+ end
35
+
36
+ describe ".clear_all" do
37
+ it "should clear all words" do
38
+ ReservedWord.foo = %w(bar)
39
+ ReservedWord.clear_all
40
+ ReservedWord.list.should be_empty
41
+ lambda { ReservedWord.foo }.should raise_error
42
+ end
43
+ end
44
+
45
+ describe ".word_list" do
46
+ it "should return the list of ReservedWord::Word" do
47
+ ReservedWord.word_list.should be_kind_of(Array)
48
+ ReservedWord.word_list.include?(:site_slug).should be_true
49
+ end
50
+ end
51
+
52
+ describe ".all" do
53
+ it "should return all words as hash" do
54
+ hash = { default_words: ReservedWord.list }
55
+ ReservedWord.all.should eq hash
56
+ end
57
+
58
+ it "should return all words with original words as hash" do
59
+ words = %w(foo bar)
60
+ hash = { default_words: ReservedWord.list, test: words }
61
+ ReservedWord.test = words
62
+ ReservedWord.all.should eq hash
63
+ end
64
+ end
65
+
66
+ describe ".load!" do
67
+ before { ReservedWord.clear }
68
+
69
+ it "should be loaded one of ReservedWord::Word" do
70
+ ReservedWord.load!(:site_slug)
71
+ ReservedWord.include?('about').should be_true
72
+ end
73
+
74
+ it "should be loaded one of ReservedWord::Word as test" do
75
+ ReservedWord.load!(:site_slug, :test)
76
+ ReservedWord.test.include?('about').should be_true
77
+ end
78
+ end
79
+
80
+ describe ".load_words" do
81
+ it "should return words from ReservedWord::Word" do
82
+ ReservedWord.load_words(:site_slug).should be_kind_of(Array)
83
+ ReservedWord.load_words(:site_slug).include?('about')
84
+ end
85
+ end
86
+
87
+ describe ".method_missing" do
88
+ context 'when new word is set up' do
89
+ before { ReservedWord.new_word = %w(foo bar) }
90
+
91
+ it 'should be accessed' do
92
+ ReservedWord.new_word.should be_kind_of(Array)
93
+ ReservedWord.new_word.include?("foo").should be_true
94
+ ReservedWord.new_word.include?("bar").should be_true
95
+ end
96
+ end
97
+
98
+ context 'when class method is overriden' do
99
+ it 'should raise error' do
100
+ lambda { ReservedWord.all = %w(foo bar) }.should raise_error
101
+ lambda { ReservedWord.list = %w(foo bar) }.should raise_error
102
+ end
103
+ end
104
+ end
105
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reserved_word
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - rono23
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.13
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.13
69
+ description: Make your reserved words on Rails
70
+ email:
71
+ - rono23@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/reserved_word.rb
82
+ - lib/reserved_word/version.rb
83
+ - lib/reserved_word/word.rb
84
+ - lib/reserved_word/word/site_slug.rb
85
+ - reserved_word.gemspec
86
+ - spec/reserved_word_spec.rb
87
+ homepage: https://github.com/rono23/reserved_word
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 1.9.3
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.3
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Make your reserved words on Rails
111
+ test_files:
112
+ - spec/reserved_word_spec.rb
113
+ has_rdoc: