ethos 0.2.0.beta4 → 0.2.0.beta5
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/ethos/attributes.rb +22 -10
- data/lib/ethos/entity.rb +8 -2
- data/lib/ethos/schema.rb +3 -2
- data/lib/ethos/version.rb +1 -1
- data/spec/ethos/attributes.rb +16 -0
- data/spec/ethos/entity.rb +58 -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: c27f8f8f52e943a5a3e0f4001bd2dbd0e51dfde2
|
4
|
+
data.tar.gz: d9934aa42583ef5992e77ca9aa2ff70b1eff97f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409a53cba266a6c85d9f063f2ac3b5f001fa9ccab7141a351af1df5f91cbae5522d39cb130fe027a3e4fcdeb6bf04dac96194a9f514befe6dc5d168e87cbdd47
|
7
|
+
data.tar.gz: 8e30891588e5433b6454c4986985d3eb4d8da22009f85c69d5c5a79777f34e2225f32fdd57e0e3b75495df8be4fd8365def92f6f35da3eb0ceaaa0ab82f23432
|
data/lib/ethos/attributes.rb
CHANGED
@@ -18,23 +18,27 @@ module Ethos
|
|
18
18
|
@_schema = schema
|
19
19
|
|
20
20
|
schema.defaults.each do |key, value|
|
21
|
-
initial[key] = value
|
22
|
-
current[key] = value
|
21
|
+
initial[key] = current[key] = value
|
23
22
|
end
|
24
23
|
|
25
|
-
|
26
|
-
key
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
current[key] = value
|
24
|
+
schema.attributes.keys.each do |key|
|
25
|
+
if values.key? key
|
26
|
+
initial[key] = current[key] = values[key]
|
27
|
+
elsif values.key? String key
|
28
|
+
initial[key] = current[key] = values[String key]
|
29
|
+
end
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
35
33
|
def [](key)
|
36
34
|
memoize key do
|
37
|
-
|
35
|
+
value = Ethos::Type.cast current[key], schema.attributes[key][:type]
|
36
|
+
|
37
|
+
schema.attributes[key][:extensions].each do |extension|
|
38
|
+
value.instance_eval &extension
|
39
|
+
end
|
40
|
+
|
41
|
+
value
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
@@ -44,6 +48,14 @@ module Ethos
|
|
44
48
|
current[key] = value
|
45
49
|
end
|
46
50
|
|
51
|
+
def ==(other)
|
52
|
+
return false unless other.is_a? self.class
|
53
|
+
|
54
|
+
not schema.attributes.keys.any? do |key|
|
55
|
+
self[key] != other[key]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
47
59
|
private
|
48
60
|
|
49
61
|
def memoized
|
data/lib/ethos/entity.rb
CHANGED
@@ -8,8 +8,8 @@ module Ethos
|
|
8
8
|
@_schema ||= Ethos::Schema.new
|
9
9
|
end
|
10
10
|
|
11
|
-
def attribute(key, type, default: nil)
|
12
|
-
schema.define key, type, default: default
|
11
|
+
def attribute(key, type, default: nil, &extension)
|
12
|
+
schema.define key, type, default: default, extensions: [extension].compact
|
13
13
|
|
14
14
|
reader = :"#{key}"
|
15
15
|
writer = :"#{key}="
|
@@ -37,5 +37,11 @@ module Ethos
|
|
37
37
|
def attributes
|
38
38
|
@_attributes
|
39
39
|
end
|
40
|
+
|
41
|
+
def ==(other)
|
42
|
+
return false unless other.is_a? self.class
|
43
|
+
|
44
|
+
self.attributes == other.attributes
|
45
|
+
end
|
40
46
|
end
|
41
47
|
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)
|
11
|
+
def define(key, type, default: nil, extensions: [])
|
12
12
|
attributes[key] = {
|
13
13
|
type: type,
|
14
|
-
default: default
|
14
|
+
default: default,
|
15
|
+
extensions: extensions
|
15
16
|
}
|
16
17
|
|
17
18
|
defaults[key] = default if default
|
data/lib/ethos/version.rb
CHANGED
data/spec/ethos/attributes.rb
CHANGED
@@ -46,3 +46,19 @@ scope do
|
|
46
46
|
asserts(attributes[:value]) == 1
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
scope do
|
51
|
+
spec do
|
52
|
+
this = Ethos::Attributes.new schema, values: {value: 1}
|
53
|
+
that = Ethos::Attributes.new schema, values: {value: 1}
|
54
|
+
|
55
|
+
asserts(this) == that
|
56
|
+
end
|
57
|
+
|
58
|
+
spec do
|
59
|
+
this = Ethos::Attributes.new schema, values: {value: 1}
|
60
|
+
that = Ethos::Attributes.new schema, values: {value: 2}
|
61
|
+
|
62
|
+
refutes(this) == that
|
63
|
+
end
|
64
|
+
end
|
data/spec/ethos/entity.rb
CHANGED
@@ -66,6 +66,40 @@ scope do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
scope do
|
70
|
+
setup do
|
71
|
+
class Entity
|
72
|
+
prepend Ethos::Entity
|
73
|
+
|
74
|
+
attribute :value, String do
|
75
|
+
def extended?
|
76
|
+
true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
spec do
|
83
|
+
entity = Entity.new
|
84
|
+
|
85
|
+
asserts(entity.value).extended?
|
86
|
+
end
|
87
|
+
|
88
|
+
spec do
|
89
|
+
entity = Entity.new value: '1'
|
90
|
+
|
91
|
+
asserts(entity.value).extended?
|
92
|
+
end
|
93
|
+
|
94
|
+
spec do
|
95
|
+
entity = Entity.new
|
96
|
+
|
97
|
+
entity.value = '1'
|
98
|
+
|
99
|
+
asserts(entity.value).extended?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
69
103
|
scope do
|
70
104
|
setup do
|
71
105
|
class Entity
|
@@ -96,3 +130,27 @@ scope do
|
|
96
130
|
end
|
97
131
|
end
|
98
132
|
end
|
133
|
+
|
134
|
+
scope do
|
135
|
+
setup do
|
136
|
+
class Entity
|
137
|
+
prepend Ethos::Entity
|
138
|
+
|
139
|
+
attribute :value, Integer
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
spec do
|
144
|
+
this = Entity.new value: 1
|
145
|
+
that = Entity.new value: 1
|
146
|
+
|
147
|
+
asserts(this) == that
|
148
|
+
end
|
149
|
+
|
150
|
+
spec do
|
151
|
+
this = Entity.new value: 1
|
152
|
+
that = Entity.new value: 2
|
153
|
+
|
154
|
+
refutes(this) == that
|
155
|
+
end
|
156
|
+
end
|
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}
|
11
|
+
asserts(schema.attributes[:value]) == {type: Integer, default: 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}
|
25
|
+
asserts(schema.attributes[:value]) == {type: Integer, default: 1, 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.beta5
|
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-03-
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|