entity_rb 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/entity_rb.gemspec +1 -0
- data/lib/entity_rb/base.rb +22 -6
- data/lib/entity_rb/version.rb +1 -1
- data/spec/entity/base_spec.rb +28 -0
- data/spec/spec_helper.rb +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec533ea6b4d05e089556b5907f4aa520371e4d82
|
4
|
+
data.tar.gz: 0eb195f2c53c5780694289c529bf132a0a587527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f897bab77f8ee4a7c8b282ad4dc5c917b03c55abfe67db2f7457b47031a11b487002306be58e1d3930928d9c0ef0be33baf78ff3d237c64d70a094bfac75ed85
|
7
|
+
data.tar.gz: 424551ccf13c235ae7f47cb186e7acaa12c72ad353983d89afc0c08b190fd4c217cca040b4878fe919b2d84618989e8c317248023c39944a0533c70cd8111812
|
data/entity_rb.gemspec
CHANGED
data/lib/entity_rb/base.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
module Entity
|
2
2
|
class Base
|
3
|
-
|
4
|
-
attributes = {} unless args
|
3
|
+
attr_reader :attributes
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
5
|
+
def initialize(args={})
|
6
|
+
initialize_attributes(args || {})
|
9
7
|
|
10
8
|
set_attributes(args)
|
11
9
|
end
|
@@ -13,6 +11,16 @@ module Entity
|
|
13
11
|
def set_attributes(args)
|
14
12
|
end
|
15
13
|
|
14
|
+
def attributes=(args)
|
15
|
+
@attributes ||= {}
|
16
|
+
|
17
|
+
args.each do |key, value|
|
18
|
+
set_field(key, value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
alias initialize_attributes attributes=
|
23
|
+
|
16
24
|
def to_h
|
17
25
|
{}.tap do |hash|
|
18
26
|
fields.each do |key|
|
@@ -21,7 +29,6 @@ module Entity
|
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
|
-
alias attributes to_h
|
25
32
|
alias to_hash to_h
|
26
33
|
|
27
34
|
def self.fields
|
@@ -54,6 +61,15 @@ module Entity
|
|
54
61
|
end
|
55
62
|
end
|
56
63
|
|
64
|
+
def set_field(key, value)
|
65
|
+
key = key.to_sym
|
66
|
+
|
67
|
+
if fields.include? key
|
68
|
+
send("#{key}=", value)
|
69
|
+
@attributes[key] = value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
57
73
|
private
|
58
74
|
def self.parent
|
59
75
|
(respond_to?(:superclass) && superclass != Object) ? superclass : nil
|
data/lib/entity_rb/version.rb
CHANGED
data/spec/entity/base_spec.rb
CHANGED
@@ -257,4 +257,32 @@ describe Entity::Base do
|
|
257
257
|
subject
|
258
258
|
end
|
259
259
|
end
|
260
|
+
|
261
|
+
describe '#attributes=' do
|
262
|
+
let(:new_attributes) { { field3: 'new field3', field5: 'ignored' } }
|
263
|
+
let(:instance) { Test.new }
|
264
|
+
|
265
|
+
before do
|
266
|
+
class Test < Entity::Base
|
267
|
+
field :field1
|
268
|
+
field :field2
|
269
|
+
field :field3
|
270
|
+
field :field4
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
subject { instance.attributes = new_attributes }
|
275
|
+
|
276
|
+
it "sets new value to field3" do
|
277
|
+
subject
|
278
|
+
|
279
|
+
expect(instance.field3).to eq 'new field3'
|
280
|
+
end
|
281
|
+
|
282
|
+
it "does not add field5 to the attributes" do
|
283
|
+
subject
|
284
|
+
|
285
|
+
expect(instance.attributes['field5']).to be_nil
|
286
|
+
end
|
287
|
+
end
|
260
288
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entity_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Torres e Paulo Patto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-meta
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.0'
|
55
69
|
description: An Entity implementation in ruby to store all business logic from the
|
56
70
|
(so called) model.
|
57
71
|
email:
|