entity_store 0.3.4 → 0.3.5

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: 6059057a520f33be6535455e2fb3a8bb06dcad9e
4
- data.tar.gz: eed17da359fd9c16574f0916f43a680a8e0b12b3
3
+ metadata.gz: a15a515aaab833170cd1874dd0ed2bcb878747d6
4
+ data.tar.gz: c5f62d569ebace43e4ac6f3f18de1ede780b1c25
5
5
  SHA512:
6
- metadata.gz: bd204c5bbd3e992ae69a7b59839d0c0a14025893707740c6d28eac34f9507a79c0886d9d26ed7b2a49913e0f98a0d64c862cb9f20b259ce3af5125c81044738b
7
- data.tar.gz: 40732c9907edf1e4e2e7708f3603fef57a4a616b00a06227e22238f9b55a8f42667f40e3b6476bd4353a14614625929893082789e7c63116ffa3d233b4f99276
6
+ metadata.gz: af5c80820dc57d1904b6d5f64d4742004a851fc5782b12a33ed56ece03a528d6fd55cc96644ff929ed1ded844492eedc11e9d9dae9578992fa6873a542a722b4
7
+ data.tar.gz: 06d3cef2139723f728274332e512a2b0e8f30686421dfa7825d3816d6eaf6dce1ac598bb204c784c4295412e651556fd1fca5b01a0ceb8b82bcc52d60cf2435f
@@ -26,21 +26,25 @@ module EntityStore
26
26
  end
27
27
 
28
28
  def entity_value_array_attribute name, klass
29
- define_method(name) {
30
- instance_variable_get("@_#{name}") || instance_variable_set("@_#{name}", [])
31
- }
29
+ variable_name = "@_#{name}".to_sym
32
30
 
33
- define_method("#{name}=") do |value|
34
- value.each do |item|
35
- case item
31
+ define_method(name) do
32
+ instance_variable_get(variable_name) || instance_variable_set(variable_name, [])
33
+ end
34
+
35
+ define_method("#{name}=") do |values|
36
+ mapped_values = values.map do |value|
37
+ case value
36
38
  when Hash
37
- send(name) << klass.new(item)
39
+ klass.new(value)
38
40
  when klass
39
- send(name) << item
41
+ value
40
42
  else
41
- raise ArgumentError.new("#{item.class.name} not supported. Expecting #{klass.name}")
43
+ raise ArgumentError.new("#{value.class} not supported. Expecting #{klass.name}")
42
44
  end
43
45
  end
46
+
47
+ instance_variable_set(variable_name, mapped_values)
44
48
  end
45
49
  end
46
50
 
@@ -24,6 +24,9 @@ module EntityStore
24
24
  attrs
25
25
  end
26
26
 
27
+ alias_method :to_hash, :attributes
28
+ alias_method :to_h, :attributes
29
+
27
30
  def attribute_methods
28
31
  public_methods
29
32
  .select { |m| m =~ /\w\=$/ }
@@ -1,3 +1,3 @@
1
1
  module EntityStore
2
- VERSION = "0.3.4".freeze
2
+ VERSION = "0.3.5".freeze
3
3
  end
@@ -131,6 +131,18 @@ describe Entity do
131
131
  expect { entity.things = items }.to raise_error(ArgumentError)
132
132
  end
133
133
  end
134
+ context "when already populated" do
135
+ let(:items) { [ ThingEntityValue.new(name: random_string), ThingEntityValue.new(name: random_string)] }
136
+
137
+ before(:each) do
138
+ entity.things = [{ name: random_string }, { name: random_string }]
139
+ entity.things = items
140
+ end
141
+
142
+ it "should replace the contents" do
143
+ entity.things.should eq(items)
144
+ end
145
+ end
134
146
  end
135
147
 
136
148
  describe "getter" do
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entity_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bird
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.8'
20
20
  type: :runtime
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: '1.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bson_ext
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.8'
34
34
  type: :runtime
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: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hatchet
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.2'
55
55
  description: Event sourced entity store with a replaceable body
@@ -96,12 +96,12 @@ require_paths:
96
96
  - lib
97
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - ">="
99
+ - - '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - ">="
104
+ - - '>='
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []