validates_not_shouting 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47526e07aaebbf01f2c81d7b36a3882c1bb2e5e9
4
+ data.tar.gz: 1d297c90370169b4d83cb518a66af3bea7020b97
5
+ SHA512:
6
+ metadata.gz: 77a93d81652381c33568b563517604a1e1bb3d51702faaad3340274f26550a4d617d43af5b2b3833af2f726d4c5d910f1a89aa36ff846e6684dfc042b56852f6
7
+ data.tar.gz: df2d5d612fb337faaa25171a86c01f85c38c93e7f403249c4cf52f03f766af33e65b61ab156b46d72956305eaf1ad289fb6abe1a2dbd669bf5d5bd5d01751890
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ env:
7
+ global:
8
+ - CODECLIMATE_REPO_TOKEN=e60275947ae5fe3e0042bc2a3a0e3324a779ae4eb37f90ac787129cde9f36508
9
+ matrix:
10
+ - "AM_VERSION=3.2.0"
11
+ - "AM_VERSION=4.0.0"
12
+ - "AM_VERSION=4.1.0"
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in validates_not_shouting.gemspec
4
+ gemspec
5
+
6
+ am_version = ENV["AM_VERSION"] || "default"
7
+
8
+ am_version = case am_version
9
+ when "default"
10
+ ">= 3.2.0"
11
+ else
12
+ "~> #{am_version}"
13
+ end
14
+
15
+ gem "activesupport", am_version
16
+
17
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jeff Ching
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,49 @@
1
+ # ValidatesNotShouting [![Build Status](https://travis-ci.org/avvo/validates_not_shouting.png)](https://travis-ci.org/avvo/validates_not_shouting) [![Code Climate](https://codeclimate.com/github/avvo/validates_not_shouting.png)](https://codeclimate.com/github/avvo/validates_not_shouting) [![Code Coverage](https://codeclimate.com/github/avvo/validates_not_shouting/coverage.png)](https://codeclimate.com/github/avvo/validates_not_shouting)
2
+
3
+ To prevent noobs from being uber noobs.
4
+
5
+ Originally idea conceived by [bvandenbos](https://github.com/bvandenbos). ActiveModel::Validator
6
+ to prevent the percentage of capital letters.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'validates_not_shouting'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install validates_not_shouting
23
+
24
+ ## Usage
25
+
26
+ ```
27
+
28
+ class Foo
29
+ include ActiveModel::Validations
30
+ attr_accessor :foo
31
+
32
+ validates :foo, not_shouting: true
33
+ end
34
+
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ You can set the message and threshold as configuration for the validator. The default threshold is 0.5 (half of the characters).
40
+
41
+ validates :foo, not_shouting: {threshold: 0.1, message: 'cannot be so shouty.'}
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/avvo/validates_not_shouting/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = false
10
+ end
11
+
12
+
13
+ task default: :test
@@ -0,0 +1,7 @@
1
+ require 'active_model'
2
+ require 'validates_not_shouting/version'
3
+ require 'validates_not_shouting/not_shouting_validator'
4
+
5
+ module ValidatesNotShouting
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,16 @@
1
+ # this is not namespaced so that we can do
2
+ # validates :body, not_shouting: true
3
+ class NotShoutingValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ return true if value.blank?
6
+
7
+ if shouting?(value)
8
+ record.errors[attribute] << options.fetch(:message, "cannot be mostly caps. It's not polite to shout.")
9
+ end
10
+ end
11
+
12
+ def shouting?(value)
13
+ threshold = options.fetch(:threshold, 0.5)
14
+ (value.gsub(/[^A-Z]/, '').length.to_f / value.length) > threshold
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module ValidatesNotShouting
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ class ModelTest < MiniTest::Unit::TestCase
4
+
5
+ class TestModel
6
+ attr_accessor :body, :subject, :blurb
7
+ include ActiveModel::Validations
8
+
9
+ validates :body, :subject, not_shouting: {threshold: 0.1}
10
+ end
11
+
12
+ class TestModelNoThreshold
13
+ attr_accessor :body, :subject, :blurb
14
+ include ActiveModel::Validations
15
+
16
+ validates :body, :subject, not_shouting: true
17
+ end
18
+
19
+ def test_validates_nil
20
+ m = TestModel.new
21
+ assert(m.valid?)
22
+ end
23
+
24
+ def test_validates_shouting
25
+ m = TestModel.new
26
+ m.body = "THIS IS SHOUTING AND SHOULD NOT BE OK"
27
+ m.subject = "THIS IS NOT OK"
28
+ assert !m.valid?
29
+ assert m.errors[:body].present?
30
+ assert m.errors[:subject].present?
31
+ end
32
+
33
+ def test_validates_with_threshold
34
+ m = TestModel.new
35
+ m.subject = "This is actually ok" # < 10%
36
+ assert m.valid?
37
+
38
+ m = TestModel.new
39
+ m.subject = "THIs is actually ok" # > 10%
40
+ assert !m.valid?
41
+ end
42
+
43
+ def test_without_threshold
44
+ m = TestModelNoThreshold.new
45
+ m.body = "ABCabc" # 50% ok
46
+ assert(m.valid?)
47
+
48
+ m.body = "ABCDabc" # >50% not ok
49
+ assert(!m.valid?)
50
+ end
51
+
52
+ end
@@ -0,0 +1,5 @@
1
+ Bundler.require(:default, :test)
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+
5
+ require 'minitest/autorun'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'validates_not_shouting/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "validates_not_shouting"
8
+ spec.version = ValidatesNotShouting::VERSION
9
+ spec.authors = ["Jeff Ching"]
10
+ spec.email = ["jching@avvo.com"]
11
+ spec.summary = "To prevent noobs from being uber noobs"
12
+ spec.description = "To prevent noobs from being uber noobs"
13
+ spec.homepage = ""
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 "activemodel", ">= 3.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validates_not_shouting
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Ching
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-12 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: '3.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'
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.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
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
+ description: To prevent noobs from being uber noobs
56
+ email:
57
+ - jching@avvo.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/validates_not_shouting.rb
69
+ - lib/validates_not_shouting/not_shouting_validator.rb
70
+ - lib/validates_not_shouting/version.rb
71
+ - test/model_test.rb
72
+ - test/test_helper.rb
73
+ - validates_not_shouting.gemspec
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.0
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: To prevent noobs from being uber noobs
98
+ test_files:
99
+ - test/model_test.rb
100
+ - test/test_helper.rb
101
+ has_rdoc: