scriba 0.0.1.alpha1 → 0.0.1.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scriba/assertions.rb +20 -1
- data/lib/scriba/partial_update.rb +9 -0
- data/lib/scriba.rb +12 -25
- data/scriba.gemspec +1 -1
- data/test/partial.rb +28 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc46acaf0eb146741ee1eab5e2465410dc6dae8d
|
4
|
+
data.tar.gz: 7686ab4fd5581a0536b38e3979bb3bd0473195cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4bf2701fd0b99e60045d59726b086cd8d29e4fd80a0acc14a2c4b9728feca5d5fc6217172aca9f51e50496478c9e0d4270e10bb0c15ef57488d5cbcfedd85f7
|
7
|
+
data.tar.gz: 0fb347174d7e93a78942cbbde070b8173f0c4e75248e0e74fbc1ae34e9bfa36801e69cacdbbde1bd08ccf8e57a14b4c7552c24d13e764d551935f6ff82ef703c
|
data/lib/scriba/assertions.rb
CHANGED
@@ -1,4 +1,23 @@
|
|
1
1
|
module Scriba::Assertions
|
2
|
+
def valid?
|
3
|
+
errors.clear
|
4
|
+
|
5
|
+
validate
|
6
|
+
|
7
|
+
return errors.empty?
|
8
|
+
end
|
9
|
+
|
10
|
+
def invalid?
|
11
|
+
return !valid?
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate
|
15
|
+
end
|
16
|
+
|
17
|
+
def errors
|
18
|
+
@errors ||= Hash.new { |hash, key| hash[key] = [] }
|
19
|
+
end
|
20
|
+
|
2
21
|
protected
|
3
22
|
|
4
23
|
EMAIL = /\A([\w\!\#$\%\&\'\*\+\-\/\=\?\^\end\|\}\~]+\.)*
|
@@ -51,6 +70,6 @@ module Scriba::Assertions
|
|
51
70
|
end
|
52
71
|
|
53
72
|
def add_error(att, options)
|
54
|
-
|
73
|
+
errors[att] << generate_message(options)
|
55
74
|
end
|
56
75
|
end
|
data/lib/scriba.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
class Scriba
|
2
2
|
require_relative "scriba/assertions"
|
3
3
|
require_relative "scriba/messages"
|
4
|
+
require_relative "scriba/partial_update"
|
4
5
|
|
5
6
|
include Scriba::Assertions
|
6
7
|
include Scriba::Messages
|
@@ -18,40 +19,26 @@ class Scriba
|
|
18
19
|
@attributes ||= []
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
+
def initialize(updates = {})
|
23
|
+
update(@_updates = updates)
|
24
|
+
end
|
22
25
|
|
23
|
-
def
|
24
|
-
|
26
|
+
def update(updates)
|
27
|
+
updates.each do |att, value|
|
25
28
|
accessor = "#{att}="
|
26
|
-
|
27
|
-
if respond_to?(accessor)
|
28
|
-
send(accessor, value)
|
29
|
-
end
|
29
|
+
send(accessor, value) if respond_to?(accessor)
|
30
30
|
end
|
31
|
-
|
32
|
-
@errors = Hash.new { |hash, key| hash[key] = [] }
|
33
31
|
end
|
34
32
|
|
35
33
|
def attributes
|
36
|
-
return slice(*
|
34
|
+
return slice(*__attributes)
|
37
35
|
end
|
38
36
|
|
39
|
-
def
|
40
|
-
return
|
37
|
+
def __attributes
|
38
|
+
return self.class.attributes
|
41
39
|
end
|
42
40
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
validate
|
47
|
-
|
48
|
-
return @errors.empty?
|
49
|
-
end
|
50
|
-
|
51
|
-
def invalid?
|
52
|
-
return !valid?
|
53
|
-
end
|
54
|
-
|
55
|
-
def validate
|
41
|
+
def slice(*atts)
|
42
|
+
return atts.each_with_object({}) { |att, hash| hash[att] = send(att) }
|
56
43
|
end
|
57
44
|
end
|
data/scriba.gemspec
CHANGED
data/test/partial.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class Signup < Scriba
|
4
|
+
include Scriba::PartialUpdate
|
5
|
+
|
6
|
+
attribute :username
|
7
|
+
attribute :password
|
8
|
+
|
9
|
+
def validate
|
10
|
+
assert_present(:username)
|
11
|
+
assert_present(:password)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
test "return only passed attributes" do
|
16
|
+
attrs = { username: "me" }
|
17
|
+
signup = Signup.new(attrs)
|
18
|
+
|
19
|
+
assert_equal(attrs, signup.attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "validate given attributes" do
|
23
|
+
attrs = { username: "" }
|
24
|
+
signup = Signup.new(attrs)
|
25
|
+
|
26
|
+
assert !signup.valid?
|
27
|
+
assert_equal [:username], signup.errors.keys
|
28
|
+
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.alpha2
|
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-
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
@@ -37,11 +37,13 @@ files:
|
|
37
37
|
- lib/scriba.rb
|
38
38
|
- lib/scriba/assertions.rb
|
39
39
|
- lib/scriba/messages.rb
|
40
|
+
- lib/scriba/partial_update.rb
|
40
41
|
- makefile
|
41
42
|
- scriba.gemspec
|
42
43
|
- test/assertions.rb
|
43
44
|
- test/attributes.rb
|
44
45
|
- test/helper.rb
|
46
|
+
- test/partial.rb
|
45
47
|
homepage: https://github.com/harmoni/scriba
|
46
48
|
licenses:
|
47
49
|
- MIT
|