caruby-core 1.4.9 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/History.md +48 -0
  2. data/lib/caruby/cli/command.rb +2 -1
  3. data/lib/caruby/csv/csv_mapper.rb +8 -8
  4. data/lib/caruby/database/persistable.rb +44 -65
  5. data/lib/caruby/database/persistence_service.rb +12 -9
  6. data/lib/caruby/database/persistifier.rb +14 -14
  7. data/lib/caruby/database/reader.rb +53 -51
  8. data/lib/caruby/database/search_template_builder.rb +9 -10
  9. data/lib/caruby/database/store_template_builder.rb +58 -58
  10. data/lib/caruby/database/writer.rb +96 -96
  11. data/lib/caruby/database.rb +19 -19
  12. data/lib/caruby/domain/attribute.rb +581 -0
  13. data/lib/caruby/domain/attributes.rb +615 -0
  14. data/lib/caruby/domain/dependency.rb +240 -0
  15. data/lib/caruby/domain/importer.rb +183 -0
  16. data/lib/caruby/domain/introspection.rb +176 -0
  17. data/lib/caruby/domain/inverse.rb +173 -0
  18. data/lib/caruby/domain/inversible.rb +1 -2
  19. data/lib/caruby/domain/java_attribute.rb +173 -0
  20. data/lib/caruby/domain/merge.rb +13 -10
  21. data/lib/caruby/domain/metadata.rb +141 -0
  22. data/lib/caruby/domain/mixin.rb +35 -0
  23. data/lib/caruby/domain/reference_visitor.rb +5 -3
  24. data/lib/caruby/domain.rb +340 -0
  25. data/lib/caruby/import/java.rb +29 -25
  26. data/lib/caruby/migration/migratable.rb +5 -5
  27. data/lib/caruby/migration/migrator.rb +19 -15
  28. data/lib/caruby/migration/resource_module.rb +1 -1
  29. data/lib/caruby/resource.rb +39 -30
  30. data/lib/caruby/util/collection.rb +94 -33
  31. data/lib/caruby/util/coordinate.rb +28 -2
  32. data/lib/caruby/util/log.rb +4 -4
  33. data/lib/caruby/util/module.rb +12 -28
  34. data/lib/caruby/util/partial_order.rb +9 -10
  35. data/lib/caruby/util/pretty_print.rb +46 -26
  36. data/lib/caruby/util/topological_sync_enumerator.rb +10 -4
  37. data/lib/caruby/util/transitive_closure.rb +2 -2
  38. data/lib/caruby/util/visitor.rb +1 -1
  39. data/lib/caruby/version.rb +1 -1
  40. data/test/lib/caruby/database/persistable_test.rb +1 -1
  41. data/test/lib/caruby/domain/domain_test.rb +14 -28
  42. data/test/lib/caruby/domain/inversible_test.rb +1 -1
  43. data/test/lib/caruby/import/java_test.rb +5 -0
  44. data/test/lib/caruby/migration/test_case.rb +0 -1
  45. data/test/lib/caruby/test_case.rb +9 -10
  46. data/test/lib/caruby/util/collection_test.rb +23 -5
  47. data/test/lib/caruby/util/module_test.rb +10 -14
  48. data/test/lib/caruby/util/partial_order_test.rb +16 -15
  49. data/test/lib/caruby/util/visitor_test.rb +1 -1
  50. data/test/lib/examples/galena/clinical_trials/migration/test_case.rb +1 -1
  51. metadata +16 -15
  52. data/History.txt +0 -44
  53. data/lib/caruby/domain/attribute_metadata.rb +0 -551
  54. data/lib/caruby/domain/java_attribute_metadata.rb +0 -183
  55. data/lib/caruby/domain/resource_attributes.rb +0 -565
  56. data/lib/caruby/domain/resource_dependency.rb +0 -217
  57. data/lib/caruby/domain/resource_introspection.rb +0 -160
  58. data/lib/caruby/domain/resource_inverse.rb +0 -151
  59. data/lib/caruby/domain/resource_metadata.rb +0 -155
  60. data/lib/caruby/domain/resource_module.rb +0 -370
  61. data/lib/caruby/yard/resource_metadata_handler.rb +0 -8
@@ -7,14 +7,15 @@ require 'caruby/util/collection'
7
7
  require 'caruby/util/inflector'
8
8
 
9
9
  class PrettyPrint
10
- # Fixes the standard prettyprint gem SingleLine to add an output accessor and an optional output argument to {#initialize}.
10
+ # The standard +prettyprint+ gem SingleLine is adjusted to add an output accessor and an optional output argument to {#initialize}.
11
11
  class SingleLine
12
+ # @return [String] the print target
12
13
  attr_reader :output
13
14
 
14
15
  alias :base__initialize :initialize
15
16
  private :base__initialize
16
17
 
17
- # Allow output to be optional, defaulting to ''
18
+ # Overrides the standard SingleLine initializer to supply an output parameter default.
18
19
  def initialize(output='', maxwidth=nil, newline=nil)
19
20
  base__initialize(output, maxwidth, newline)
20
21
  end
@@ -29,13 +30,14 @@ class PrintWrapper < Proc
29
30
  @args = args
30
31
  end
31
32
 
32
- # Sets the arguments to wrap with this wrapper's print block and returns self.
33
+ # @param args this wrapper's print block parameters
34
+ # @return [PrintWrapper] self
33
35
  def wrap(*args)
34
36
  @args = args
35
37
  self
36
38
  end
37
39
 
38
- # Calls this PrintWrapper's print procedure on its arguments.
40
+ # Calls this PrintWrapper's print procedure on the arguments set in the initializer.
39
41
  def to_s
40
42
  @args.empty? ? 'nil' : call(*@args)
41
43
  end
@@ -44,7 +46,7 @@ class PrintWrapper < Proc
44
46
  end
45
47
 
46
48
  class Object
47
- # Prints this object's class demodulized name and object id.
49
+ # @return [String] this object's class demodulized name and object id
48
50
  def print_class_and_id
49
51
  "#{self.class.qp}@#{object_id}"
50
52
  end
@@ -52,11 +54,14 @@ class Object
52
54
  # qp, an abbreviation for quick-print, calls {#print_class_and_id} in this base implementation.
53
55
  alias :qp :print_class_and_id
54
56
 
55
- # Formats this object as a String with PrettyPrint.
56
- # If the :single_line option is set, then the output is printed to a single line.
57
- def pp_s(options=nil)
57
+ # Formats this object with the standard {PrettyPrint}.
58
+ #
59
+ # @param [Hash, Symbol, nil] opts the print options
60
+ # @option opts [Boolean] :single_line print the output on a single line
61
+ # @return [String] the formatted print result
62
+ def pp_s(opts=nil)
58
63
  s = StringIO.new
59
- if Options.get(:single_line, options) then
64
+ if Options.get(:single_line, opts) then
60
65
  PP.singleline_pp(self, s)
61
66
  else
62
67
  PP.pp(self, s)
@@ -67,58 +72,70 @@ class Object
67
72
  end
68
73
 
69
74
  class Numeric
70
- # qp, an abbreviation for quick-print, is an alias for {#to_s} in this primitive class.
75
+ # Alias #{Object#qp} to {#to_s} in this primitive class.
71
76
  alias :qp :to_s
72
77
  end
73
78
 
74
79
  class String
75
- # qp, an abbreviation for quick-print, is an alias for {#to_s} in this primitive class.
80
+ # Alias #{Object#qp} to {#to_s} in this primitive class.
76
81
  alias :qp :to_s
77
82
  end
78
83
 
79
84
  class TrueClass
80
- # qp, an abbreviation for quick-print, is an alias for {#to_s} in this primitive class.
85
+ # Alias #{Object#qp} to {#to_s} in this primitive class.
81
86
  alias :qp :to_s
82
87
  end
83
88
 
84
89
  class FalseClass
85
- # qp, an abbreviation for quick-print, is an alias for {#to_s} in this primitive class.
90
+ # Alias #{Object#qp} to {#to_s} in this primitive class.
86
91
  alias :qp :to_s
87
92
  end
88
93
 
89
94
  class NilClass
90
- # qp, an abbreviation for quick-print, is an alias for {#inspect} in this NilClass.
95
+ # Alias #{Object#qp} to {#to_s} in this primitive class.
91
96
  alias :qp :inspect
92
97
  end
93
98
 
94
99
  class Symbol
95
- # qp, an abbreviation for quick-print, is an alias for {#inspect} in this Symbol class.
100
+ # Alias #{Object#qp} to {#to_s} in this primitive class.
96
101
  alias :qp :inspect
97
102
  end
98
103
 
99
104
  class Module
100
- # qp, an abbreviation for quick-print, prints this module's name unqualified by a parent module prefix.
105
+ # @return [String ] the demodulized name
101
106
  def qp
102
107
  name[/\w+$/]
103
108
  end
104
109
  end
105
110
 
106
111
  module Enumerable
107
- # qp, short for quick-print, prints a collection Enumerable with a filter that calls qp on each item.
108
- # Non-collection Enumerables delegate to the superclass method.
109
- def qp
110
- wrap { |item| item.qp }.pp_s
111
- end
112
-
113
- # If the transformer block is given to this method, then the transformer block to each
112
+ # Prints this Enumerable with a filter that calls qp on each item.
113
+ # Non-collection Enumerable classes override this method to delegate to {Object#qp}.
114
+ #
115
+ # Unlike {Object#qp}, this implementation accepts the {Object#pp_s} options.
116
+ # The options are used to format this Enumerable, but are not propagated to the
117
+ # enumerated items.
118
+ #
119
+ # @param (see Object#pp_s)
120
+ # @return [String] the formatted result
121
+ def qp(opts=nil)
122
+ wrap { |item| item.qp }.pp_s(opts)
123
+ end
124
+
125
+ # If a transformer block is given to this method, then the block is applied to each
114
126
  # enumerated item before pretty-printing the result.
115
- def pp_s(options=nil, &transformer)
127
+ #
128
+ # @param (see Object#pp_s)
129
+ # @yield [item] transforms the item to print
130
+ # @yieldparam item the item to print
131
+ # @return (see Oblect#pp_s)
132
+ def pp_s(opts=nil)
116
133
  # delegate to Object if no block
117
- return super(options) unless block_given?
134
+ return super unless block_given?
118
135
  # make a print wrapper
119
136
  wrapper = PrintWrapper.new { |item| yield item }
120
137
  # print using the wrapper on each item
121
- wrap { |item| wrapper.wrap(item) }.pp_s(options)
138
+ wrap { |item| wrapper.wrap(item) }.pp_s(opts)
122
139
  end
123
140
 
124
141
  # Pretty-prints the content within brackets, as is done by the Array pretty printer.
@@ -138,6 +155,8 @@ end
138
155
 
139
156
  module Hashable
140
157
  # qp, short for quick-print, prints this Hashable with a filter that calls qp on each key and value.
158
+ #
159
+ # @return [String] the quick-print result
141
160
  def qp
142
161
  qph = {}
143
162
  each { |k, v| qph[k.qp] = v.qp }
@@ -161,6 +180,7 @@ class String
161
180
  end
162
181
 
163
182
  class DateTime
183
+ # @return [String] the formatted +strftime+
164
184
  def pretty_print(q)
165
185
  q.text(strftime)
166
186
  end
@@ -3,16 +3,22 @@ require 'caruby/util/collection'
3
3
  class TopologicalSyncEnumerator
4
4
  include Enumerable
5
5
 
6
- def initialize(targets, sources, symbol, &matcher)
6
+ # @param targets the objects to synch to
7
+ # @param sources the objects to synch from
8
+ # @param [Symbol] method the topological order reference method
9
+ # @yield (see #each)
10
+ def initialize(targets, sources, method, &matcher)
7
11
  @tgts = targets
8
12
  @srcs = sources
9
- @mthd = symbol
13
+ @mthd = method
10
14
  @matcher = matcher || lambda { |tgt, srcs| srcs.first }
11
15
  end
12
16
 
13
17
  # Calls the given block on each matching target and source.
14
- # Returns the matching target => source hash.
15
- def each # :yields: target, source
18
+ #
19
+ # @yield [target, source] the objects to synchronize
20
+ # @return [Hash] the matching target => source hash
21
+ def each
16
22
  # the parent hashes for targets and sources
17
23
  pt = @tgts.to_compact_hash { |tgt| tgt.send(@mthd) }
18
24
  ps = @srcs.to_compact_hash { |src| src.send(@mthd) }
@@ -34,9 +34,9 @@ module Enumerable
34
34
  # Returns the transitive closure over all items in this Enumerable.
35
35
  #
36
36
  # @see Object#transitive_closure
37
- def transitive_closure(method=nil, &navigator)
37
+ def transitive_closure(method=nil)
38
38
  # delegate to Object if there is a method argument
39
- return super(method, &navigator) if method
39
+ return super(method) if method
40
40
  # this Enumerable's children are this Enumerable's contents
41
41
  closure = super() { |node| node.equal?(self) ? self : yield(node) }
42
42
  # remove this collection from the closure
@@ -139,7 +139,7 @@ module CaRuby
139
139
 
140
140
  # @return [Enumerable] iterator over each visited node
141
141
  def to_enum(node)
142
- # JRuby alert - could use Generator instead, but that results in dire behavior on any error
142
+ # JRuby could use Generator instead, but that results in dire behavior on any error
143
143
  # by crashing with an elided Java lineage trace.
144
144
  VisitorEnumerator.new(self, node)
145
145
  end
@@ -1,3 +1,3 @@
1
1
  module CaRuby
2
- VERSION = "1.4.9"
2
+ VERSION = "1.5.1"
3
3
  end
@@ -85,7 +85,7 @@ class PersistableTest < Test::Unit::TestCase
85
85
 
86
86
  def duplicate_with_id(obj)
87
87
  return obj.map { |item| duplicate_with_id(item) } if Enumerable === obj
88
- copy = obj.copy(obj.class.nondomain_attributes)
88
+ copy = obj.copy
89
89
  copy.identifier ||= @@counter += 1
90
90
  copy
91
91
  end
@@ -15,38 +15,24 @@ class DomainTest < Test::Unit::TestCase
15
15
  super
16
16
  @crd = ClinicalTrials::User.new(:login => 'study.coordinator@test.org')
17
17
  address = ClinicalTrials::Address.new(:street => '555 Elm St', :city => 'Burlington', :state => 'VT', :zip_code => '55555')
18
- @pnt = ClinicalTrials::Participant.new(:name => 'Test Participant', :address => address)
19
- @study = ClinicalTrials::Study.new(:name => 'Test Study', :coordinator => @crd, :enrollment => [@pnt])
18
+ @sbj = ClinicalTrials::Subject.new(:name => 'Test Subject', :address => address)
19
+ @study = ClinicalTrials::Study.new(:name => 'Test Study', :coordinator => @crd, :enrollment => [@sbj])
20
20
  @evt = ClinicalTrials::StudyEvent.new(:study => @study, :calendar_event_point => 1.0)
21
21
  end
22
22
 
23
23
  def test_alias
24
24
  assert(ClinicalTrials::Study.method_defined?(:events), "Study alias not recognized: events")
25
- assert_equal(@pnt.address.zip_code, @pnt.address.postal_code, 'zip_code not aliased to postal_code')
26
- assert_equal(:zip_code, @pnt.address.class.standard_attribute(:postal_code), 'postal_code does not map to a standard attribute symbol')
25
+ assert_equal(@sbj.address.zip_code, @sbj.address.postal_code, 'zip_code not aliased to postal_code')
26
+ assert_equal(:zip_code, @sbj.address.class.standard_attribute(:postal_code), 'postal_code does not map to a standard attribute symbol')
27
27
  end
28
28
 
29
29
  def test_redefine
30
- @pnt.address.zip_code = 55555
31
- assert_equal('55555', @pnt.address.zip_code, "Address zip_code not redefined to support a numeric value")
30
+ @sbj.address.zip_code = 55555
31
+ assert_equal('55555', @sbj.address.zip_code, "Address zip_code not redefined to support a numeric value")
32
32
  end
33
33
 
34
34
  def test_merge_attributes
35
- assert_same(@study.enrollment.first, @pnt, "Merge incorrect")
36
- end
37
-
38
- def test_merge_unambiguous_dependent_collection_attribute
39
- @study.enrollment.clear
40
- assert_same(@study.enrollment, @study.merge_attribute(:enrollment, [@pnt]), "Merge collection attribute result incorrect")
41
- assert_not_nil(@study.enrollment.first, "Merge collection attribute didn't add source item")
42
- assert_same(@study.enrollment.first, @pnt, "Merge collection attribute incorrect")
43
- end
44
-
45
- def test_merge_ambiguous_dependent_collection_attribute
46
- @study.enrollment.clear
47
- assert_same(@study.enrollment, @study.merge_attribute(:enrollment, [@pnt]), "Merge collection attribute result incorrect")
48
- assert_not_nil(@study.enrollment.first, "Merge collection attribute didn't add source item")
49
- assert_same(@study.enrollment.first, @pnt, "Merge collection attribute incorrect")
35
+ assert_same(@study.enrollment.first, @sbj, "Merge incorrect")
50
36
  end
51
37
 
52
38
  def test_owner_inverse_setter
@@ -72,9 +58,9 @@ class DomainTest < Test::Unit::TestCase
72
58
 
73
59
  # Tests whether add_defaults method propagates to dependents.
74
60
  def test_participant_defaults
75
- assert_nil(@pnt.address.country, 'Participant address country is already set')
76
- @pnt.add_defaults
77
- assert_equal('US', @pnt.address.country, 'Participant address country is not set to default')
61
+ assert_nil(@sbj.address.country, 'Subject address country is already set')
62
+ @sbj.add_defaults
63
+ assert_equal('US', @sbj.address.country, 'Subject address country is not set to default')
78
64
  end
79
65
 
80
66
  def test_dependents
@@ -91,9 +77,9 @@ class DomainTest < Test::Unit::TestCase
91
77
  assert_equal([@study, 1.0], @evt.key, "Event key incorrect")
92
78
  end
93
79
 
94
- # def test_address_key
95
- # assert_nil(@pnt.address.key, "Address key incorrect")
96
- # end
80
+ def test_address_key
81
+ assert_nil(@sbj.address.key, "Address key incorrect")
82
+ end
97
83
 
98
84
  def test_set_collection_attribute
99
85
  consent = ClinicalTrials::Consent.new(:statement => 'Test Statement 1')
@@ -115,7 +101,7 @@ class DomainTest < Test::Unit::TestCase
115
101
  def test_visit_path
116
102
  visited = []
117
103
  @study.visit_path([:enrollment, :address]) { |ref| visited << ref }
118
- assert_equal([@study, @pnt, @pnt.address], visited, "Path visitor incorrect")
104
+ assert_equal([@study, @sbj, @sbj.address], visited, "Path visitor incorrect")
119
105
  end
120
106
 
121
107
  def test_visit_dependents
@@ -5,7 +5,7 @@ require "test/unit"
5
5
 
6
6
  class InversibleTest < Test::Unit::TestCase
7
7
  module Domain
8
- extend CaRuby::ResourceModule
8
+ extend CaRuby::Domain
9
9
  end
10
10
 
11
11
  module Resource
@@ -20,6 +20,11 @@ class JavaTest < Test::Unit::TestCase
20
20
  end
21
21
  end
22
22
 
23
+ def test_zero_date
24
+ jdt = Java::JavaUtil::Date.new(0)
25
+ verify_java_to_ruby_date_conversion(jdt)
26
+ end
27
+
23
28
  def flip_DST(cal)
24
29
  isdt = cal.timeZone.inDaylightTime(cal.time)
25
30
  11.times do
@@ -44,7 +44,6 @@ module CaRuby
44
44
  # @return [CaTissue::Migrator]
45
45
  # @yield [opts] the optional Migrator factory
46
46
  def create_migrator(fixture, opts={}, &factory)
47
- opts[:quiet] = true
48
47
  opts[:input] ||= File.join(@fixtures, fixture.to_s + '.csv')
49
48
  block_given? ? yield(opts) : CaRuby::Migrator.new(opts)
50
49
  end
@@ -113,8 +113,7 @@ module CaRuby
113
113
 
114
114
  def verify_dependency(dependent)
115
115
  return if dependent.class.owner_attribute.nil?
116
- # kludge for annotation proxy nonsense (cf. Annotation#owner)
117
- ownr = Annotation === dependent ? (dependent.hook or dependent.owner) : dependent.owner
116
+ ownr = dependent.owner
118
117
  assert_not_nil(ownr, "Owner missing for dependent: #{dependent}")
119
118
  attribute = ownr.class.dependent_attribute(dependent.class)
120
119
  assert_not_nil(attribute, "Dependent attribute missing for #{dependent} owner #{ownr}")
@@ -129,7 +128,7 @@ module CaRuby
129
128
  # Verifies that the given dependent has an identifier and that the given owner dependent attribute value
130
129
  # contains the dependent.
131
130
  #
132
- # JRuby alert - Set include? incorrectly returns false in the OHSU PSR samples_test test_save_grade
131
+ # JRuby Set include? incorrectly returns false in the OHSU PSR samples_test test_save_grade
133
132
  # call to this method. Work around by using Set detect rather than include?.
134
133
  def verify_saved_dependent_collection_member(dependent, owner, attribute)
135
134
  deps = owner.send(attribute)
@@ -168,12 +167,12 @@ module CaRuby
168
167
  # Verifies that the given expected domain object has the same content as actual,
169
168
  # and that the dependents match.
170
169
  #
171
- # caTissue alert - caTissue mutilates an unspecified specimen type available quantity, e.g.
172
- # changing a Specimen with specimen type 'Not Specified' from available quantity 1, initial
173
- # quantity 1 to available quantity 0, initial quantity 3 results in available quantity 2
174
- # in database. The update is necessary when creating the Specimen with available quantity 0,
175
- # initial quantity 3 to work around a different caTissue bug. Thus, the bug work-around
176
- # is broken by a different caTissue bug.
170
+ # @quirk caTissue caTissue mutilates an unspecified specimen type available quantity, e.g.
171
+ # changing a Specimen with specimen type 'Not Specified' from available quantity 1, initial
172
+ # quantity 1 to available quantity 0, initial quantity 3 results in available quantity 2
173
+ # in database. The update is necessary when creating the Specimen with available quantity 0,
174
+ # initial quantity 3 to work around a different caTissue bug. Thus, the bug work-around
175
+ # is broken by a different caTissue bug.
177
176
  #
178
177
  # @param [Resource] expected the saved value
179
178
  # @param [Resource] actual the fetched value
@@ -201,7 +200,7 @@ module CaRuby
201
200
  verify_dependents_match(expected, actual)
202
201
  end
203
202
 
204
- # @param [AttributeMetadata] attr_md the saved attribute to check
203
+ # @param [Attribute] attr_md the saved attribute to check
205
204
  # @return whether the attribute is fetched, creatable and not volatile
206
205
  def verify_saved_attribute?(attr_md)
207
206
  attr_md.fetched? and attr_md.creatable? and not attr_md.volatile?
@@ -127,6 +127,12 @@ class CollectionTest < Test::Unit::TestCase
127
127
  b << 5
128
128
  assert_equal([1, 2, 3, 3, 4, 5], ab.to_a, "Addition does not reflect change to second enumerable")
129
129
  end
130
+
131
+ def test_partial_sort
132
+ sorted = [Array, Object, Numeric, Enumerable, Set].partial_sort
133
+ assert(sorted.index(Array) < sorted.index(Enumerable), "Partial sort order incorrect")
134
+ assert(sorted.index(Set) < sorted.index(Enumerable), "Partial sort order incorrect")
135
+ end
130
136
 
131
137
  def test_hash_union
132
138
  a = {:a => 1, :b => 2}
@@ -173,11 +179,11 @@ class CollectionTest < Test::Unit::TestCase
173
179
  end
174
180
 
175
181
  def test_hash_enum_keys
176
- assert_equal([1, 2], { 1 => :a, 2 => :b }.enum_keys.sort)
177
- end
178
-
179
- def test_hash_partition
180
- assert_equal([{:a => 1}, { :b => 2}], { :a => 1, :b => 2 }.partition { |key, value| value < 2 }, "Hash partition incorrect")
182
+ hash = { 1 => :a, 2 => :b }
183
+ ek = hash.enum_keys
184
+ assert_equal([1, 2], ek.sort, "Hash key enumerator incorrect")
185
+ hash[3] = :c
186
+ assert_equal([1, 2, 3], ek.sort, "Hash key enumerator does not reflect hash change")
181
187
  end
182
188
 
183
189
  def test_hash_enum_keys_with_value
@@ -188,6 +194,18 @@ class CollectionTest < Test::Unit::TestCase
188
194
  assert_equal([:b, :c], {:a => 1, :b => 2, :c => 3}.enum_keys_with_value { |value| value > 1 }.to_a, "Hash filtered value block keys incorrect")
189
195
  end
190
196
 
197
+ def test_hash_enum_values
198
+ hash = { :a => 1, :b => 2 }
199
+ ev = hash.enum_values
200
+ assert_equal([1, 2], ev.sort, "Hash value enumerator incorrect")
201
+ hash[:c] = 3
202
+ assert_equal([1, 2, 3], ev.sort, "Hash value enumerator does not reflect hash change")
203
+ end
204
+
205
+ def test_hash_partition
206
+ assert_equal([{:a => 1}, { :b => 2}], { :a => 1, :b => 2 }.partition { |key, value| value < 2 }, "Hash partition incorrect")
207
+ end
208
+
191
209
  def test_hash_flatten
192
210
  assert_equal([:a, :b, :c, :d, :e, :f, :g], {:a => {:b => :c}, :d => :e, :f => [:g]}.flatten, "Hash flatten incorrect")
193
211
  end
@@ -5,25 +5,21 @@ require 'caruby/util/module'
5
5
 
6
6
  module Outer
7
7
  module Middle
8
- module InnerModule; end
9
- class InnerClass; end
8
+ class C; end
10
9
  end
11
10
  end
12
11
 
13
12
  class ModuleTest < Test::Unit::TestCase
14
- def test_top_level_module_with_name
15
- assert_equal(Array, Module.module_with_name(nil, 'Array'), "Top level module incorrect")
16
- end
17
-
18
- def test_module_with_unqualified_name
13
+ def test_module_with_name
19
14
  assert_equal(Outer::Middle, Outer.module_with_name('Middle'), "Unqualified module incorrect")
15
+ assert_nil(Outer.module_with_name('Zed'), "Missing module incorrectly resolves to non-nil value")
16
+ assert_equal(Outer::Middle::C, Outer.module_with_name('Middle::C'), "Qualified module incorrect")
17
+ assert_equal(Outer, Kernel.module_with_name('Outer'), "Top-level module incorrect")
20
18
  end
21
-
22
- def test_module_with_qualified_name
23
- assert_equal(Outer::Middle::InnerModule, Outer.module_with_name('Middle::InnerModule'), "Qualified module incorrect")
24
- end
25
-
26
- def test_class_with_name
27
- assert_equal(Outer::Middle::InnerClass, Outer.module_with_name('Middle::InnerClass'), "Inner class incorrect")
19
+
20
+ def test_parent_module
21
+ assert_equal(Outer, Outer::Middle.parent_module, "Middle parent module incorrect")
22
+ assert_equal(Outer::Middle, Outer::Middle::C.parent_module, "Inner parent module incorrect")
23
+ assert_equal(Kernel, Outer.parent_module, "Outer parent module incorrect")
28
24
  end
29
25
  end
@@ -6,36 +6,37 @@ require 'caruby/util/partial_order'
6
6
  class Queued
7
7
  include PartialOrder
8
8
 
9
- attr_reader :value, :queue
9
+ attr_reader :queue
10
10
 
11
- def initialize(value, on)
12
- @value = value
11
+ def initialize(on)
13
12
  @queue = on.push(self)
14
13
  end
15
14
 
16
15
  def <=>(other)
17
- value <=> other.value if queue.equal?(other.queue)
16
+ queue.index(self) <=> other.queue.index(other) if queue.equal?(other.queue)
18
17
  end
19
18
  end
20
19
 
21
20
  class PartialOrderTest < Test::Unit::TestCase
22
21
  def test_same_queue
23
- @a = Queued.new(1, [])
24
- assert_equal(@a, @a.dup, "Same value, queue not equal")
22
+ q = []
23
+ a = Queued.new(q)
24
+ assert_equal(a, a, "Same value, queue not equal")
25
25
  end
26
26
 
27
27
  def test_different_eql_queue
28
- @a = Queued.new(1, [])
29
- @b = Queued.new(1, [])
30
- assert_nil(@a <=> @b, "Same value, different queue <=> not nil")
31
- assert_not_equal(@a, @b, "Same value, different queue is equal")
28
+ a = Queued.new([])
29
+ @b = Queued.new([])
30
+ assert_nil(a <=> @b, "Same value, different queue <=> not nil")
31
+ assert_not_equal(a, @b, "Same value, different queue is equal")
32
32
  end
33
33
 
34
34
  def test_less_than
35
- @a = Queued.new(1, [])
36
- @b = Queued.new(2, @a.queue)
37
- @c = Queued.new(2, [])
38
- assert(@a < @b, "Comparison incorrect")
39
- assert_nil(@a < @c, "Comparison incorrect")
35
+ q = []
36
+ a = Queued.new(q)
37
+ b = Queued.new(q)
38
+ c = Queued.new([])
39
+ assert(a < b, "Comparison incorrect")
40
+ assert_nil(a < c, "Comparison incorrect")
40
41
  end
41
42
  end
@@ -1,6 +1,6 @@
1
1
  $:.unshift 'lib'
2
2
 
3
- # JRuby alert - SyncEnumerator moved from generator to REXML in JRuby 1.5
3
+ # JRuby SyncEnumerator moved from generator to REXML in JRuby 1.5
4
4
  require 'rexml/document'
5
5
  require "test/unit"
6
6
  require 'caruby/util/collection'
@@ -13,7 +13,7 @@ module Galena
13
13
  FIXTURES = 'examples/galena/data'
14
14
 
15
15
  # The migration input data directory.
16
- SHIMS = 'examples/galena/lib/galena/migration'
16
+ SHIMS = 'examples/galena/lib/galena/clinical_trials/migration'
17
17
 
18
18
  # The migration configuration directory.
19
19
  CONFIGS = 'examples/galena/conf/migration'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caruby-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 4
9
- - 9
10
- version: 1.4.9
8
+ - 5
9
+ - 1
10
+ version: 1.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - OHSU
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-09 00:00:00 -07:00
18
+ date: 2011-07-05 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -104,20 +104,22 @@ files:
104
104
  - lib/caruby/database/store_template_builder.rb
105
105
  - lib/caruby/database/writer.rb
106
106
  - lib/caruby/database.rb
107
- - lib/caruby/domain/attribute_metadata.rb
107
+ - lib/caruby/domain/attribute.rb
108
+ - lib/caruby/domain/attributes.rb
109
+ - lib/caruby/domain/dependency.rb
108
110
  - lib/caruby/domain/id_alias.rb
111
+ - lib/caruby/domain/importer.rb
112
+ - lib/caruby/domain/introspection.rb
113
+ - lib/caruby/domain/inverse.rb
109
114
  - lib/caruby/domain/inversible.rb
110
- - lib/caruby/domain/java_attribute_metadata.rb
115
+ - lib/caruby/domain/java_attribute.rb
111
116
  - lib/caruby/domain/merge.rb
117
+ - lib/caruby/domain/metadata.rb
118
+ - lib/caruby/domain/mixin.rb
112
119
  - lib/caruby/domain/properties.rb
113
120
  - lib/caruby/domain/reference_visitor.rb
114
- - lib/caruby/domain/resource_attributes.rb
115
- - lib/caruby/domain/resource_dependency.rb
116
- - lib/caruby/domain/resource_introspection.rb
117
- - lib/caruby/domain/resource_inverse.rb
118
- - lib/caruby/domain/resource_metadata.rb
119
- - lib/caruby/domain/resource_module.rb
120
121
  - lib/caruby/domain/uniquify.rb
122
+ - lib/caruby/domain.rb
121
123
  - lib/caruby/import/java.rb
122
124
  - lib/caruby/migration/migratable.rb
123
125
  - lib/caruby/migration/migrator.rb
@@ -154,7 +156,6 @@ files:
154
156
  - lib/caruby/util/visitor.rb
155
157
  - lib/caruby/util/weak_hash.rb
156
158
  - lib/caruby/version.rb
157
- - lib/caruby/yard/resource_metadata_handler.rb
158
159
  - lib/caruby.rb
159
160
  - test/lib/caruby/csv/csv_mapper_test.rb
160
161
  - test/lib/caruby/csv/csvio_test.rb
@@ -192,7 +193,7 @@ files:
192
193
  - test/lib/caruby/util/weak_hash_test.rb
193
194
  - test/lib/examples/galena/clinical_trials/migration/participant_test.rb
194
195
  - test/lib/examples/galena/clinical_trials/migration/test_case.rb
195
- - History.txt
196
+ - History.md
196
197
  - LEGAL
197
198
  - LICENSE
198
199
  - README.md