scriba 0.0.1.alpha4 → 0.0.1.alpha5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5518ab48176f05d83deaece3e6a44c3bd77ed7b
4
- data.tar.gz: efa6a5f8a22501d88c515be06d293d8d68653730
3
+ metadata.gz: aa1ceda1c68fb56b7556fd5881f56c40930bf309
4
+ data.tar.gz: 9e1e4f6c4a1d8717140e85b20ead463f753adf2b
5
5
  SHA512:
6
- metadata.gz: 2df4486faea12e1e5f630f62cbc50c274aa1dc36333ea3e42dcb2e956305c983c082bd451e5cbe07c215703a929e1cc4077bfa7227c9a0e07d381581baf2ae6a
7
- data.tar.gz: 9c554ddfd541931bd8fbf836265378ddee44c61460de96d1e5c8f1f8ef255d53901678465d0407886f9ba4c21c9b82de26ba1b87dad867d5ddb05a551270b263
6
+ metadata.gz: e98f80125086b86ae8f2b5e7462f08c9ec5edec6448f497345a03b49496dcd889b8298eb65ee0a802564e4cd24b39781fa43746973b64b7fe63e798fdcbebee9
7
+ data.tar.gz: 2e946bbdd2b4eb65c68b31273b527a6944861387b2097befc0dae1b21d2852ec9a8830ff6182f4d56c6a4c5775fd9187556f41030bd7a693b23624b84644f5fb
@@ -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, value, error = :wrong_length)
41
- assert(att, error, value: value) { |v| v.to_s.length == value }
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, value, error = :too_long)
45
- assert(att, error, value: value) { |v| v.to_s.length <= value }
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, value, error = :too_short)
49
- assert(att, error, value: value) { |v| v.to_s.length >= value }
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
@@ -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 %{value} characters",
10
- too_short: "must be minimum %{value} characters",
11
- wrong_length: "must be %{value} characters"
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
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "scriba"
3
- s.version = "0.0.1.alpha4"
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@me.com"]
7
+ s.email = ["frodsan@protonmail.ch"]
8
8
  s.homepage = "https://github.com/harmoni/scriba"
9
9
  s.license = "MIT"
10
10
 
@@ -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.alpha4
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-12 00:00:00.000000000 Z
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@me.com
29
+ - frodsan@protonmail.ch
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []