jinx 2.1.3 → 2.1.4
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/Gemfile.lock +27 -0
- data/History.md +4 -0
- data/lib/jinx/helpers/class.rb +16 -12
- data/lib/jinx/helpers/collection.rb +277 -29
- data/lib/jinx/helpers/collections.rb +35 -2
- data/lib/jinx/helpers/conditional_enumerator.rb +2 -2
- data/lib/jinx/helpers/filter.rb +8 -2
- data/lib/jinx/helpers/flattener.rb +2 -2
- data/lib/jinx/helpers/hash.rb +3 -2
- data/lib/jinx/helpers/{hashable.rb → hasher.rb} +125 -77
- data/lib/jinx/helpers/module.rb +1 -1
- data/lib/jinx/helpers/multi_enumerator.rb +25 -9
- data/lib/jinx/helpers/options.rb +4 -3
- data/lib/jinx/helpers/partial_order.rb +16 -8
- data/lib/jinx/helpers/pretty_print.rb +14 -4
- data/lib/jinx/helpers/transformer.rb +3 -1
- data/lib/jinx/helpers/transitive_closure.rb +3 -3
- data/lib/jinx/helpers/visitor.rb +33 -42
- data/lib/jinx/import/java.rb +40 -27
- data/lib/jinx/importer.rb +86 -33
- data/lib/jinx/metadata/attribute_enumerator.rb +5 -11
- data/lib/jinx/metadata/dependency.rb +65 -30
- data/lib/jinx/metadata/id_alias.rb +1 -0
- data/lib/jinx/metadata/introspector.rb +21 -9
- data/lib/jinx/metadata/inverse.rb +14 -11
- data/lib/jinx/metadata/java_property.rb +15 -26
- data/lib/jinx/metadata/propertied.rb +80 -19
- data/lib/jinx/metadata/property.rb +13 -8
- data/lib/jinx/metadata/property_characteristics.rb +2 -2
- data/lib/jinx/resource.rb +62 -32
- data/lib/jinx/resource/inversible.rb +4 -0
- data/lib/jinx/resource/match_visitor.rb +0 -1
- data/lib/jinx/resource/mergeable.rb +16 -6
- data/lib/jinx/resource/reference_enumerator.rb +1 -2
- data/lib/jinx/version.rb +1 -1
- data/test/lib/jinx/helpers/collections_test.rb +29 -14
- data/test/lib/jinx/helpers/visitor_test.rb +7 -20
- data/test/lib/jinx/import/mixed_case_test.rb +17 -3
- metadata +4 -4
- data/lib/jinx/helpers/enumerable.rb +0 -245
@@ -5,12 +5,26 @@ require File.dirname(__FILE__) + '/../../../helper'
|
|
5
5
|
require 'java'
|
6
6
|
require "test/unit"
|
7
7
|
|
8
|
-
# Verifies whether JRuby supports a mixed-case package.
|
9
|
-
# The work-around is to import the class as a string.
|
10
8
|
class MixedCaseTest < Test::Unit::TestCase
|
9
|
+
# Verifies whether JRuby supports a mixed-case package.
|
10
|
+
# This test case exercises the following JRuby bug:
|
11
|
+
#
|
12
|
+
# @ quirk JRuby JRuby cannot resolve a class with a mixed-case package name. Although
|
13
|
+
# discouraged, a Java mixed-case package name is legal. The work-around is to
|
14
|
+
# import the class name instead.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# # Assuming mixed.Case.Example is in the Java class path, then:
|
18
|
+
# mixed.Case.Example #=> NameError
|
19
|
+
# java_import 'mixed.Case.Example' #=> Class
|
20
|
+
#
|
21
|
+
# @param [String] jname the fully-qualified Java class or interface name
|
22
|
+
# @return [String] the JRuby class or module name
|
23
|
+
# @example
|
24
|
+
# Java.to_ruby_class_name('com.test.Sample') #=> Java::ComTest::Sample
|
11
25
|
def test_import
|
12
26
|
assert_raises(NameError, "Mixed-case package resolved") { Java::mixed.Case.Example }
|
13
27
|
assert_raises(NameError, "Mixed-case JRuby module resolved") { Java::MixedCase::Example }
|
14
|
-
assert_nothing_raised("Mixed-case import as a string not resolved") {java_import
|
28
|
+
assert_nothing_raised("Mixed-case import as a string not resolved") { java_import 'mixed.Case.Example' }
|
15
29
|
end
|
16
30
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: jinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.1.
|
5
|
+
version: 2.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- OHSU
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-10-31 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- .rspec
|
59
59
|
- .yardopts
|
60
60
|
- Gemfile
|
61
|
+
- Gemfile.lock
|
61
62
|
- History.md
|
62
63
|
- LEGAL
|
63
64
|
- LICENSE
|
@@ -122,13 +123,12 @@ files:
|
|
122
123
|
- lib/jinx/helpers/collections.rb
|
123
124
|
- lib/jinx/helpers/collector.rb
|
124
125
|
- lib/jinx/helpers/conditional_enumerator.rb
|
125
|
-
- lib/jinx/helpers/enumerable.rb
|
126
126
|
- lib/jinx/helpers/enumerate.rb
|
127
127
|
- lib/jinx/helpers/file_separator.rb
|
128
128
|
- lib/jinx/helpers/filter.rb
|
129
129
|
- lib/jinx/helpers/flattener.rb
|
130
130
|
- lib/jinx/helpers/hash.rb
|
131
|
-
- lib/jinx/helpers/
|
131
|
+
- lib/jinx/helpers/hasher.rb
|
132
132
|
- lib/jinx/helpers/inflector.rb
|
133
133
|
- lib/jinx/helpers/lazy_hash.rb
|
134
134
|
- lib/jinx/helpers/log.rb
|
@@ -1,245 +0,0 @@
|
|
1
|
-
require 'jinx/helpers/transformer'
|
2
|
-
require 'jinx/helpers/multi_enumerator'
|
3
|
-
|
4
|
-
module Enumerable
|
5
|
-
# Returns a new Hash generated from this Enumerable and an optional value generator block.
|
6
|
-
# This Enumerable contains the Hash keys. If the value generator block is given to this
|
7
|
-
# method then the block is called with each enumerated element as an argument to
|
8
|
-
# generate the associated hash value. If no block is given, then the values are nil.
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# [1, 2, 3].hashify { |item| item.modulo(2) } #=> { 1 => 1, 2 => 0, 3 => 1 }
|
12
|
-
# [:a].hashify #=> { :a => nil }
|
13
|
-
# @return [Hash]
|
14
|
-
def hashify
|
15
|
-
hash = {}
|
16
|
-
each { |item| hash[item] = yield item if block_given? }
|
17
|
-
hash
|
18
|
-
end
|
19
|
-
|
20
|
-
# Returns a new Hash generated from this Enumerable and a required value generator block.
|
21
|
-
# This Enumerable contains the Hash keys. The block is called with each enumerated
|
22
|
-
# element as an argument to generate the associated hash value.
|
23
|
-
# Only non-nil, non-empty values are included in the hash.
|
24
|
-
#
|
25
|
-
# @example
|
26
|
-
# [1, 2, 3].to_compact_hash { |item| item.modulo(2) } #=> { 1 => 1, 2 => 0, 3 => 1 }
|
27
|
-
# [1, 2, 3].to_compact_hash { |n| n.modulo(2) unless item > 2 } #=> {1 => 1, 2 => 0}
|
28
|
-
# [1, 2, 3].to_compact_hash { |n| n > 2 } #=> {1 => false, 2 => false, 3 => true}
|
29
|
-
# [1, 2, 3].to_compact_hash { |n| Array.new(n - 1, n) } #=> {2 => [2], 3 => [2, 3]}
|
30
|
-
# @return [Hash]
|
31
|
-
# @raise [ArgumentError] if the generator block is not given
|
32
|
-
# @see #hashify
|
33
|
-
def to_compact_hash
|
34
|
-
raise ArgumentError.new("Compact hash builder is missing the value generator block") unless block_given?
|
35
|
-
to_compact_hash_with_index { |item, index| yield item }
|
36
|
-
end
|
37
|
-
|
38
|
-
# Returns a new Hash generated from this Enumerable with a block whose arguments include the enumerated item
|
39
|
-
# and its index. Every value which is nil or empty is excluded.
|
40
|
-
#
|
41
|
-
# @example
|
42
|
-
# [1, 2, 3].to_compact_hash_with_index { |item, index| item + index } #=> { 1 => 1, 2 => 3, 3 => 5 }
|
43
|
-
# @yield [item, index] the hash value
|
44
|
-
# @yieldparam item the enumerated value
|
45
|
-
# @yieldparam index the enumeration index
|
46
|
-
# @return [Hash] this {Enumerable} converted to a hash by the given block
|
47
|
-
def to_compact_hash_with_index
|
48
|
-
hash = {}
|
49
|
-
self.each_with_index do |item, index|
|
50
|
-
next if item.nil?
|
51
|
-
value = yield(item, index)
|
52
|
-
next if value.nil_or_empty?
|
53
|
-
hash[item] = value
|
54
|
-
end
|
55
|
-
hash
|
56
|
-
end
|
57
|
-
|
58
|
-
# This method is functionally equivalent to +to_a.empty+ but is more concise and efficient.
|
59
|
-
#
|
60
|
-
# @return [Boolean] whether this Enumerable iterates over at least one item
|
61
|
-
def empty?
|
62
|
-
not any? { true }
|
63
|
-
end
|
64
|
-
|
65
|
-
# This method is functionally equivalent to +to_a.first+ but is more concise and efficient.
|
66
|
-
#
|
67
|
-
# @return the first enumerated item in this Enumerable, or nil if this Enumerable is empty
|
68
|
-
def first
|
69
|
-
detect { true }
|
70
|
-
end
|
71
|
-
|
72
|
-
# This method is functionally equivalent to +to_a.last+ but is more concise and efficient.
|
73
|
-
#
|
74
|
-
# @return the last enumerated item in this Enumerable, or nil if this Enumerable is empty
|
75
|
-
def last
|
76
|
-
detect { true }
|
77
|
-
end
|
78
|
-
|
79
|
-
# This method is functionally equivalent to +to_a.size+ but is more concise and efficient
|
80
|
-
# for an Enumerable which does not implement the {#size} method.
|
81
|
-
#
|
82
|
-
# @return [Integer] the count of items enumerated in this Enumerable
|
83
|
-
def size
|
84
|
-
inject(0) { |size, item| size + 1 }
|
85
|
-
end
|
86
|
-
|
87
|
-
alias :length :size
|
88
|
-
|
89
|
-
# @return [String] the content of this Enumerable as a series using {Array#to_series}
|
90
|
-
def to_series(conjunction=nil)
|
91
|
-
to_a.to_series
|
92
|
-
end
|
93
|
-
|
94
|
-
# Returns the first non-nil, non-false enumerated value resulting from a call to the block given to this method,
|
95
|
-
# or nil if no value detected.
|
96
|
-
#
|
97
|
-
# @example
|
98
|
-
# [1, 2].detect_value { |item| item / 2 if item % 2 == 0 } #=> 1
|
99
|
-
# @return [Object] the detected block result
|
100
|
-
# @see #detect_with_value
|
101
|
-
def detect_value
|
102
|
-
each do |*item|
|
103
|
-
value = yield(*item)
|
104
|
-
return value if value
|
105
|
-
end
|
106
|
-
nil
|
107
|
-
end
|
108
|
-
|
109
|
-
# Returns the first item and value for which an enumeration on the block given to this method returns
|
110
|
-
# a non-nil, non-false value.
|
111
|
-
#
|
112
|
-
# @example
|
113
|
-
# [1, 2].detect_with_value { |item| item / 2 if item % 2 == 0 } #=> [2, 1]
|
114
|
-
# @return [(Object, Object)] the detected [item, value] pair
|
115
|
-
# @see #detect_value
|
116
|
-
def detect_with_value
|
117
|
-
value = nil
|
118
|
-
match = detect do |*item|
|
119
|
-
value = yield(*item)
|
120
|
-
end
|
121
|
-
[match, value]
|
122
|
-
end
|
123
|
-
|
124
|
-
# Returns a new Enumerable that iterates over the base Enumerable items for which filter evaluates to a non-nil,
|
125
|
-
# non-false value, e.g.:
|
126
|
-
# [1, 2, 3].filter { |n| n != 2 }.to_a #=> [1, 3]
|
127
|
-
#
|
128
|
-
# Unlike select, filter reflects changes to the base Enumerable, e.g.:
|
129
|
-
# a = [1, 2, 3]
|
130
|
-
# filter = a.filter { |n| n != 2 }
|
131
|
-
# a << 4
|
132
|
-
# filter.to_a #=> [1, 3, 4]
|
133
|
-
#
|
134
|
-
# In addition, filter has a small, fixed storage requirement, making it preferable to select for large collections.
|
135
|
-
# Note, however, that unlike select, filter does not return an Array.
|
136
|
-
# The default filter block returns the passed item.
|
137
|
-
#
|
138
|
-
# @example
|
139
|
-
# [1, nil, 3].filter.to_a #=> [1, 3]
|
140
|
-
# @yield [item] filter the selection filter
|
141
|
-
# @yieldparam item the collection member to filter
|
142
|
-
# @return [Enumerable] the filtered result
|
143
|
-
def filter(&filter)
|
144
|
-
Jinx::Filter.new(self, &filter)
|
145
|
-
end
|
146
|
-
|
147
|
-
# @return [Enumerable] an iterator over the non-nil items in this Enumerable
|
148
|
-
def compact
|
149
|
-
filter { |item| not item.nil? }
|
150
|
-
end
|
151
|
-
|
152
|
-
# @example
|
153
|
-
# {:a => {:b => :c}, :d => [:e]}.enum_values.flatten.to_a #=> [:b, :c, :e]
|
154
|
-
# @return [Enumerable] the flattened result
|
155
|
-
def flatten
|
156
|
-
Jinx::Flattener.new(self).to_a
|
157
|
-
end
|
158
|
-
|
159
|
-
# Returns an Enumerable which iterates over items in this Enumerable and the other Enumerable in sequence.
|
160
|
-
# Unlike the Array plus (+) operator, {#union} reflects changes to the underlying enumerators.
|
161
|
-
#
|
162
|
-
# @quirk Cucumber Cucumber defines it's own Enumerable union monkey-patch. Work around this in the short
|
163
|
-
# term by trying to call the super first.
|
164
|
-
#
|
165
|
-
# @example
|
166
|
-
# a = [1, 2]
|
167
|
-
# b = [4, 5]
|
168
|
-
# ab = a.union(b)
|
169
|
-
# ab #=> [1, 2, 4, 5]
|
170
|
-
# a << 3
|
171
|
-
# a + b #=> [1, 2, 4, 5]
|
172
|
-
# ab #=> [1, 2, 3, 4, 5]
|
173
|
-
# @param [Enumerable] other the Enumerable to compose with this Enumerable
|
174
|
-
# @return [Enumerable] an enumerator over self followed by other
|
175
|
-
def union(other)
|
176
|
-
super rescue Jinx::MultiEnumerator.new(self, other)
|
177
|
-
end
|
178
|
-
|
179
|
-
alias :+ :union
|
180
|
-
|
181
|
-
# @return an Enumerable which iterates over items in this Enumerable but not the other Enumerable
|
182
|
-
def difference(other)
|
183
|
-
filter { |item| not other.include?(item) }
|
184
|
-
end
|
185
|
-
|
186
|
-
alias :- :difference
|
187
|
-
|
188
|
-
# @return an Enumerable which iterates over items in this Enumerable which are also in the other Enumerable
|
189
|
-
def intersect(other)
|
190
|
-
filter { |item| other.include?(item) }
|
191
|
-
end
|
192
|
-
|
193
|
-
alias :& :intersect
|
194
|
-
|
195
|
-
# Returns a new Enumerable that iterates over the base Enumerable applying the transformer block to each item, e.g.:
|
196
|
-
# [1, 2, 3].transform_value { |n| n * 2 }.to_a #=> [2, 4, 6]
|
197
|
-
#
|
198
|
-
# Unlike Array.map, {#wrap} reflects changes to the base Enumerable, e.g.:
|
199
|
-
# a = [2, 4, 6]
|
200
|
-
``# transformed = a.wrap { |n| n * 2 }
|
201
|
-
# a << 4
|
202
|
-
# transformed.to_a #=> [2, 4, 6, 8]
|
203
|
-
#
|
204
|
-
# In addition, transform has a small, fixed storage requirement, making it preferable to select for large collections.
|
205
|
-
# Note, however, that unlike map, transform does not return an Array.
|
206
|
-
#
|
207
|
-
# @yield [item] the transformer on the enumerated items
|
208
|
-
# @yieldparam item an enumerated item
|
209
|
-
# @return [Enumerable] an enumeration on the transformed values
|
210
|
-
def transform(&mapper)
|
211
|
-
Jinx::Transformer.new(self, &mapper)
|
212
|
-
end
|
213
|
-
|
214
|
-
alias :wrap :transform
|
215
|
-
|
216
|
-
def join(sep = $,)
|
217
|
-
to_a.join(sep)
|
218
|
-
end
|
219
|
-
|
220
|
-
# Sorts this collection's members with a partial sort operator, i.e. the comparison returns -1, 0, 1 or nil.
|
221
|
-
# The resulting sorted order places each non-nil comparable items in the sort order. The order of nil
|
222
|
-
# comparison items is indeterminate.
|
223
|
-
#
|
224
|
-
# @example
|
225
|
-
# [Array, Numeric, Enumerable, Set].partial_sort #=> [Array, Numeric, Set, Enumerable]
|
226
|
-
# @return [Enumerable] the items in this collection in partial sort order
|
227
|
-
def partial_sort
|
228
|
-
unless block_given? then return partial_sort { |item1, item2| item1 <=> item2 } end
|
229
|
-
sort { |item1, item2| yield(item1, item2) or 1 }
|
230
|
-
end
|
231
|
-
|
232
|
-
# Sorts this collection's members with a partial sort operator on the results of applying the block.
|
233
|
-
#
|
234
|
-
# @return [Enumerable] the items in this collection in partial sort order
|
235
|
-
def partial_sort_by
|
236
|
-
partial_sort { |item1, item2| yield(item1) <=> yield(item2) }
|
237
|
-
end
|
238
|
-
|
239
|
-
# @yield [item] the transformer on the enumerated items
|
240
|
-
# @yieldparam item an enumerated item
|
241
|
-
# @return [Enumerable] the mapped values excluding null values
|
242
|
-
def compact_map(&mapper)
|
243
|
-
wrap(&mapper).compact
|
244
|
-
end
|
245
|
-
end
|