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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8204add8315ec4efed8923ffb753d5e670e56b3
4
- data.tar.gz: 1a9bd0c932aa43bbdeba519cc00b5bae7ccfdfbd
3
+ metadata.gz: 25b19951b05ff45b26a3b49697be290ca1d158e1
4
+ data.tar.gz: e33200c58bb1e9cc283385f4ec17ee1b47892d8c
5
5
  SHA512:
6
- metadata.gz: 5d0dea2a50e1b8a212c43eec8cd10ca463c53fa1cb8982db307f29fdf397c006fd7febe9c0fbabd2f146f94112f0a1bfcfdde627a94e80ce82a53548b4674876
7
- data.tar.gz: a364d893f9d2bf9a4aba61970020ded68f136ca3bc8877a06783aa37e7ffcc0e4436acd629ad165cb1448a29460b3dd0b0290df747d1928a1228e7afbfad7646
6
+ metadata.gz: ebbc4fa62ef404c3f12af3d49ab7272a92de00400606aee3ca280ebfa0cae73191419c3f36e89730ba76848713d4a92dfb7555020fb6badfe25d8d3fbba2dc61
7
+ data.tar.gz: 51acb033f6d282060d3170d7d9c029349af1a0da3574617d8129e9fe68c8d14664a041e9fd1b5ecfb86204311fe6883939509d03c88d4e35cc192fd721bbbeed
@@ -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
@@ -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
@@ -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] = type.is_a?(String) ? Data[type] : type
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(
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Data
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.4.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica