dry-data 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/dry/data/struct.rb +12 -0
- data/lib/dry/data/type/hash.rb +5 -1
- data/lib/dry/data/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25b19951b05ff45b26a3b49697be290ca1d158e1
|
4
|
+
data.tar.gz: e33200c58bb1e9cc283385f4ec17ee1b47892d8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebbc4fa62ef404c3f12af3d49ab7272a92de00400606aee3ca280ebfa0cae73191419c3f36e89730ba76848713d4a92dfb7555020fb6badfe25d8d3fbba2dc61
|
7
|
+
data.tar.gz: 51acb033f6d282060d3170d7d9c029349af1a0da3574617d8129e9fe68c8d14664a041e9fd1b5ecfb86204311fe6883939509d03c88d4e35cc192fd721bbbeed
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# v0.4.1 2015-12-11
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
* `Dry::Data::Struct#to_hash` with `to_h` as alias (solnic)
|
6
|
+
* `Dry::Data::Struct#[]` for reading attribute values (solnic)
|
7
|
+
* Ability to pass any class to hash schema assuming it has a corresponding type registered (solnic)
|
8
|
+
|
9
|
+
[Compare v0.4.0...v0.4.1](https://github.com/dryrb/dry-data/compare/v0.4.0...v0.4.1)
|
10
|
+
|
1
11
|
# v0.4.0 2015-12-11
|
2
12
|
|
3
13
|
## Added
|
data/lib/dry/data/struct.rb
CHANGED
@@ -39,6 +39,18 @@ module Dry
|
|
39
39
|
def initialize(attributes)
|
40
40
|
attributes.each { |key, value| instance_variable_set("@#{key}", value) }
|
41
41
|
end
|
42
|
+
|
43
|
+
def [](name)
|
44
|
+
public_send(name)
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_hash
|
48
|
+
self.class.schema.keys.each_with_object({}) { |key, result|
|
49
|
+
value = self[key]
|
50
|
+
result[key] = value.respond_to?(:to_hash) ? value.to_hash : value
|
51
|
+
}
|
52
|
+
end
|
53
|
+
alias_method :to_h, :to_hash
|
42
54
|
end
|
43
55
|
end
|
44
56
|
end
|
data/lib/dry/data/type/hash.rb
CHANGED
@@ -49,7 +49,11 @@ module Dry
|
|
49
49
|
|
50
50
|
def schema(type_map, meth = :safe_constructor)
|
51
51
|
value_constructors = type_map.each_with_object({}) { |(name, type), result|
|
52
|
-
result[name] =
|
52
|
+
result[name] =
|
53
|
+
case type
|
54
|
+
when String, Class then Data[type]
|
55
|
+
else type
|
56
|
+
end
|
53
57
|
}
|
54
58
|
|
55
59
|
self.class.new(
|
data/lib/dry/data/version.rb
CHANGED