ngwords 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8597c1279bb002b6e362fd1000e33cdf6b1c4ba4
4
+ data.tar.gz: 3e13e8724e97ebceed2b3cc39e2a1b91576d7995
5
+ SHA512:
6
+ metadata.gz: 9cc70d0bf7aa05b4dd25615c9edb2425c8630ff4f8171c1ec79cf1c7304e73b9a4e4f17642672cc1fb11c13c8f58ba842470ec5836c071819ee1ddaf1ea38bf0
7
+ data.tar.gz: ecb8f890923d1d74747eaeac0fd6e45fac023dd48954b504059b7a239136e069fe8b16720bab6314c6c9d62551c50e7af4ffbadc26c714ab5324a82757fe4924
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 chitamano
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,74 @@
1
+ # Ngwords
2
+ Ngwords prevents prohibited words from being registered in your application. The prohibited word list can be set in the YAML data format. Ngwords currently only works with Rails.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'ngwords'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ $ gem install ngwords
19
+ ```
20
+ ## Usage
21
+
22
+ #### 1. Create your settings in `config/ngwords.yml`
23
+
24
+ ```yml
25
+ defaults: &defaults
26
+ en:
27
+ - shit
28
+ - id password input
29
+ ja:
30
+ - 白痴
31
+ - ID パスワード 入力
32
+
33
+ development:
34
+ <<: *defaults
35
+
36
+ test:
37
+ <<: *defaults
38
+
39
+ production:
40
+ <<: *defaults
41
+ ```
42
+
43
+ Block of `en` is a list of prohibited words for space-separated languages ​​such as English. The block in `ja` is for non-space delimited languages ​​such as Japanese.
44
+
45
+ Note: To prevent data registration when all words are included, set prohibited words with a space delimiter like `id password input`.
46
+
47
+ #### 2. Add `ngwords: true` to your model's validates method
48
+
49
+ ```ruby
50
+ class Post < ApplicationRecord
51
+ validates :title, presence: true, ngwords: true
52
+ validates :body, ngwords: true
53
+ end
54
+ ```
55
+
56
+ Note: If you want to customize the error message, set your locale setting file (e.g.: `config/locales/ja.yml`) as follows.
57
+
58
+ ```yml
59
+ ja:
60
+ activerecord:
61
+ errors:
62
+ messages:
63
+ includes_ngwords: "は禁止単語を含んでいます。"
64
+ ```
65
+
66
+ ## Contributing
67
+ 1. Fork it ( https://github.com/chitamano/ngwords/fork )
68
+ 2. Create your feature branch (git checkout -b my-new-feature)
69
+ 3. Commit your changes (git commit -am 'Add some feature')
70
+ 4. Push to the branch (git push origin my-new-feature)
71
+ 5. Create new Pull Request
72
+
73
+ ## License
74
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Ngwords'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,8 @@
1
+ require 'settingslogic'
2
+
3
+ module Ngwords
4
+ class Settings < Settingslogic
5
+ source "#{Rails.root}/config/ngwords.yml"
6
+ namespace Rails.env
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Ngwords
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'ngwords' do |_app|
4
+ ActiveSupport.on_load :after_initialize do
5
+ require 'ngwords/config'
6
+ require 'ngwords/validator'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ require 'moji'
2
+
3
+ module ActiveModel
4
+ module Validations
5
+ class NgwordsValidator < EachValidator
6
+ @@ngwords = nil
7
+
8
+ def validate_each(record, attribute, value)
9
+ return if value.blank?
10
+ if Moji.normalize_zen_han(value) =~ ngwords
11
+ record.errors.add(attribute, I18n.t('activerecord.errors.messages.includes_ngwords', default: 'includes prohibited words.'))
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def ngwords
18
+ return @@ngwords unless @@ngwords.nil?
19
+ ngwords = []
20
+ Ngwords::Settings.each do |lang, list|
21
+ delim = lang == :en ? '\\b' : ''
22
+ Array(list).reject(&:blank?).each do |ngword|
23
+ escaped_ngword = ngword.split(/\p{blank}/).reject(&:blank?).map { |word| '(?=.*' + delim + Regexp.escape(word) + delim + ')' }.join('')
24
+ ngwords.push(Regexp.compile("^#{escaped_ngword}", Regexp::IGNORECASE))
25
+ end
26
+ end
27
+ @@ngwords = Regexp.union(ngwords)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Ngwords
2
+ VERSION = '0.1.0'
3
+ end
data/lib/ngwords.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ngwords/railtie'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ngwords do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ngwords
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - chitamano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: moji
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: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: settingslogic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ngwords prevents prohibited words from being registered in your application.
70
+ The prohibited word list can be set in the YAML data format. Ngwords currently only
71
+ works with Rails.
72
+ email:
73
+ - yonesuke3000@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - MIT-LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ngwords.rb
82
+ - lib/ngwords/config.rb
83
+ - lib/ngwords/railtie.rb
84
+ - lib/ngwords/validator.rb
85
+ - lib/ngwords/version.rb
86
+ - lib/tasks/ngwords_tasks.rake
87
+ homepage: https://github.com/chitamano/ngwords
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: '0'
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.6.14
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ngwords prevents prohibited words from being registered in your application.
111
+ test_files: []