structure 0.25.1 → 0.26.0

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: 12c6920942010f99e7c1e26fed12d0cd07d28788
4
- data.tar.gz: 67f298813aa7f59d7e4e7c737363f82f6d4ac180
3
+ metadata.gz: 7d836fcee886c983c153695e9d454e42b8ff53ee
4
+ data.tar.gz: 1b7ebe258505000bb9156f672959ddfaae5608c6
5
5
  SHA512:
6
- metadata.gz: c90c4ad394683b5d8f4e425b0024b5ba2ef6d8664f76ba5e266987b91010ac0c6d18d8bc1f0c587c5b0a446ee9b076029d2e1e1ce9acef51872cae175cd25021
7
- data.tar.gz: 1148c4a09f718b4441a1a3f8c4a072f4c1f4edd18dfec79676d9022874a41d2be4495cebe6d6ae4214733ba9fadc780212c92e46b05c6650a5676f351c41693a
6
+ metadata.gz: ec1d7492bc4806441940ec83dca67afef6e445112cf8d025d6326fdc9b65b59300c8dcddd0a8510abb9ae7eff26a870a2151035478e5aa9e101a8994faf4ed4f
7
+ data.tar.gz: d054f3f46d0759b1fa1044ee56357e77f361bf0fd53b1253d3e683bc4ef579762cb5ca92d48c628183c4363b7198ef8af5b8ee63b536c70c024c0a3c13892871
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
+ bin
3
4
  coverage
4
- pkg/*
5
+ pkg
5
6
  Gemfile.lock
@@ -1,3 +1,3 @@
1
1
  module Structure
2
- VERSION = '0.25.1'
2
+ VERSION = '0.26.0'
3
3
  end
data/lib/structure.rb CHANGED
@@ -10,7 +10,10 @@ module Structure
10
10
 
11
11
  vals
12
12
  end
13
- alias :to_h :values
13
+
14
+ def to_h
15
+ Hash[values.dup.map { |k, v| [k, v.respond_to?(:to_h) ? v.to_h : v] } ]
16
+ end
14
17
 
15
18
  def ==(other)
16
19
  values == other.values
@@ -57,4 +57,27 @@ class StructureTest < MiniTest::Test
57
57
 
58
58
  assert_equal({ latitude: 10, longitude: 100, name: 'foo' }, obj.values)
59
59
  end
60
+
61
+ def test_recursively_casts_to_hash
62
+ city_class = Class.new do
63
+ include Structure
64
+
65
+ attr :res
66
+
67
+ def initialize(res)
68
+ @res = res
69
+ end
70
+
71
+ value :name do
72
+ res.fetch(:name)
73
+ end
74
+
75
+ value :location do
76
+ Location.new(res.fetch(:loc))
77
+ end
78
+ end
79
+
80
+ city = city_class.new(name: 'London', loc: { lat: 51.5, lng: 0.1 })
81
+ assert_equal({ name: 'London', location: { latitude: 51.5, longitude: 0.1 }}, city.to_h)
82
+ end
60
83
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.1
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Value objects in Ruby
@@ -45,7 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE
51
51
  - README.md
@@ -64,17 +64,17 @@ require_paths:
64
64
  - lib
65
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.0.5
77
+ rubygems_version: 2.2.0
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Value objects in Ruby