hoygan_validator 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.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +16 -0
- data/Guardfile +14 -0
- data/Rakefile +8 -0
- data/Readme.md +14 -0
- data/config/locales/en.yml +9 -0
- data/hoygan_validator.gemspec +24 -0
- data/lib/hoygan_validator.rb +20 -0
- data/spec/hoygan_validator_spec.rb +65 -0
- data/spec/spec_helper.rb +10 -0
- metadata +102 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use 1.9.3@hoygan-validator
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in dexter.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'guard'
|
8
|
+
gem 'guard-minitest'
|
9
|
+
gem 'minitest-reporters'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :darwin do
|
13
|
+
gem 'rb-fsevent'
|
14
|
+
gem 'growl'
|
15
|
+
gem 'guard-bundler'
|
16
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'minitest' do
|
5
|
+
watch(%r|^spec/(.*)_spec\.rb|)
|
6
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
7
|
+
watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'bundler' do
|
11
|
+
watch('Gemfile')
|
12
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
13
|
+
watch(/^.+.gemspec/)
|
14
|
+
end
|
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# hoygan_validator
|
2
|
+
|
3
|
+
This is a hoygan validator for ActiveModel (Rails 3 compatible).
|
4
|
+
|
5
|
+
It uses [hoygancop](http://github.com/scumbag/hoygancop) in the guts
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```Ruby
|
10
|
+
class Comment < ActiveRecord::Base
|
11
|
+
validates :body, hoygan: false # To prevent the body from being hoygan
|
12
|
+
validates :body, hoygan: true # To ensure the body is hoygan
|
13
|
+
end
|
14
|
+
```
|
@@ -0,0 +1,9 @@
|
|
1
|
+
en:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
hoygan:
|
5
|
+
starts_with_hoygan: "Starts with hoygan"
|
6
|
+
ayudenme: "Don't be so imperative"
|
7
|
+
too_much_marks: "Too much exclamation or question marks"
|
8
|
+
too_much_caps: "What's with all the shouting? You're using way too much capital letters"
|
9
|
+
not_hoygan: "Too polite"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "hoygan_validator"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Josep Jaume Rey"]
|
8
|
+
s.email = ["josepjaume@gmail.com"]
|
9
|
+
s.homepage = "http://github.com/scumbag/hoygan_validator"
|
10
|
+
s.summary = %q{An activemodel validator for hoyganness}
|
11
|
+
s.description = %q{An activemodel validator for hoyganness}
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
# specify any dependencies here; for example:
|
19
|
+
s.add_development_dependency "minitest"
|
20
|
+
s.add_development_dependency "railties"
|
21
|
+
|
22
|
+
s.add_runtime_dependency "activemodel"
|
23
|
+
s.add_runtime_dependency "hoygancop"
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'hoygancop'
|
3
|
+
require 'i18n'
|
4
|
+
|
5
|
+
class HoyganValidator < ActiveModel::EachValidator
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
if options[:with] == false
|
8
|
+
Hoygancop.report(value).each do |error|
|
9
|
+
record.errors.add attribute, "hoygan.#{error}".to_sym
|
10
|
+
end
|
11
|
+
else
|
12
|
+
record.errors.add attribute, :not_hoygan unless Hoygancop.hoygan?(value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined? Rails
|
18
|
+
class HoyganValidatorRailtie < Rails::Engine
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require 'hoygan_validator'
|
3
|
+
|
4
|
+
describe HoyganValidator do
|
5
|
+
describe "hoygan false" do
|
6
|
+
subject do
|
7
|
+
Class.new do
|
8
|
+
def self.name; "FakeClass"; end;
|
9
|
+
include ActiveModel::Naming
|
10
|
+
include ActiveModel::Validations
|
11
|
+
validates :sentence, hoygan: false
|
12
|
+
attr_accessor :sentence
|
13
|
+
end.new
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
subject.sentence = "HOYGAN TENGO UN PROBLEMA"
|
18
|
+
subject.valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
it "detects hoygan" do
|
22
|
+
subject.valid?.must_equal false
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "errors" do
|
26
|
+
it "reports the starts_with_hoygan error" do
|
27
|
+
subject.errors.messages[:sentence].
|
28
|
+
must_include I18n.t('errors.messages.hoygan.starts_with_hoygan')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "reports the caps error" do
|
32
|
+
subject.errors.messages[:sentence].
|
33
|
+
must_include I18n.t('errors.messages.hoygan.too_much_caps')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "doesn't report too_much_caps error" do
|
37
|
+
subject.errors.messages[:sentence].
|
38
|
+
wont_include I18n.t('errors.messages.hoygan.too_much_marks')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
describe "hoygan false" do
|
43
|
+
subject do
|
44
|
+
Class.new do
|
45
|
+
def self.name; "FakeClass"; end;
|
46
|
+
include ActiveModel::Naming
|
47
|
+
include ActiveModel::Validations
|
48
|
+
validates :sentence, hoygan: true
|
49
|
+
attr_accessor :sentence
|
50
|
+
end.new
|
51
|
+
end
|
52
|
+
|
53
|
+
it "is valid if hoygan" do
|
54
|
+
subject.sentence = "HOYGAN"
|
55
|
+
subject.valid?.must_equal true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "adds an error if not hoygan" do
|
59
|
+
subject.sentence = "This is a perfectly polite sentence."
|
60
|
+
subject.valid?.must_equal false
|
61
|
+
subject.errors.messages[:sentence].
|
62
|
+
must_include I18n.t('errors.messages.not_hoygan')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/reporters'
|
4
|
+
MiniTest::Unit.runner = MiniTest::SuiteRunner.new
|
5
|
+
MiniTest::Unit.runner.reporters << MiniTest::Reporters::SpecReporter.new
|
6
|
+
|
7
|
+
require 'i18n'
|
8
|
+
require 'rails'
|
9
|
+
I18n.default_locale = :en
|
10
|
+
I18n.backend.load_translations('config/locales/en.yml')
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hoygan_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josep Jaume Rey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: &70099595843780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70099595843780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: railties
|
27
|
+
requirement: &70099595842620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70099595842620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activemodel
|
38
|
+
requirement: &70099595841820 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70099595841820
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hoygancop
|
49
|
+
requirement: &70099595841280 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70099595841280
|
58
|
+
description: An activemodel validator for hoyganness
|
59
|
+
email:
|
60
|
+
- josepjaume@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rvmrc
|
67
|
+
- Gemfile
|
68
|
+
- Guardfile
|
69
|
+
- Rakefile
|
70
|
+
- Readme.md
|
71
|
+
- config/locales/en.yml
|
72
|
+
- hoygan_validator.gemspec
|
73
|
+
- lib/hoygan_validator.rb
|
74
|
+
- spec/hoygan_validator_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: http://github.com/scumbag/hoygan_validator
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.8.10
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: An activemodel validator for hoyganness
|
100
|
+
test_files:
|
101
|
+
- spec/hoygan_validator_spec.rb
|
102
|
+
- spec/spec_helper.rb
|