scrivener 0.2.0 → 0.3.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 +4 -4
- data/README.md +2 -4
- data/lib/scrivener.rb +1 -1
- data/lib/scrivener/validations.rb +3 -13
- data/test/scrivener_test.rb +1 -1
- 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: dc1f71859949ac9d78b3bc589d6d04ec70531240
|
4
|
+
data.tar.gz: 5bbd3d104350d6472cd03da0f18c1d90b6120dea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd5c732af472a97cfdd34d0091fa9eab509d9121d57369b1197cd259e7f1bdb8a02c7fdccf7746cf753819b838a00c8b456d1e856192f1f80fc228ad2b2ce60f
|
7
|
+
data.tar.gz: 2117ae9707e937dfa06d4ae54b99b8a299dcb6ead0aca9ca14a354e05fd570706b065bb344a5896cf9aad9b1346d2bd7f85bfad8aca33008e8516e6547ad2dd9
|
data/README.md
CHANGED
@@ -23,9 +23,7 @@ and its features are a subset of Bureaucrat's. For a more robust and tested
|
|
23
23
|
solution, please [check it](https://github.com/tizoc/bureaucrat).
|
24
24
|
|
25
25
|
This library exists to satify the need of extracting Ohm's validations for
|
26
|
-
reuse in other scenarios.
|
27
|
-
will be able to profit from extra assertions such as those provided by
|
28
|
-
[ohm-contrib](https://github.com/cyx/ohm-contrib).
|
26
|
+
reuse in other scenarios.
|
29
27
|
|
30
28
|
Usage
|
31
29
|
-----
|
@@ -60,7 +58,7 @@ body = "I am a rather elderly man..."
|
|
60
58
|
article = Article.new(title: title, body: body)
|
61
59
|
|
62
60
|
article.valid? #=> false
|
63
|
-
article.errors
|
61
|
+
article.errors[:state] #=> [:not_present]
|
64
62
|
```
|
65
63
|
|
66
64
|
Of course, what you would do instead is declare `:title` and `:body` as allowed
|
data/lib/scrivener.rb
CHANGED
@@ -25,13 +25,6 @@ class Scrivener
|
|
25
25
|
#
|
26
26
|
# Other validations are simply added on a per-model or per-project basis.
|
27
27
|
#
|
28
|
-
# If you want other validations you may want to take a peek at Ohm::Contrib
|
29
|
-
# and all of the validation modules it provides.
|
30
|
-
#
|
31
|
-
# @see http://cyx.github.com/ohm-contrib/doc/Ohm/WebValidations.html
|
32
|
-
# @see http://cyx.github.com/ohm-contrib/doc/Ohm/NumberValidations.html
|
33
|
-
# @see http://cyx.github.com/ohm-contrib/doc/Ohm/ExtraValidations.html
|
34
|
-
#
|
35
28
|
# @example
|
36
29
|
#
|
37
30
|
# class Quote
|
@@ -117,17 +110,14 @@ class Scrivener
|
|
117
110
|
assert(!send(att).to_s.empty?, error)
|
118
111
|
end
|
119
112
|
|
120
|
-
# Checks if all the characters of an attribute is a digit.
|
121
|
-
# verify that a value is a decimal, try looking at Ohm::Contrib's
|
122
|
-
# assert_decimal assertion.
|
113
|
+
# Checks if all the characters of an attribute is a digit.
|
123
114
|
#
|
124
115
|
# @param [Symbol] att The attribute you wish to verify the numeric format.
|
125
116
|
# @param [Array<Symbol, Symbol>] error The error that should be returned
|
126
117
|
# when the validation fails.
|
127
|
-
# @see http://cyx.github.com/ohm-contrib/doc/Ohm/NumberValidations.html
|
128
118
|
def assert_numeric(att, error = [att, :not_numeric])
|
129
119
|
if assert_present(att, error)
|
130
|
-
assert_format(att, /\A
|
120
|
+
assert_format(att, /\A\-?\d+\z/, error)
|
131
121
|
end
|
132
122
|
end
|
133
123
|
|
@@ -163,7 +153,7 @@ class Scrivener
|
|
163
153
|
end
|
164
154
|
end
|
165
155
|
|
166
|
-
DECIMAL = /\A(\d+)?(\.\d+)?\z/
|
156
|
+
DECIMAL = /\A\-?(\d+)?(\.\d+)?\z/
|
167
157
|
|
168
158
|
def assert_decimal(att, error = [att, :not_decimal])
|
169
159
|
assert_format att, DECIMAL, error
|
data/test/scrivener_test.rb
CHANGED
@@ -193,7 +193,7 @@ scope do
|
|
193
193
|
assert ! filter.valid?
|
194
194
|
assert_equal [:not_decimal], filter.errors[:a]
|
195
195
|
|
196
|
-
%w{10 10.1 10.100000 0.100000 .1000}.each do |a|
|
196
|
+
%w{10 10.1 10.100000 0.100000 .1000 -10}.each do |a|
|
197
197
|
filter = G.new(a: a)
|
198
198
|
assert filter.valid?
|
199
199
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrivener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
61
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.0.
|
62
|
+
rubygems_version: 2.0.14
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
65
|
summary: Validation frontend for models.
|