hexx-entities 0.1.1 → 0.2.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: 5c93ee8a3d4271e91a696427b35b8a6ba05da2a0
4
- data.tar.gz: 6f69ca96cbb85cbafbf36a9b8946552f3cdc69b2
3
+ metadata.gz: 04667c21ab81ba4a9e2c69c734d0eb1da0f5259e
4
+ data.tar.gz: fc9d3d1826fb1751813c145128ce5f1b88a182e5
5
5
  SHA512:
6
- metadata.gz: 10b1cdf1f6695351854f948df670eb34104ae9e6bce235619847d559d4a15454ad58085039fbd565d428f0ce6b0633e53252c718f9bc6d425ae19fa122d9cb3b
7
- data.tar.gz: 417fe608dfa733f29eb8a198698cc5e2b730c07fb0af8a91bffa757a285d85d5ed7f259073a724cff8f0f9276d27254018af1c5cfd48e3985d247bba2940a6ee
6
+ metadata.gz: 1b3c8514ef9a5f8717ec931d21a28da63cfa86ea5da2b1609195913aaa3e7de00e06b3522f3f41a7bac56548af1d42597dd65f0ff59d24a7065ac3060ec481f1
7
+ data.tar.gz: 0863e2cc356a59c2f74f731f1c3fbc69bbf0e8ccb47799c7245c06be63abfe4343a9955b4de46e347ef232f3784a3e176f42dc7166baced3cd6814094405a44e
data/Guardfile CHANGED
@@ -4,11 +4,11 @@ guard :rspec, cmd: "bundle exec rspec" do
4
4
 
5
5
  watch(%r{^spec/tests/.+_spec\.rb$})
6
6
 
7
- watch(%r{^lib/hexx/entities/(.+)\.rb}) do |m|
7
+ watch(%r{^lib/hexx-entities/(.+)\.rb}) do |m|
8
8
  "spec/tests/#{ m[1] }_spec.rb"
9
9
  end
10
10
 
11
- watch(%r{^lib/\w+\.rb$}) { "spec" }
12
- watch("spec/spec_helper.rb") { "spec" }
11
+ watch("lib/hexx-entities.rb") { "spec" }
12
+ watch("spec/spec_helper.rb") { "spec" }
13
13
 
14
14
  end # guard :rspec
@@ -1,5 +1,5 @@
1
1
  $:.push File.expand_path("../lib", __FILE__)
2
- require "hexx/entities/version"
2
+ require "hexx-entities/version"
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
 
@@ -4,15 +4,19 @@ require "attestor" # for validations
4
4
  require "eigindir" # for attributes
5
5
  require "securerandom" # for uuids
6
6
 
7
- # Module Hexx provides the shared namespace for 'hexx' collection of gems
7
+ # Shared namespace for the hexx collection of modules
8
8
  #
9
- # @author Andrew Kozin <Andrew.Kozin@gmail.com>
10
9
  module Hexx
11
10
 
12
- require_relative "hexx/entities" # for namespace
13
- require_relative "hexx/entities/part"
14
- require_relative "hexx/entities/uuid"
15
- require_relative "hexx/entities/uuids"
16
- require_relative "hexx/entities/base"
11
+ # Module Entities provides a base class for domain entities
12
+ #
13
+ module Entities
14
+
15
+ require_relative "hexx-entities/part"
16
+ require_relative "hexx-entities/uuid"
17
+ require_relative "hexx-entities/uuids"
18
+ require_relative "hexx-entities/base"
19
+
20
+ end # module Entities
17
21
 
18
22
  end # module Hexx
@@ -46,10 +46,15 @@ module Hexx::Entities
46
46
  #
47
47
  # @return [Hash]
48
48
  def serialize
49
- values = attributes.values.map do |item|
50
- item.respond_to?(:serialize) ? item.serialize : item
51
- end
52
- attributes.keys.zip(values).to_h
49
+ attributes.map { |key, value| [key, serialize__(value)] }.to_h
50
+ end
51
+
52
+ private
53
+
54
+ def serialize__(value)
55
+ return value.serialize if value.respond_to? :serialize
56
+ return value.map { |item| serialize__(item) } if value.is_a? Array
57
+ value
53
58
  end
54
59
 
55
60
  end # class Part
@@ -6,7 +6,7 @@ module Hexx
6
6
 
7
7
  # The semantic version of the module.
8
8
  # @see http://semver.org/ Semantic versioning 2.0
9
- VERSION = "0.1.1".freeze
9
+ VERSION = "0.2.0".freeze
10
10
 
11
11
  end # module Entities
12
12
 
@@ -39,15 +39,18 @@ describe Hexx::Entities::Part do
39
39
 
40
40
  before { klass.attribute :foo }
41
41
  before { klass.attribute :bar }
42
+ before { klass.attribute :qux }
42
43
 
43
44
  let(:bar) { double }
44
45
  let(:baz) { double serialize: { baz: :baz } }
46
+ let(:qux) { [bar, baz] }
45
47
  let(:uuids) { [SecureRandom.uuid] }
46
48
 
47
- subject(:entity) { klass.new(foo: bar, bar: baz) }
49
+ subject(:entity) { klass.new(foo: bar, bar: baz, qux: qux) }
48
50
 
49
51
  it "returns a nested hash" do
50
- expect(entity.serialize).to eq(foo: bar, bar: { baz: :baz })
52
+ expect(entity.serialize)
53
+ .to eq(foo: bar, bar: { baz: :baz }, qux: [bar, { baz: :baz }])
51
54
  end
52
55
 
53
56
  end # describe #to_hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexx-entities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin
@@ -85,12 +85,11 @@ files:
85
85
  - config/metrics/yardstick.yml
86
86
  - hexx-entities.gemspec
87
87
  - lib/hexx-entities.rb
88
- - lib/hexx/entities.rb
89
- - lib/hexx/entities/base.rb
90
- - lib/hexx/entities/part.rb
91
- - lib/hexx/entities/uuid.rb
92
- - lib/hexx/entities/uuids.rb
93
- - lib/hexx/entities/version.rb
88
+ - lib/hexx-entities/base.rb
89
+ - lib/hexx-entities/part.rb
90
+ - lib/hexx-entities/uuid.rb
91
+ - lib/hexx-entities/uuids.rb
92
+ - lib/hexx-entities/version.rb
94
93
  - spec/spec_helper.rb
95
94
  - spec/tests/base_spec.rb
96
95
  - spec/tests/part_spec.rb
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Hexx
4
-
5
- # Module Entities provides a base class for domain entities
6
- #
7
- # @example (see Hexx::Entities::Base)
8
- #
9
- # @author Andrew Kozin <Andrew.Kozin@gmail.com>
10
- module Entities
11
-
12
- end # module Entities
13
-
14
- end # module Hexx