intermine 1.01.01 → 1.02.00
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.
- data/lib/intermine/model.rb +11 -2
- data/lib/intermine/version.rb +3 -2
- data/test/live_test.rb +2 -0
- metadata +1 -1
data/lib/intermine/model.rb
CHANGED
|
@@ -32,6 +32,9 @@ module Metadata
|
|
|
32
32
|
BOOL_TYPES = ["Boolean", "boolean"]
|
|
33
33
|
NUMERIC_TYPES = FLOAT_TYPES | INT_TYPES
|
|
34
34
|
|
|
35
|
+
# Whether this is a lazy model
|
|
36
|
+
attr_accessor :is_lazy
|
|
37
|
+
|
|
35
38
|
# The name of the model
|
|
36
39
|
attr_reader :name
|
|
37
40
|
|
|
@@ -52,6 +55,7 @@ module Metadata
|
|
|
52
55
|
def initialize(model_data, service=nil)
|
|
53
56
|
result = JSON.parse(model_data)
|
|
54
57
|
@model = result["model"]
|
|
58
|
+
@is_lazy = false
|
|
55
59
|
@service = service
|
|
56
60
|
@name = @model["name"]
|
|
57
61
|
@classes = {}
|
|
@@ -544,7 +548,8 @@ module Metadata
|
|
|
544
548
|
if fd.is_a?(ReferenceDescriptor)
|
|
545
549
|
klass.class_eval do
|
|
546
550
|
define_method(fd.name) do
|
|
547
|
-
|
|
551
|
+
instance_var = instance_variable_get("@" + fd.name)
|
|
552
|
+
if fd.referencedType.model.is_lazy and instance_var.nil? and not instance_variable_get("@" + fd.name + "_ISNULL")
|
|
548
553
|
q = __cd__.select(:id, fd.name + ".*").where(:id => objectId).outerjoin(fd.name)
|
|
549
554
|
first_result = q.results.first
|
|
550
555
|
unless first_result.nil?
|
|
@@ -559,7 +564,11 @@ module Metadata
|
|
|
559
564
|
instance_variable_set("@" + fd.name, instance_var)
|
|
560
565
|
end
|
|
561
566
|
end
|
|
562
|
-
|
|
567
|
+
if instance_var.nil? and fd.is_a?(CollectionDescriptor)
|
|
568
|
+
return []
|
|
569
|
+
else
|
|
570
|
+
return instance_var
|
|
571
|
+
end
|
|
563
572
|
end
|
|
564
573
|
end
|
|
565
574
|
end
|
data/lib/intermine/version.rb
CHANGED
|
@@ -3,7 +3,8 @@ module Intermine
|
|
|
3
3
|
# Webservice Client Version number
|
|
4
4
|
#
|
|
5
5
|
# Changes:
|
|
6
|
-
# 1.
|
|
6
|
+
# 1.02.00 - Allow the lazy fetching to be optional
|
|
7
|
+
# 1.01.01 - Improved lazy reference fetching
|
|
7
8
|
# 1.01.00 - Test compatibility with 1.8.7, 1.9.2, 2.0.0-rc1
|
|
8
9
|
# Numerous bug fixes.
|
|
9
10
|
# 1.00.00 - Up to make use of new features of the InterMine 1.0 API
|
|
@@ -19,5 +20,5 @@ module Intermine
|
|
|
19
20
|
# 0.98.09 - Major changes to results - now with thorough-going Enumerable support
|
|
20
21
|
# 0.98.08 - Added column summary support
|
|
21
22
|
#
|
|
22
|
-
VERSION = "1.
|
|
23
|
+
VERSION = "1.02.00"
|
|
23
24
|
end
|
data/test/live_test.rb
CHANGED
|
@@ -59,6 +59,7 @@ class LiveDemoTest < Test::Unit::TestCase
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def testLazyReferenceFetching
|
|
62
|
+
@service.model.is_lazy = true
|
|
62
63
|
list = @service.list("My-Favourite-Employees")
|
|
63
64
|
|
|
64
65
|
deps = list.map {|emp| emp.department.name }
|
|
@@ -71,6 +72,7 @@ class LiveDemoTest < Test::Unit::TestCase
|
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
def testLazyCollectionFetching
|
|
75
|
+
@service.model.is_lazy = true
|
|
74
76
|
list = @service.list("My-Favourite-Employees")
|
|
75
77
|
emps = list.map {|manager| manager.department.employees.map{|employee| employee.age}.sort }
|
|
76
78
|
exp = [
|