scriba 0.0.1.alpha4 → 0.0.1.alpha5
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 +4 -4
- data/lib/scriba/assertions.rb +11 -7
- data/lib/scriba/messages.rb +4 -3
- data/scriba.gemspec +2 -2
- data/test/assertions.rb +20 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa1ceda1c68fb56b7556fd5881f56c40930bf309
|
4
|
+
data.tar.gz: 9e1e4f6c4a1d8717140e85b20ead463f753adf2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e98f80125086b86ae8f2b5e7462f08c9ec5edec6448f497345a03b49496dcd889b8298eb65ee0a802564e4cd24b39781fa43746973b64b7fe63e798fdcbebee9
|
7
|
+
data.tar.gz: 2e946bbdd2b4eb65c68b31273b527a6944861387b2097befc0dae1b21d2852ec9a8830ff6182f4d56c6a4c5775fd9187556f41030bd7a693b23624b84644f5fb
|
data/lib/scriba/assertions.rb
CHANGED
@@ -37,16 +37,20 @@ module Scriba::Assertions
|
|
37
37
|
assert(att, error) { |v| format === v.to_s }
|
38
38
|
end
|
39
39
|
|
40
|
-
def assert_length(att,
|
41
|
-
assert(att, error,
|
40
|
+
def assert_length(att, length, error = :wrong_length)
|
41
|
+
assert(att, error, length: length) { |v| v.to_s.length == length }
|
42
42
|
end
|
43
43
|
|
44
|
-
def assert_maximum_length(att,
|
45
|
-
assert(att, error,
|
44
|
+
def assert_maximum_length(att, length, error = :too_long)
|
45
|
+
assert(att, error, length: length) { |v| v.to_s.length <= length }
|
46
46
|
end
|
47
47
|
|
48
|
-
def assert_minimum_length(att,
|
49
|
-
assert(att, error,
|
48
|
+
def assert_minimum_length(att, length, error = :too_short)
|
49
|
+
assert(att, error, length: length) { |v| v.to_s.length >= length }
|
50
|
+
end
|
51
|
+
|
52
|
+
def assert_member(att, set, error = :not_member)
|
53
|
+
assert(att, error) { |v| set.include?(v) }
|
50
54
|
end
|
51
55
|
|
52
56
|
BLANK = /\A[[:space:]]*\z/
|
@@ -71,7 +75,7 @@ module Scriba::Assertions
|
|
71
75
|
if value
|
72
76
|
return true
|
73
77
|
else
|
74
|
-
errors[att] << generate_message(error, options)
|
78
|
+
errors[att] << generate_message(error, options.merge(value: value))
|
75
79
|
return false
|
76
80
|
end
|
77
81
|
end
|
data/lib/scriba/messages.rb
CHANGED
@@ -2,13 +2,14 @@ module Scriba::Messages
|
|
2
2
|
DEFAULTS = {
|
3
3
|
not_email: "must be a valid email",
|
4
4
|
not_equal: "doesn't match",
|
5
|
+
not_member: "is not included in the list",
|
5
6
|
not_present: "is required",
|
6
7
|
not_unique: "is already taken",
|
7
8
|
not_url: "is an invalid URL",
|
8
9
|
not_valid: "is invalid",
|
9
|
-
too_long: "must be maximum %{
|
10
|
-
too_short: "must be minimum %{
|
11
|
-
wrong_length: "must be %{
|
10
|
+
too_long: "must be maximum %{length} characters",
|
11
|
+
too_short: "must be minimum %{length} characters",
|
12
|
+
wrong_length: "must be %{length} characters"
|
12
13
|
}
|
13
14
|
|
14
15
|
private
|
data/scriba.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "scriba"
|
3
|
-
s.version = "0.0.1.
|
3
|
+
s.version = "0.0.1.alpha5"
|
4
4
|
s.summary = "Validation frontend for models."
|
5
5
|
s.description = s.summary + " Inspired by the scrivener gem."
|
6
6
|
s.authors = ["Francesco Rodríguez"]
|
7
|
-
s.email = ["frodsan@
|
7
|
+
s.email = ["frodsan@protonmail.ch"]
|
8
8
|
s.homepage = "https://github.com/harmoni/scriba"
|
9
9
|
s.license = "MIT"
|
10
10
|
|
data/test/assertions.rb
CHANGED
@@ -160,3 +160,23 @@ test "url assertion" do
|
|
160
160
|
assert filter.valid?
|
161
161
|
assert filter.errors.empty?
|
162
162
|
end
|
163
|
+
|
164
|
+
test "member assertion" do
|
165
|
+
class A < Scriba
|
166
|
+
attribute :status
|
167
|
+
|
168
|
+
def validate
|
169
|
+
assert_member :status, %w(pending active)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
filter = A.new(status: "undefined")
|
174
|
+
|
175
|
+
assert !filter.valid?
|
176
|
+
assert filter.errors.key?(:status)
|
177
|
+
|
178
|
+
filter.status = "active"
|
179
|
+
|
180
|
+
assert filter.valid?
|
181
|
+
assert filter.errors.empty?
|
182
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scriba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.alpha5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodríguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
version: '1.2'
|
27
27
|
description: Validation frontend for models. Inspired by the scrivener gem.
|
28
28
|
email:
|
29
|
-
- frodsan@
|
29
|
+
- frodsan@protonmail.ch
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|