rmtools 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,6 +27,19 @@ It's still randomly documented since it's just my working tool.
27
27
 
28
28
  ### CHANGES
29
29
 
30
+ ##### Version 2.2.3
31
+
32
+ * Hash
33
+ * #key_value = to_a.first
34
+
35
+ * Array
36
+ * #fold[l,r]_<method> now passes up to 2 arguments to fold itself
37
+ * Aliased sort_along_by => order_by
38
+
39
+ * Dir
40
+ * Fixed #content for dirs with dotted files only
41
+ * #content now accepts :recursive and :include_dot options turned off by default
42
+
30
43
  ##### Version 2.2.2
31
44
 
32
45
  * Enumerable
@@ -55,6 +68,7 @@ It's still randomly documented since it's just my working tool.
55
68
 
56
69
  * Array
57
70
  * Added #any and #none to iterators pattern
71
+
58
72
  * Hash
59
73
  * Fixed #any? (and removed it for Ruby>=1.9)
60
74
 
@@ -64,6 +78,7 @@ It's still randomly documented since it's just my working tool.
64
78
  * For ruby >= 1.9.3 #uniq_by[!] is alias of #uniq[!] itself, since it’s native implementation appears to be ~1.4x faster
65
79
  * A bit better english singularizer for iterators
66
80
  * Added #partition_by iterator
81
+
67
82
  * Enumerable
68
83
  * Generalized faster set operations for Array and Set (see rmtools/enumerable/set_ops)
69
84
  * Boosted &-operator
data/ext/extconf.rb CHANGED
@@ -5,8 +5,6 @@ if RUBY_VERSION >= "1.9"
5
5
  $CFLAGS += " -DRUBY_IS_19"
6
6
  end
7
7
 
8
- $LDFLAGS += " -module"
9
-
10
8
  dir_config("ruby19")
11
9
  create_makefile("rmtools")
12
10
 
@@ -14,7 +14,8 @@ module RMTools
14
14
  end
15
15
 
16
16
  def files_stats(*stat_params)
17
- Dir(@pwd || Dir.pwd).recursive_content.flatten.map_hash {|fn|
17
+ opts = {recursive: true, include_dot: true}.merge(stat_params.extract_options!)
18
+ Dir(@pwd || Dir.pwd).content(opts).map_hash {|fn|
18
19
  if File.file? fn
19
20
  if stat_params
20
21
  stats = stat_params.map_hash {|param|
@@ -173,6 +173,7 @@ class Array
173
173
  sort_by {|e| ary.index yield e}
174
174
  end
175
175
  end
176
+ alias :order_by :sort_along_by
176
177
 
177
178
  # concatenation
178
179
  # analogue to String#>>
@@ -12,10 +12,15 @@ RMTools::require 'enumerable/array'
12
12
  # => [[1, 2, 3], [3, 4, 6]]
13
13
  class Array
14
14
  alias :throw_no :method_missing
15
- mattr_reader :iterators_names, :iterators_pattern
15
+ if respond_to? :mattr_reader
16
+ mattr_reader :iterators_names, :iterators_pattern
17
+ else
18
+ cattr_reader :iterators_names, :iterators_pattern, :instance_reader => false
19
+ end
16
20
  @@iterators_names = []
17
21
 
18
22
  private
23
+
19
24
  def simple_inplace_singularize!(noun)
20
25
  noun.sub!(/(ss|[sc]h|[xo])es([=!?]?)$/, '\1\2') or
21
26
  noun.sub!(/ies([=!?]?)$/, 'y\1') or
@@ -69,9 +74,14 @@ private
69
74
 
70
75
  begin
71
76
  return case iterator
72
- when :sum, :sort_along_by; __send__(iterator, args.shift) {|i| i.__send__ meth, *args, &block}
73
- when :find_by, :select_by, :reject_by, :partition_by; __send__(iterator, meth, *args)
74
- else __send__(iterator) {|i| i.__send__ meth, *args, &block}
77
+ when :sum, :sort_along_by
78
+ __send__(iterator, args.shift) {|i| i.__send__ meth, *args, &block}
79
+ when :find_by, :select_by, :reject_by, :partition_by
80
+ __send__(iterator, meth, *args)
81
+ when :fold, :foldl, :foldr
82
+ __send__(iterator, *args[0, 2]) {|e| e.__send__ meth, *args[2..-1], &block}
83
+ else
84
+ __send__(iterator) {|i| i.__send__ meth, *args, &block}
75
85
  end
76
86
  rescue NoMethodError => e
77
87
  e.message << " (`#{method}' interpreted as decorator-function `#{meth}')"
@@ -230,30 +240,40 @@ private
230
240
 
231
241
  case iterator
232
242
  when :sum, :sort_along_by
233
- Array.class_eval %{
234
- def #{method}(*args, &block)
235
243
  # sum_posts_ids([], :all) =>
236
244
  # sum([]) {|e| e.posts_ids(:all)}
245
+ Array.class_eval %{
246
+ def #{method}(*args, &block)
237
247
  #{iterator}(args.shift) {|e| e.#{meth}(*args, &block)}
238
248
  rescue NoMethodError => err
239
249
  err.message << " (`#{method}' interpreted as decorator-function `#{meth}')"
240
250
  raise err
241
251
  end}
242
252
  when :find_by, :rfind_by, :select_by, :reject_by, :partition_by
243
- Array.class_eval %{
244
- def #{method}(val)
245
253
  # select_by_count(max_count) =>
246
254
  # select {|e| e.count == max_count}
255
+ Array.class_eval %{
256
+ def #{method}(val)
247
257
  #{iterator.to_s[0...-3]} {|e| e.#{meth} == val}
248
258
  rescue NoMethodError => err
249
259
  err.message << " (`#{method}' interpreted as decorator-function `#{meth}')"
250
260
  raise err
251
- end}
252
- else
261
+ end}
262
+ when :fold, :foldl, :foldr
263
+ # fold_responders(:|, []) =>
264
+ # fold(:|, []) {|e| e.responders}
253
265
  Array.class_eval %{
254
266
  def #{method}(*args, &block)
267
+ #{iterator}(*args[0, 2]) {|e| e.#{meth}(*args[2..-1], &block)}
268
+ rescue NoMethodError => err
269
+ err.message << " (`#{method}' interpreted as decorator-function `#{meth}')"
270
+ raise err
271
+ end}
272
+ else
255
273
  # uniq_by_sum(1) {|i| 1 / i.weight} =>
256
274
  # uniq_by {|e| e.sum(1) {|i| 1 / i .weight}}
275
+ Array.class_eval %{
276
+ def #{method}(*args, &block)
257
277
  #{iterator} {|e| e.#{meth}(*args, &block)}
258
278
  rescue NoMethodError => err
259
279
  err.message << " (`#{method}' interpreted as decorator-function `#{meth}')"
@@ -266,15 +286,17 @@ private
266
286
  meth = meth.to_sym
267
287
 
268
288
  if assignment
289
+ # if Array === value
290
+ # owner_ids = users_ids =>
291
+ # each_with_index {|e, i| e.owner_id = users_ids[i]}
292
+ # else
293
+ # owner_ids = user_id =>
294
+ # each {|e, i| e.owner_id = user_id}
269
295
  Array.class_eval %{
270
296
  def #{method}(value)
271
297
  if Array === value
272
- # owner_ids = users_ids =>
273
- # each_with_index {|e, i| e.owner_id = users_ids[i]}
274
298
  each_with_index {|e, i| e.#{meth} value[i]}
275
299
  else
276
- # owner_ids = user_id =>
277
- # each {|e, i| e.owner_id = user_id}
278
300
  each {|e| e.#{meth} value}
279
301
  end
280
302
  rescue NoMethodError => err
@@ -282,10 +304,10 @@ private
282
304
  raise err
283
305
  end}
284
306
  else
285
- Array.class_eval %{
286
- def #{method}(*args, &block)
287
307
  # to_is(16) =>
288
308
  # map {|e| e.to_i(16)}
309
+ Array.class_eval %{
310
+ def #{method}(*args, &block)
289
311
  map {|e| e.#{meth}(*args, &block)}
290
312
  rescue NoMethodError => err
291
313
  err.message << " (`#{method}' interpreted as map-function `#{meth}')"
@@ -11,25 +11,24 @@ class Dir
11
11
  end
12
12
 
13
13
  def include?(name)
14
- #content.map {|f| File.split(f)[1]}.include? name
15
- entries.include? name
14
+ to_a.include? name
16
15
  end
17
16
 
18
- def recursive_content(flat=true)
19
- list = []
20
- cont = content.map {|f|
21
- if File.directory?(f)
22
- rc = Dir.new(f).recursive_content(flat)
23
- flat ? list.concat(rc) : rc
24
- else flat ? (list << f.sub(/^\.\//, '')) : f.sub(/^\.\//, '')
17
+ def recursive_content(flat=true, opts={})
18
+ if opts[:recursive] = flat
19
+ return content(opts)
20
+ end
21
+ content(opts).map {|p|
22
+ if File.directory?(p)
23
+ Dir.new(p).recursive_content(false)
24
+ else p
25
25
  end
26
26
  }
27
- (flat ? list : cont)
28
27
  end
29
28
 
30
- def content
31
- list = Dir["#{path}/**"]
32
- list.empty? ? to_a[2..-1].sort.map {|c| File.join path, c} : list
29
+ def content(opts={})
30
+ Dir["#{path}/#{'**/' if opts.recursive}#{'{.,}' if opts.include_dot}*"].
31
+ reject {|p| p =~ %r{/\.\.?$}}.map! {|p| p.sub(/^\.\//, '')}
33
32
  end
34
33
 
35
34
  def parent
@@ -1,3 +1,3 @@
1
1
  module RMTools
2
- VERSION = '2.2.2'
2
+ VERSION = '2.2.3'
3
3
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Sergey Baev
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-07-05 00:00:00.000000000 Z
12
+ date: 2013-07-19 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activesupport
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: bundler
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rake
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -165,26 +172,27 @@ files:
165
172
  homepage: https://github.com/tinbka/rmtools
166
173
  licenses:
167
174
  - MIT
168
- metadata: {}
169
175
  post_install_message:
170
176
  rdoc_options: []
171
177
  require_paths:
172
178
  - lib
173
179
  required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
174
181
  requirements:
175
182
  - - ! '>='
176
183
  - !ruby/object:Gem::Version
177
184
  version: '0'
178
185
  required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
179
187
  requirements:
180
188
  - - ! '>='
181
189
  - !ruby/object:Gem::Version
182
190
  version: '0'
183
191
  requirements: []
184
192
  rubyforge_project:
185
- rubygems_version: 2.0.3
193
+ rubygems_version: 1.8.24
186
194
  signing_key:
187
- specification_version: 4
195
+ specification_version: 3
188
196
  summary: Collection of helpers for debug, text/array/file processing and simply easing
189
197
  a coding process
190
198
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZWUxNjE2OGIzZjY5Njk0MTVjNDA4NzY3YTQwNjE2NGY5ZDQ5NWRiMA==
5
- data.tar.gz: !binary |-
6
- ODY0YzAwNjFlYzg4MmNiODUxZjBkYjIwMmJjOTlkZDViZWU5MjAyZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- M2E4OGZlYjY4NDRjYzVhZTMxMGFiMzUwOTAxYWUzMGIxZjY4MzUwOGFhZTA3
10
- ZWQzNWJiMWNlMzA2MzNiYjAwZTkyOGJmMTZmODg4NWVmNjYwNjkxYTJlOTk1
11
- YTRjZWNiM2E0NDM5NWJmYmRmNmFjNTIxNThlZjk5MTE4MjBjOWU=
12
- data.tar.gz: !binary |-
13
- NDI0NTQ0ZWMxZjM3ZDA1NTY4YWQ1ZmFhMjhiN2UwYTk2NmFjYmI2N2FhNzQx
14
- NWEzNjQ0YjQxM2NiOTI0NTY4ODdmOTZiODIzMjFhZDFkNTJjNTljNDU3YzNh
15
- ODJkZTJjNDZkZDEzOTliYjFlNTkwNTgwOTcyNzY1ZjFmY2VlODY=