multitype 0.0.1 → 0.0.2

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: 31fd13aa6edb45c77dff6a27f1f0e86205b26058
4
- data.tar.gz: 34651ec1ffb2ae2067988b8bbd3d39a17ba0e16f
3
+ metadata.gz: d0be09639666335fce74afed223dbcd4b43e4a79
4
+ data.tar.gz: e94e9a6f4817d0640f03bdeb24f462ba599b700e
5
5
  SHA512:
6
- metadata.gz: 6453bac963334d070f745ae156e3030c30c4a0a9e03192b14d06fe17c5d5632516bf9268d7f579526af7851ba9961c704dec0c9719ed50516a7b061cdd9015d2
7
- data.tar.gz: c48478da8607993dfd77103094fff64eca7c8fc2df102e5ad55c671e85352bde606d10908cbd9ee31a199e4f1c938c12e5de0c1eebe6d3d0cd4f403336061dec
6
+ metadata.gz: 08737b68bef83c843befce142e19a756163a19c51a6a2a60d835bc6ff07261678938540ef93a81d268970a40be361ece20aa86fc3aaadf4c30f76d6a962f2e31
7
+ data.tar.gz: ee82b279a1450e96a347dcad1f76cde7c8ae4a1a4fc67336bd045bc838282e9d45aed2a92dbfaac61f9614f8f89e0c467251900b2b73563547eca1694a8a2378
data/lib/multitype.rb CHANGED
@@ -27,14 +27,22 @@ module Multitype
27
27
  module ClassMethods
28
28
 
29
29
  def type_comparator(type, *comparators)
30
- __send__(:attr_accessor, *comparators)
30
+ new_comparators = comparators.inject({}) do |out, comparator|
31
+ if comparator.is_a?(Hash)
32
+ out.merge(comparator)
33
+ else
34
+ out.merge({comparator => comparator})
35
+ end
36
+ end
37
+
38
+ __send__(:attr_accessor, *new_comparators.keys)
31
39
  __create_multitype_datastore__
32
40
 
33
41
  # Get the type name if a typeset is passed as an object
34
42
  type = type.type if type.is_a?(Object) && type.respond_to?(:__multitype_typeset__)
35
43
 
36
44
  # Append to the list comparator columns
37
- __update_multitype_cache__(type, :comparators, comparators)
45
+ __update_multitype_cache__(type, :comparators, new_comparators)
38
46
  end
39
47
 
40
48
  def type_alias(type, *aliases)
@@ -121,11 +129,11 @@ module Multitype
121
129
  match = true # Did we find a match
122
130
 
123
131
  # Loop through the type comparators to find a match
124
- __get_multitype_cache__(type, :comparators).each do |comparator|
132
+ __get_multitype_cache__(type, :comparators).each do |model_comparator, typeset_comparator|
125
133
 
126
134
  # Check the comparator for a match
127
- match = if typeset.respond_to?(comparator) && self.respond_to?(comparator)
128
- typeset.__send__(comparator) == self.__send__(comparator)
135
+ match = if typeset.respond_to?(typeset_comparator) && self.respond_to?(model_comparator)
136
+ typeset.__send__(typeset_comparator) == self.__send__(model_comparator)
129
137
  else
130
138
  false
131
139
  end
@@ -1,3 +1,3 @@
1
1
  module Multitype
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -23,6 +23,20 @@ class FakeModel
23
23
  end
24
24
  end
25
25
 
26
+ type_comparator :apple, compare: :title
27
+
28
+ deftype :apple, 'Testing Hash Comparator 1', title: :tree do
29
+ def run
30
+ :tree
31
+ end
32
+ end
33
+
34
+ deftype :apple, 'Testing Hash Comparator 2', title: :pie do
35
+ def run
36
+ :pie
37
+ end
38
+ end
39
+
26
40
  deftype :general, 'APrefined', class: ATypeSet
27
41
  deftype :general, 'BPrefined', class: BTypeSet
28
42
 
@@ -36,6 +36,16 @@ describe "Test the multitype with FakeModel" do
36
36
  result = FakeModel.new.override.run()
37
37
  result.should == :works
38
38
  end
39
+
40
+ it "Should use a hash for comparing multiple typesets 1" do
41
+ result = FakeModel.new(:tree).apple.run()
42
+ result.should == :tree
43
+ end
44
+
45
+ it "Should use a hash for comparing multiple typesets 2" do
46
+ result = FakeModel.new(:pie).apple.run()
47
+ result.should == :pie
48
+ end
39
49
  end
40
50
 
41
51
  describe "Test the multitype with FakeModel2 (inherits FakeModel)" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multitype
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Becker