antivirus 0.0.1.pre → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14c3308679f09582dbc8a438372800538cecb5a8
4
- data.tar.gz: ddd8670eaae09032cfa75a5767ff150800b4815a
3
+ metadata.gz: fc1d30d434238df7de4e8f2ec33236e05c70873c
4
+ data.tar.gz: 1d291ce3febb2a348a39a7eb744e46527802254e
5
5
  SHA512:
6
- metadata.gz: d97c1f2b46a53be3c9353b5a509b5b645a737da06e584872cb500a70b7e5e098c6de05aaa11fed8302762995599fdddc211746384da4fbf75455ea843c324926
7
- data.tar.gz: 2ccc757008c3df7cefba9d6ec8d793e1cf280daec5859d9a35551db5a39d6df5fe951728c4262cc58a5f2fa46c5d3ae4e1777c7ada3b4888dc771eed7e874ba2
6
+ metadata.gz: 1bcc885a639317821344ef7d58328a067dc581e4d56e0b59972593d91c9dd1941ac1b1778106a7104913023a8446eea077efb065c2dd4d2fb94209a101a9a11a
7
+ data.tar.gz: 4da1eb5c489bf657e803ca64dc0f8e541b0dcf90f9bc73cece0cb606d9b33d2e4c0aa0fd0140fcdf18b332365e1b7d1a638a1cd8655d144130916b4f012d74eb
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Antivirus
2
+
3
+ [![Build Status](https://travis-ci.org/kami30k/antivirus.svg)](https://travis-ci.org/kami30k/antivirus)
4
+ [![Gem Version](https://badge.fury.io/rb/antivirus.svg)](http://badge.fury.io/rb/antivirus)
5
+
6
+ Antivirus provides a validator which filter profane words for Rails application.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'antivirus'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```
19
+ $ bundle
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Profane words define as array in `config/locales/*.yml`.
25
+ You can define profane words in `antivirus.profane_words`.
26
+
27
+ `antivirus.message` is an error message when target includes profane words.
28
+
29
+ ```yml
30
+ en:
31
+ antivirus:
32
+ message: includes profane words.
33
+ profane_words:
34
+ - foo
35
+ - bar
36
+ - baz
37
+ ```
38
+
39
+ For example, Post model exists like this:
40
+
41
+ ```ruby
42
+ class Post < ActiveRecord::Base
43
+ validates :content, profanity_filter: true
44
+ end
45
+ ```
46
+
47
+ In this case, `post` can't include profane words.
48
+
49
+ ```ruby
50
+ post = Post.create(content: 'foo')
51
+
52
+ post.valid?
53
+ #=> false
54
+
55
+ post.errors.full_messages
56
+ #=> ["Content includes profane words."]
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/kami30k/antivirus/fork )
62
+ 2. Create your feature branch (git checkout -b my-new-feature)
63
+ 3. Commit your changes (git commit -am 'Add some feature')
64
+ 4. Push to the branch (git push origin my-new-feature)
65
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,23 +1,7 @@
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 = 'Antivirus'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
-
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
21
3
 
22
4
  Bundler::GemHelper.install_tasks
23
5
 
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module Antivirus
4
+ class Railtie < ::Rails::Railtie
5
+ initializer 'antivirus' do
6
+ ActiveSupport.on_load :active_record do
7
+ ActiveRecord::Base.send :include, Validator
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module Antivirus
2
+ module Validator
3
+ class ProfanityFilterValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ record.errors[attribute] << message if value && profane?(value)
6
+ end
7
+
8
+ private
9
+
10
+ def profane?(value)
11
+ !!(value.downcase =~ Regexp.union(profane_words.map(&:downcase)))
12
+ end
13
+
14
+ def profane_words
15
+ t('antivirus.profane_words', [])
16
+ end
17
+
18
+ def message
19
+ t('antivirus.message', 'includes profane words.')
20
+ end
21
+
22
+ def t(key, default)
23
+ value = I18n.t(key, default: '')
24
+ value.present? ? value : default
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Antivirus
2
- VERSION = "0.0.1.pre"
2
+ VERSION = '0.0.1'
3
3
  end
data/lib/antivirus.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require 'antivirus/railtie' if defined?(Rails)
2
+
1
3
  module Antivirus
4
+ autoload :Validator, 'antivirus/validator'
2
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antivirus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kami
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
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'
41
55
  description: Profanity filter for Rails application.
42
56
  email:
43
57
  - kami30k@gmail.com
@@ -46,11 +60,12 @@ extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - MIT-LICENSE
49
- - README.rdoc
63
+ - README.md
50
64
  - Rakefile
51
65
  - lib/antivirus.rb
66
+ - lib/antivirus/railtie.rb
67
+ - lib/antivirus/validator.rb
52
68
  - lib/antivirus/version.rb
53
- - lib/tasks/antivirus_tasks.rake
54
69
  homepage: https://github.com/kami30k/antivirus
55
70
  licenses:
56
71
  - MIT
@@ -66,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
81
  version: '0'
67
82
  required_rubygems_version: !ruby/object:Gem::Requirement
68
83
  requirements:
69
- - - ">"
84
+ - - ">="
70
85
  - !ruby/object:Gem::Version
71
- version: 1.3.1
86
+ version: '0'
72
87
  requirements: []
73
88
  rubyforge_project:
74
89
  rubygems_version: 2.2.2
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = Antivirus
2
-
3
- This project rocks and uses MIT-LICENSE.
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :antivirus do
3
- # # Task goes here
4
- # end