validates_im 1.0.0 → 2.0.0
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 +7 -0
- data/CHANGELOG.md +48 -0
- data/LICENSE +1 -1
- data/README.md +109 -0
- data/lib/account_name_validator.rb +35 -31
- data/lib/aim_validator.rb +17 -10
- data/lib/discord_validator.rb +39 -0
- data/lib/matrix_validator.rb +63 -0
- data/lib/signal_validator.rb +37 -0
- data/lib/skype_validator.rb +18 -11
- data/lib/steam_validator.rb +16 -5
- data/lib/telegram_validator.rb +44 -0
- data/lib/validates_im/version.rb +5 -0
- data/lib/validates_im.rb +16 -7
- data/lib/xbox_live_validator.rb +24 -11
- data/lib/yahoo_im_validator.rb +20 -13
- data/validates_im.gemspec +44 -62
- metadata +66 -74
- data/.document +0 -5
- data/.gitignore +0 -25
- data/.rspec +0 -1
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -50
- data/README.textile +0 -40
- data/Rakefile +0 -35
- data/VERSION +0 -1
- data/spec/account_name_validator_spec.rb +0 -115
- data/spec/spec_helper.rb +0 -10
data/lib/xbox_live_validator.rb
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Validates Xbox Live gamertags. From the Xbox Live website:
|
|
2
4
|
#
|
|
3
|
-
#
|
|
4
|
-
# with a number.
|
|
5
|
+
# > Gamertags can only contain letters, numbers, and spaces, and can't begin
|
|
6
|
+
# > with a number.
|
|
5
7
|
#
|
|
6
|
-
#
|
|
7
|
-
# than 15 characters, and also cannot start with a space.
|
|
8
|
+
# Xbox gamertags are 3-12 characters and cannot start with a space.
|
|
8
9
|
#
|
|
9
10
|
# The following error message keys are used to localize invalid screen names.
|
|
10
11
|
#
|
|
11
|
-
# |
|
|
12
|
-
#
|
|
13
|
-
# |
|
|
12
|
+
# | | |
|
|
13
|
+
# |:--------------------------|:--------------------------------------|
|
|
14
|
+
# | `xbox_too_short` | Gamertag is under 3 characters. |
|
|
15
|
+
# | `xbox_too_long` | Gamertag is over 12 characters. |
|
|
16
|
+
# | `xbox_invalid_chars` | Gamertag contains invalid characters. |
|
|
17
|
+
# | `xbox_invalid_first_char` | Gamertag doesn't start with a letter. |
|
|
14
18
|
#
|
|
15
19
|
# @example
|
|
16
20
|
# validates :steam_account, steam: true
|
|
21
|
+
#
|
|
22
|
+
# Options
|
|
23
|
+
# -------
|
|
24
|
+
#
|
|
25
|
+
# | | |
|
|
26
|
+
# |:-------------|:-------------------------------------------------|
|
|
27
|
+
# | `:message` | A custom message to use if the email is invalid. |
|
|
28
|
+
# | `:allow_nil` | If true, `nil` values are allowed. |
|
|
17
29
|
|
|
18
30
|
class XboxLiveValidator < AccountNameValidator
|
|
19
|
-
error_key_prefix
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
error_key_prefix "xbox"
|
|
32
|
+
min_length 3
|
|
33
|
+
max_length 12
|
|
34
|
+
valid_chars "A-Za-z0-9 "
|
|
35
|
+
first_char "A-Za-z"
|
|
23
36
|
end
|
data/lib/yahoo_im_validator.rb
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Validates Yahoo! Instant Messenger screen names. According to the Yahoo!
|
|
2
4
|
# website:
|
|
3
5
|
#
|
|
4
|
-
#
|
|
5
|
-
# numbers, underscores, and one dot (.).
|
|
6
|
+
# > Use 4 to 32 characters and start with a letter. You may use letters,
|
|
7
|
+
# > numbers, underscores, and one dot (.).
|
|
6
8
|
#
|
|
7
9
|
# The following error message keys are used to localize invalid screen names:
|
|
8
10
|
#
|
|
9
|
-
# |
|
|
10
|
-
#
|
|
11
|
-
# |
|
|
12
|
-
# |
|
|
13
|
-
# |
|
|
11
|
+
# | | |
|
|
12
|
+
# |:-------------------------|:--------------------------------------------|
|
|
13
|
+
# | `yim_too_short` | Screen name is fewer than 3 characters. |
|
|
14
|
+
# | `yim_too_long` | Screen name is over 16 characters. |
|
|
15
|
+
# | `yim_invalid_chars` | Screen name contains invalid characters. |
|
|
16
|
+
# | `yim_invalid_first_char` | Screen name doesn't start with a letter. |
|
|
17
|
+
# | `yim_multiple_periods` | Screen name has more than one period in it. |
|
|
14
18
|
#
|
|
15
19
|
# @example
|
|
16
20
|
# validates :yim_sn, yahoo_im: true
|
|
17
21
|
#
|
|
18
|
-
#
|
|
22
|
+
# Options
|
|
23
|
+
# -------
|
|
19
24
|
#
|
|
20
|
-
# |
|
|
21
|
-
#
|
|
25
|
+
# | | |
|
|
26
|
+
# |:-------------|:-------------------------------------------------|
|
|
27
|
+
# | `:message` | A custom message to use if the email is invalid. |
|
|
28
|
+
# | `:allow_nil` | If true, `nil` values are allowed. |
|
|
22
29
|
|
|
23
30
|
class YahooImValidator < AccountNameValidator
|
|
24
|
-
error_key_prefix
|
|
31
|
+
error_key_prefix "yim"
|
|
25
32
|
min_length 4
|
|
26
33
|
max_length 32
|
|
27
34
|
valid_chars 'A-Za-z0-9_\\.'
|
|
28
|
-
first_char
|
|
29
|
-
add_validation(:multiple_periods) { |value| value.count(
|
|
35
|
+
first_char "A-Za-z"
|
|
36
|
+
add_validation(:multiple_periods) { |value| value.count(".") < 2 }
|
|
30
37
|
end
|
data/validates_im.gemspec
CHANGED
|
@@ -1,63 +1,45 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"README.textile"
|
|
18
|
-
]
|
|
19
|
-
s.files = [
|
|
20
|
-
".document",
|
|
21
|
-
".gitignore",
|
|
22
|
-
".rspec",
|
|
23
|
-
"Gemfile",
|
|
24
|
-
"Gemfile.lock",
|
|
25
|
-
"LICENSE",
|
|
26
|
-
"README.textile",
|
|
27
|
-
"Rakefile",
|
|
28
|
-
"VERSION",
|
|
29
|
-
"lib/account_name_validator.rb",
|
|
30
|
-
"lib/aim_validator.rb",
|
|
31
|
-
"lib/skype_validator.rb",
|
|
32
|
-
"lib/steam_validator.rb",
|
|
33
|
-
"lib/validates_im.rb",
|
|
34
|
-
"lib/xbox_live_validator.rb",
|
|
35
|
-
"lib/yahoo_im_validator.rb",
|
|
36
|
-
"spec/account_name_validator_spec.rb",
|
|
37
|
-
"spec/spec_helper.rb",
|
|
38
|
-
"validates_im.gemspec"
|
|
39
|
-
]
|
|
40
|
-
s.homepage = %q{http://github.com/riscfuture/validates_im}
|
|
41
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
|
42
|
-
s.require_paths = ["lib"]
|
|
43
|
-
s.rubygems_version = %q{1.3.7}
|
|
44
|
-
s.summary = %q{A set of Rails validators for common instant messenging services}
|
|
45
|
-
s.test_files = [
|
|
46
|
-
"spec/account_name_validator_spec.rb",
|
|
47
|
-
"spec/spec_helper.rb"
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
if s.respond_to? :specification_version then
|
|
51
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
52
|
-
s.specification_version = 3
|
|
53
|
-
|
|
54
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
55
|
-
s.add_runtime_dependency(%q<activerecord>, [">= 3.0"])
|
|
56
|
-
else
|
|
57
|
-
s.add_dependency(%q<activerecord>, [">= 3.0"])
|
|
58
|
-
end
|
|
59
|
-
else
|
|
60
|
-
s.add_dependency(%q<activerecord>, [">= 3.0"])
|
|
61
|
-
end
|
|
62
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/validates_im/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "validates_im"
|
|
7
|
+
spec.version = ValidatesIm::VERSION
|
|
8
|
+
spec.authors = ["Tim Morgan"]
|
|
9
|
+
spec.email = "git@timothymorgan.info"
|
|
10
|
+
|
|
11
|
+
spec.summary = "A set of Rails validators for common instant messaging services"
|
|
12
|
+
spec.description = "Adds ActiveModel validators for common instant messaging services like Discord, Telegram, Matrix, and Signal (as well as legacy services like AIM, Yahoo!, and Skype)."
|
|
13
|
+
spec.homepage = "https://github.com/riscfuture/validates_im"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.required_ruby_version = ">= 3.1"
|
|
63
17
|
|
|
18
|
+
spec.metadata = {
|
|
19
|
+
"homepage_uri" => spec.homepage,
|
|
20
|
+
"source_code_uri" => "#{spec.homepage}/tree/master",
|
|
21
|
+
"changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
|
|
22
|
+
"bug_tracker_uri" => "#{spec.homepage}/issues",
|
|
23
|
+
"rubygems_mfa_required" => "true"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
spec.files = Dir.chdir(__dir__) do
|
|
27
|
+
candidates =
|
|
28
|
+
if system("git rev-parse --is-inside-work-tree > /dev/null 2>&1")
|
|
29
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
30
|
+
f.start_with?(".github/", "spec/", ".idea/", ".claude/", "bin/") ||
|
|
31
|
+
f.match?(/\A(?:Gemfile|Gemfile\.lock|Rakefile|\.rspec|\.rubocop\.yml|\.travis\.yml|\.ruby-(?:gemset|version)|\.gitignore|\.document)/)
|
|
32
|
+
end
|
|
33
|
+
else
|
|
34
|
+
Dir["lib/**/*.rb"] + %w[LICENSE README.md CHANGELOG.md validates_im.gemspec]
|
|
35
|
+
end
|
|
36
|
+
candidates.select { |f| File.exist?(f) } +
|
|
37
|
+
Dir["lib/**/*.rb"].reject { |f| candidates.include?(f) } +
|
|
38
|
+
%w[CHANGELOG.md].reject { |f| candidates.include?(f) || !File.exist?(f) }
|
|
39
|
+
end.uniq
|
|
40
|
+
|
|
41
|
+
spec.require_paths = ["lib"]
|
|
42
|
+
|
|
43
|
+
spec.add_dependency "activemodel", ">= 6.1"
|
|
44
|
+
spec.add_dependency "activesupport", ">= 6.1"
|
|
45
|
+
end
|
metadata
CHANGED
|
@@ -1,98 +1,90 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: validates_im
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
segments:
|
|
6
|
-
- 1
|
|
7
|
-
- 0
|
|
8
|
-
- 0
|
|
9
|
-
version: 1.0.0
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
10
5
|
platform: ruby
|
|
11
|
-
authors:
|
|
6
|
+
authors:
|
|
12
7
|
- Tim Morgan
|
|
13
|
-
autorequire:
|
|
14
8
|
bindir: bin
|
|
15
9
|
cert_chain: []
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
|
23
|
-
none: false
|
|
24
|
-
requirements:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activemodel
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
25
16
|
- - ">="
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
|
|
28
|
-
- 3
|
|
29
|
-
- 0
|
|
30
|
-
version: "3.0"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '6.1'
|
|
31
19
|
type: :runtime
|
|
32
20
|
prerelease: false
|
|
33
|
-
version_requirements:
|
|
34
|
-
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '6.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: activesupport
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '6.1'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '6.1'
|
|
40
|
+
description: Adds ActiveModel validators for common instant messaging services like
|
|
41
|
+
Discord, Telegram, Matrix, and Signal (as well as legacy services like AIM, Yahoo!,
|
|
42
|
+
and Skype).
|
|
35
43
|
email: git@timothymorgan.info
|
|
36
44
|
executables: []
|
|
37
|
-
|
|
38
45
|
extensions: []
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
- README.textile
|
|
43
|
-
files:
|
|
44
|
-
- .document
|
|
45
|
-
- .gitignore
|
|
46
|
-
- .rspec
|
|
47
|
-
- Gemfile
|
|
48
|
-
- Gemfile.lock
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- CHANGELOG.md
|
|
49
49
|
- LICENSE
|
|
50
|
-
- README.
|
|
51
|
-
- Rakefile
|
|
52
|
-
- VERSION
|
|
50
|
+
- README.md
|
|
53
51
|
- lib/account_name_validator.rb
|
|
54
52
|
- lib/aim_validator.rb
|
|
53
|
+
- lib/discord_validator.rb
|
|
54
|
+
- lib/matrix_validator.rb
|
|
55
|
+
- lib/signal_validator.rb
|
|
55
56
|
- lib/skype_validator.rb
|
|
56
57
|
- lib/steam_validator.rb
|
|
58
|
+
- lib/telegram_validator.rb
|
|
57
59
|
- lib/validates_im.rb
|
|
60
|
+
- lib/validates_im/version.rb
|
|
58
61
|
- lib/xbox_live_validator.rb
|
|
59
62
|
- lib/yahoo_im_validator.rb
|
|
60
|
-
- spec/account_name_validator_spec.rb
|
|
61
|
-
- spec/spec_helper.rb
|
|
62
63
|
- validates_im.gemspec
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
homepage: https://github.com/riscfuture/validates_im
|
|
65
|
+
licenses:
|
|
66
|
+
- MIT
|
|
67
|
+
metadata:
|
|
68
|
+
homepage_uri: https://github.com/riscfuture/validates_im
|
|
69
|
+
source_code_uri: https://github.com/riscfuture/validates_im/tree/master
|
|
70
|
+
changelog_uri: https://github.com/riscfuture/validates_im/blob/master/CHANGELOG.md
|
|
71
|
+
bug_tracker_uri: https://github.com/riscfuture/validates_im/issues
|
|
72
|
+
rubygems_mfa_required: 'true'
|
|
73
|
+
rdoc_options: []
|
|
74
|
+
require_paths:
|
|
71
75
|
- lib
|
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
|
-
|
|
74
|
-
requirements:
|
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
75
78
|
- - ">="
|
|
76
|
-
- !ruby/object:Gem::Version
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
version: "0"
|
|
81
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
-
none: false
|
|
83
|
-
requirements:
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '3.1'
|
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
84
83
|
- - ">="
|
|
85
|
-
- !ruby/object:Gem::Version
|
|
86
|
-
|
|
87
|
-
- 0
|
|
88
|
-
version: "0"
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
89
86
|
requirements: []
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
specification_version: 3
|
|
95
|
-
summary: A set of Rails validators for common instant messenging services
|
|
96
|
-
test_files:
|
|
97
|
-
- spec/account_name_validator_spec.rb
|
|
98
|
-
- spec/spec_helper.rb
|
|
87
|
+
rubygems_version: 4.0.11
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: A set of Rails validators for common instant messaging services
|
|
90
|
+
test_files: []
|
data/.document
DELETED
data/.gitignore
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
## MAC OS
|
|
2
|
-
.DS_Store
|
|
3
|
-
|
|
4
|
-
## TEXTMATE
|
|
5
|
-
*.tmproj
|
|
6
|
-
tmtags
|
|
7
|
-
|
|
8
|
-
## EMACS
|
|
9
|
-
*~
|
|
10
|
-
\#*
|
|
11
|
-
.\#*
|
|
12
|
-
|
|
13
|
-
## VIM
|
|
14
|
-
*.swp
|
|
15
|
-
|
|
16
|
-
## PROJECT::GENERAL
|
|
17
|
-
coverage
|
|
18
|
-
rdoc
|
|
19
|
-
pkg
|
|
20
|
-
.rvmrc
|
|
21
|
-
.bundle
|
|
22
|
-
|
|
23
|
-
## PROJECT::DOCUMENTATION
|
|
24
|
-
.yardoc
|
|
25
|
-
doc
|
data/.rspec
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
-cfs
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
GEM
|
|
2
|
-
remote: http://rubygems.org/
|
|
3
|
-
specs:
|
|
4
|
-
RedCloth (4.2.3)
|
|
5
|
-
activemodel (3.0.1)
|
|
6
|
-
activesupport (= 3.0.1)
|
|
7
|
-
builder (~> 2.1.2)
|
|
8
|
-
i18n (~> 0.4.1)
|
|
9
|
-
activerecord (3.0.1)
|
|
10
|
-
activemodel (= 3.0.1)
|
|
11
|
-
activesupport (= 3.0.1)
|
|
12
|
-
arel (~> 1.0.0)
|
|
13
|
-
tzinfo (~> 0.3.23)
|
|
14
|
-
activesupport (3.0.1)
|
|
15
|
-
arel (1.0.1)
|
|
16
|
-
activesupport (~> 3.0.0)
|
|
17
|
-
builder (2.1.2)
|
|
18
|
-
diff-lcs (1.1.2)
|
|
19
|
-
gemcutter (0.6.1)
|
|
20
|
-
git (1.2.5)
|
|
21
|
-
i18n (0.4.2)
|
|
22
|
-
jeweler (1.4.0)
|
|
23
|
-
gemcutter (>= 0.1.0)
|
|
24
|
-
git (>= 1.2.5)
|
|
25
|
-
rubyforge (>= 2.0.0)
|
|
26
|
-
json_pure (1.4.6)
|
|
27
|
-
rspec (2.0.1)
|
|
28
|
-
rspec-core (~> 2.0.1)
|
|
29
|
-
rspec-expectations (~> 2.0.1)
|
|
30
|
-
rspec-mocks (~> 2.0.1)
|
|
31
|
-
rspec-core (2.0.1)
|
|
32
|
-
rspec-expectations (2.0.1)
|
|
33
|
-
diff-lcs (>= 1.1.2)
|
|
34
|
-
rspec-mocks (2.0.1)
|
|
35
|
-
rspec-core (~> 2.0.1)
|
|
36
|
-
rspec-expectations (~> 2.0.1)
|
|
37
|
-
rubyforge (2.0.4)
|
|
38
|
-
json_pure (>= 1.1.7)
|
|
39
|
-
tzinfo (0.3.23)
|
|
40
|
-
yard (0.6.1)
|
|
41
|
-
|
|
42
|
-
PLATFORMS
|
|
43
|
-
ruby
|
|
44
|
-
|
|
45
|
-
DEPENDENCIES
|
|
46
|
-
RedCloth
|
|
47
|
-
activerecord
|
|
48
|
-
jeweler
|
|
49
|
-
rspec
|
|
50
|
-
yard
|
data/README.textile
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
h1. validates_im -- Instant messenger account validations for ActiveRecord
|
|
2
|
-
|
|
3
|
-
| *Author* | Tim Morgan |
|
|
4
|
-
| *Version* | 1.0 (Oct 30, 2010) |
|
|
5
|
-
| *License* | Released under the MIT license. |
|
|
6
|
-
|
|
7
|
-
h2. About
|
|
8
|
-
|
|
9
|
-
@validates_im@ is a simple gem that gives you some @EachValidators@ that you can
|
|
10
|
-
use to validate instant messenger account names in your Rails 3.0 application.
|
|
11
|
-
Validators are provided for the most common IM services, like AIM, Yahoo! IM,
|
|
12
|
-
and Skype.
|
|
13
|
-
|
|
14
|
-
h2. Installation
|
|
15
|
-
|
|
16
|
-
*Important Note:* This gem is for Rails 3 only.
|
|
17
|
-
|
|
18
|
-
To install, simply add this gem to your Rails project's @Gemfile@:
|
|
19
|
-
|
|
20
|
-
<pre><code>
|
|
21
|
-
gem 'validates_im'
|
|
22
|
-
</code></pre>
|
|
23
|
-
|
|
24
|
-
h2. Usage
|
|
25
|
-
|
|
26
|
-
The IM validators are @EachValidators@, meant to be used with the @validates@
|
|
27
|
-
method. An example:
|
|
28
|
-
|
|
29
|
-
<pre><code>
|
|
30
|
-
validates :screen_name,
|
|
31
|
-
aim: true,
|
|
32
|
-
presence: true
|
|
33
|
-
</code></pre>
|
|
34
|
-
|
|
35
|
-
The name of the symbol key is taken from the name of the validator; as such, The
|
|
36
|
-
@XboxLiveValidator@ would be invoked using @:xbox_live@. See the
|
|
37
|
-
{AccountNameValidator} class docs for more information.
|
|
38
|
-
|
|
39
|
-
The localization keys for validation errors are listed in the documentation for
|
|
40
|
-
each validator class.
|
data/Rakefile
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'rake'
|
|
2
|
-
begin
|
|
3
|
-
require 'bundler'
|
|
4
|
-
rescue LoadError
|
|
5
|
-
puts "Bundler is not installed; install with `gem install bundler`."
|
|
6
|
-
exit 1
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
Bundler.require :default
|
|
10
|
-
|
|
11
|
-
Jeweler::Tasks.new do |gem|
|
|
12
|
-
gem.name = "validates_im"
|
|
13
|
-
gem.summary = %Q{A set of Rails validators for common instant messenging services}
|
|
14
|
-
gem.description = %Q{Adds ActiveModel validators for common instant messenging services like Skype and AIM.}
|
|
15
|
-
gem.email = "git@timothymorgan.info"
|
|
16
|
-
gem.homepage = "http://github.com/riscfuture/validates_im"
|
|
17
|
-
gem.authors = [ "Tim Morgan" ]
|
|
18
|
-
gem.add_dependency 'activerecord', '>= 3.0'
|
|
19
|
-
end
|
|
20
|
-
Jeweler::GemcutterTasks.new
|
|
21
|
-
|
|
22
|
-
require 'rspec/core/rake_task'
|
|
23
|
-
RSpec::Core::RakeTask.new
|
|
24
|
-
|
|
25
|
-
YARD::Rake::YardocTask.new('doc') do |doc|
|
|
26
|
-
doc.options << "-m" << "textile"
|
|
27
|
-
doc.options << "--protected"
|
|
28
|
-
doc.options << "-r" << "README.textile"
|
|
29
|
-
doc.options << "-o" << "doc"
|
|
30
|
-
doc.options << "--title" << "validates_im Documentation".inspect
|
|
31
|
-
|
|
32
|
-
doc.files = [ 'lib/*_validator.rb', 'README.textile' ]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
task(default: :spec)
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.0.0
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
-
|
|
3
|
-
module SpecSupport
|
|
4
|
-
class TestAccountNameValidator < AccountNameValidator; end
|
|
5
|
-
class FakeModel
|
|
6
|
-
extend ActiveModel::Translation
|
|
7
|
-
def errors() @errors ||= ActiveModel::Errors.new(self) end
|
|
8
|
-
def self.lookup_ancestors() [ self ] end
|
|
9
|
-
def read_attribute_for_validation(_) "mock" end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe AccountNameValidator do
|
|
14
|
-
before :each do
|
|
15
|
-
SpecSupport::TestAccountNameValidator.validations.clear
|
|
16
|
-
@model = SpecSupport::FakeModel.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe ".error_key_prefix" do
|
|
20
|
-
it "should be the downcased name of the validator by default" do
|
|
21
|
-
SpecSupport::TestAccountNameValidator.error_key_prefix.should eql(:test_account_name)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should be able to be set" do
|
|
25
|
-
SpecSupport::TestAccountNameValidator.error_key_prefix(:foo)
|
|
26
|
-
SpecSupport::TestAccountNameValidator.error_key_prefix.should eql(:foo)
|
|
27
|
-
SpecSupport::TestAccountNameValidator.instance_variable_set :@error_key_prefix, nil
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#validate_each" do
|
|
32
|
-
it "should do nothing if given nil and :allow_nil is set" do
|
|
33
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field, allow_nil: true).validate_each(@model, :field, nil)
|
|
34
|
-
@model.errors.should be_empty
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should do nothing if given a blank value and :allow_blank is set" do
|
|
38
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field, allow_blank: true).validate_each(@model, :field, "")
|
|
39
|
-
@model.errors.should be_empty
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should add an error to the record if any validation fails" do
|
|
43
|
-
SpecSupport::TestAccountNameValidator.add_validation(:not_foo) { |value| value == 'foo' }
|
|
44
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field).validate_each(@model, :field, 'bar')
|
|
45
|
-
@model.errors[:field].should_not be_empty
|
|
46
|
-
@model.errors[:field].first.should include('test_account_name_not_foo')
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "should use a :message option for the message" do
|
|
50
|
-
SpecSupport::TestAccountNameValidator.add_validation(:not_foo) { |value| value == 'foo' }
|
|
51
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field, message: 'bar').validate_each(@model, :field, 'bar')
|
|
52
|
-
@model.errors[:field].should eql([ 'bar' ])
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "should typecast the value to a string" do
|
|
56
|
-
SpecSupport::TestAccountNameValidator.add_validation(:not_foo) { |value| value == 'foo' }
|
|
57
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field).validate_each(@model, :field, :foo)
|
|
58
|
-
@model.errors.should be_empty
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
describe ".add_validation" do
|
|
63
|
-
before :each do
|
|
64
|
-
@validator = SpecSupport::TestAccountNameValidator.new(attributes: :field)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "should add a validation block" do
|
|
68
|
-
SpecSupport::TestAccountNameValidator.add_validation(:not_foo) { |value| value == 'foo' }
|
|
69
|
-
@validator.validate_each(@model, :field, 'bar')
|
|
70
|
-
@model.errors[:field].should_not be_empty
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should do nothing if no block is given" do
|
|
74
|
-
SpecSupport::TestAccountNameValidator.add_validation(:not_foo)
|
|
75
|
-
@validator.validate_each(@model, :field, 'bar')
|
|
76
|
-
@model.errors[:field].should be_empty
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe ".min_length" do
|
|
81
|
-
it "should ensure a minimum length" do
|
|
82
|
-
SpecSupport::TestAccountNameValidator.min_length 5
|
|
83
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field).validate_each(@model, :field, '1234')
|
|
84
|
-
@model.errors[:field].should_not be_empty
|
|
85
|
-
@model.errors[:field].first.should include('too_short')
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe ".max_length" do
|
|
90
|
-
it "should ensure a maximum length" do
|
|
91
|
-
SpecSupport::TestAccountNameValidator.max_length 5
|
|
92
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field).validate_each(@model, :field, '123456')
|
|
93
|
-
@model.errors[:field].should_not be_empty
|
|
94
|
-
@model.errors[:field].first.should include('too_long')
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
describe ".valid_chars" do
|
|
99
|
-
it "should check for invalid chars" do
|
|
100
|
-
SpecSupport::TestAccountNameValidator.valid_chars '[A-Z]'
|
|
101
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field).validate_each(@model, :field, 'A!Z')
|
|
102
|
-
@model.errors[:field].should_not be_empty
|
|
103
|
-
@model.errors[:field].first.should include('invalid_chars')
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
describe ".first_char" do
|
|
108
|
-
it "should check for an invalid first character" do
|
|
109
|
-
SpecSupport::TestAccountNameValidator.first_char '[A-Z]'
|
|
110
|
-
SpecSupport::TestAccountNameValidator.new(attributes: :field).validate_each(@model, :field, 'abc')
|
|
111
|
-
@model.errors[:field].should_not be_empty
|
|
112
|
-
@model.errors[:field].first.should include('invalid_first_char')
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|