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 +4 -4
- data/lib/multitype.rb +13 -5
- data/lib/multitype/version.rb +1 -1
- data/spec/support/fake_model.rb +14 -0
- data/spec/tests/multitype_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0be09639666335fce74afed223dbcd4b43e4a79
|
4
|
+
data.tar.gz: e94e9a6f4817d0640f03bdeb24f462ba599b700e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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,
|
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 |
|
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?(
|
128
|
-
typeset.__send__(
|
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
|
data/lib/multitype/version.rb
CHANGED
data/spec/support/fake_model.rb
CHANGED
@@ -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
|