data_broker 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_broker/value_object.rb +15 -0
- data/lib/data_broker/version.rb +1 -1
- data/spec/value_object_spec.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bdf2caa154cb9aff4167f9f3c34da98bc81d40b
|
4
|
+
data.tar.gz: 1ab25391bafc416d9bb155a180f5550bd9847ddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f54726074561fdcdbfd5815dde4ea327c0bd478adc6830fa75b3b97ccbe9d2a9a6c572c97723e555e74abb6f584e96ee7c9cb1ac806161f3069e040743ea9830
|
7
|
+
data.tar.gz: a697735fce73e3639fdc2a25d912268d27dce356e05a025f9716d5f4bb0205c2fb37ca3a7f0b2e7bdad6f0ec0bc553d5200c76bc6f4c348705b7594081ad827e
|
@@ -15,9 +15,24 @@ module DataBroker
|
|
15
15
|
def self.included(descendant)
|
16
16
|
descendant.send(:include, Virtus.value_object)
|
17
17
|
descendant.send(:include, ActiveSupport::Inflector)
|
18
|
+
descendant.send(:include, InstanceMethods)
|
18
19
|
descendant.extend(ClassMethods)
|
19
20
|
end
|
20
21
|
|
22
|
+
module InstanceMethods
|
23
|
+
def method_missing(method, *args, &block)
|
24
|
+
if method == :type
|
25
|
+
self.class.to_s
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def respond_to_missing?(method, include_private = false)
|
32
|
+
method == :type || super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
21
36
|
module ClassMethods
|
22
37
|
include ActiveSupport::Inflector
|
23
38
|
|
data/lib/data_broker/version.rb
CHANGED
data/spec/value_object_spec.rb
CHANGED
@@ -16,6 +16,14 @@ class TestValueObject
|
|
16
16
|
delegate :name, :to => :parent
|
17
17
|
end
|
18
18
|
|
19
|
+
class TestValueObjectWithType
|
20
|
+
include DataBroker.value_object
|
21
|
+
|
22
|
+
values do
|
23
|
+
attribute :type, String
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
19
27
|
describe DataBroker::ValueObject do
|
20
28
|
describe ".new" do
|
21
29
|
it "creates a new object" do
|
@@ -41,6 +49,21 @@ describe DataBroker::ValueObject do
|
|
41
49
|
end
|
42
50
|
end
|
43
51
|
|
52
|
+
describe "#type" do
|
53
|
+
it "adds a type method that returns the class name if type is not defined" do
|
54
|
+
obj = TestValueObject.new
|
55
|
+
expect(obj.type).to eq("TestValueObject")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "uses provided type if one already exists" do
|
59
|
+
obj1 = TestValueObjectWithType.new
|
60
|
+
obj2 = TestValueObjectWithType.new(:type => :foo)
|
61
|
+
|
62
|
+
expect(obj1.type).to be_nil
|
63
|
+
expect(obj2.type).to eq("foo")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
44
67
|
describe ".belongs_to" do
|
45
68
|
it "adds a lookup method" do
|
46
69
|
obj = TestValueObject.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|