data_broker 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3e930d1eecce8f3489041add31efa05f55fe37f
4
- data.tar.gz: 6498d2b77f56db76ee2e8c2877ec7fe2a00726c9
3
+ metadata.gz: 3bdf2caa154cb9aff4167f9f3c34da98bc81d40b
4
+ data.tar.gz: 1ab25391bafc416d9bb155a180f5550bd9847ddf
5
5
  SHA512:
6
- metadata.gz: 4dbeaa7a41acd547750e23dc2bb82265c147be4910915fee5761e5b4b34010ef68c1cde031c8465118f6914504e78b630e9546549bdb44cce3199fcafeb18bc8
7
- data.tar.gz: 2d762759043a9a4b27d0dd97122c99c0275ff719861dc34ad7e18febda376bd1be31791f0780da4d19fdafe42173fcc9cc04b7f78a9931da0a83f77936773a71
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
 
@@ -1,3 +1,3 @@
1
1
  module DataBroker
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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.3.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-17 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus