ethos 0.2.0.beta10 → 0.2.0.beta11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ethos/attributes.rb +6 -1
- data/lib/ethos/entity.rb +3 -3
- data/lib/ethos/schema.rb +2 -1
- data/lib/ethos/version.rb +1 -1
- data/spec/ethos/entity.rb +28 -0
- data/spec/ethos/schema.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99cd1b8a90c428cda94c068cd4d4a5d870e7a99e
|
4
|
+
data.tar.gz: cb33a0ce5ba5e44949ee83be7a474447e2de73fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d118062efe920c99f05d5dcc89d0fc66d5e1ef68594d1af2a642314b851a545674b8bbb23d032aa852f9d4cd845593a612cafe916fbe5b360e56dc1dd0e5ba0
|
7
|
+
data.tar.gz: 014147ee67124c927f940cfd594f00e608699576c55b8172071af0cadadb966e6a2ccb49346c958a0abdb6fde7148c2c54142c34d17886f29a84311b40ce8885
|
data/lib/ethos/attributes.rb
CHANGED
@@ -32,7 +32,12 @@ module Ethos
|
|
32
32
|
|
33
33
|
def [](key)
|
34
34
|
memoize key do
|
35
|
-
|
35
|
+
type = schema.attributes[key][:type]
|
36
|
+
|
37
|
+
raw = current[key]
|
38
|
+
raw = schema.attributes[key][:nothing] if raw.nil?
|
39
|
+
|
40
|
+
value = Ethos::Type.cast raw, type
|
36
41
|
|
37
42
|
schema.attributes[key][:extensions].each do |extension|
|
38
43
|
value.instance_eval &extension
|
data/lib/ethos/entity.rb
CHANGED
@@ -9,8 +9,8 @@ module Ethos
|
|
9
9
|
@_schema ||= Ethos::Schema.new
|
10
10
|
end
|
11
11
|
|
12
|
-
def attribute(key, type, default: nil, &extension)
|
13
|
-
schema.define key, type, default: default, extensions: [extension].compact
|
12
|
+
def attribute(key, type, default: nil, nothing: nil, &extension)
|
13
|
+
schema.define key, type, default: default, nothing: nothing, extensions: [extension].compact
|
14
14
|
|
15
15
|
reader = :"#{key}"
|
16
16
|
writer = :"#{key}="
|
@@ -25,7 +25,7 @@ module Ethos
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def collection(key, type)
|
28
|
-
attribute key, Ethos::Collection,
|
28
|
+
attribute key, Ethos::Collection, nothing: []
|
29
29
|
|
30
30
|
schema.attributes[key][:extensions].push Proc.new { self.type = type }
|
31
31
|
end
|
data/lib/ethos/schema.rb
CHANGED
@@ -8,10 +8,11 @@ module Ethos
|
|
8
8
|
@_defaults ||= {}
|
9
9
|
end
|
10
10
|
|
11
|
-
def define(key, type, default: nil, extensions: [])
|
11
|
+
def define(key, type, default: nil, nothing: nil, extensions: [])
|
12
12
|
attributes[key] = {
|
13
13
|
type: type,
|
14
14
|
default: default,
|
15
|
+
nothing: nothing,
|
15
16
|
extensions: extensions
|
16
17
|
}
|
17
18
|
|
data/lib/ethos/version.rb
CHANGED
data/spec/ethos/entity.rb
CHANGED
@@ -71,6 +71,34 @@ scope do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
scope do
|
75
|
+
setup do
|
76
|
+
class Entity
|
77
|
+
prepend Ethos::Entity
|
78
|
+
|
79
|
+
attribute :value, Integer, nothing: 1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
spec do
|
84
|
+
entity = Entity.new
|
85
|
+
|
86
|
+
asserts(entity.value) == 1
|
87
|
+
end
|
88
|
+
|
89
|
+
spec do
|
90
|
+
entity = Entity.new value: nil
|
91
|
+
|
92
|
+
asserts(entity.value) == 1
|
93
|
+
end
|
94
|
+
|
95
|
+
spec do
|
96
|
+
entity = Entity.new value: 2
|
97
|
+
|
98
|
+
asserts(entity.value) == 2
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
74
102
|
scope do
|
75
103
|
setup do
|
76
104
|
class Entity
|
data/spec/ethos/schema.rb
CHANGED
@@ -8,7 +8,7 @@ scope do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
spec do
|
11
|
-
asserts(schema.attributes[:value]) == {type: Integer, default: nil, extensions: []}
|
11
|
+
asserts(schema.attributes[:value]) == {type: Integer, default: nil, nothing: nil, extensions: []}
|
12
12
|
end
|
13
13
|
|
14
14
|
spec do
|
@@ -22,7 +22,7 @@ scope do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
spec do
|
25
|
-
asserts(schema.attributes[:value]) == {type: Integer, default: 1, extensions: []}
|
25
|
+
asserts(schema.attributes[:value]) == {type: Integer, default: 1, nothing: nil, extensions: []}
|
26
26
|
end
|
27
27
|
|
28
28
|
spec do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.
|
4
|
+
version: 0.2.0.beta11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erol Fornoles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|