more_core_extensions 3.7.0 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +9 -0
- data/README.md +1 -0
- data/lib/more_core_extensions/core_ext/array.rb +2 -0
- data/lib/more_core_extensions/core_ext/array/compact_map.rb +19 -0
- data/lib/more_core_extensions/core_ext/array/sorting.rb +35 -0
- data/lib/more_core_extensions/core_ext/class/hierarchy.rb +9 -0
- data/lib/more_core_extensions/core_ext/enumerable/sorting.rb +4 -28
- data/lib/more_core_extensions/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 524540f9e367a22c26d7512ba3a1b6fea7853f00cb9c982b847c38647afb50ce
|
4
|
+
data.tar.gz: 8ec0767016594dc332cfb62c47bf1807f1c9a0f709f0663c454bdd47bb4bb9b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fe6963df47f3334862545d9ab33870a0de051cc5766e62041441fe4a2b51f15fc66d243b36e794470c8db00db45a6864dcbbd26a1df233caa90ebe2c1fb7ec3
|
7
|
+
data.tar.gz: fee6fc9df914d2d24f9167503e1ede607f79f7700f444f61803429af7dbc35e0f625f9a69ce5bcc2d65429c9e1d80004b27b41033ddb83bf9156eb86c34c815d
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
5
5
|
## [Unreleased]
|
6
6
|
|
7
|
+
## [3.8.0] - 2020-01-31
|
8
|
+
### Changed
|
9
|
+
- Renamed Enumerable#stable_sort_by to Array#tabular_sort [[#68](https://github.com/ManageIQ/more_core_extensions/pull/68)]
|
10
|
+
- Deprecated Enumerable#stable_sort_by [[#74](https://github.com/ManageIQ/more_core_extensions/pull/74)]
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- Added Class#leaf_subclasses [[#71](https://github.com/ManageIQ/more_core_extensions/pull/71)]
|
14
|
+
- Added Array#compact_map [[#63](https://github.com/ManageIQ/more_core_extensions/pull/63)]
|
15
|
+
|
7
16
|
## [3.7.0] - 2019-02-04
|
8
17
|
### Added
|
9
18
|
- Added Enumerable#stable_sort_by [[#67](https://github.com/ManageIQ/more_core_extensions/pull/67)]
|
data/README.md
CHANGED
@@ -49,6 +49,7 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS
|
|
49
49
|
* core_ext/class/hierarchy.rb
|
50
50
|
* `#hierarchy` - Returns a tree-like Hash structure of all descendants.
|
51
51
|
* `#lineage` - Returns an Array of all superclasses.
|
52
|
+
* `#leaf_subclasses` - Returns an Array of all descendants which have no subclasses.
|
52
53
|
|
53
54
|
#### Hash
|
54
55
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'more_core_extensions/core_ext/array/compact_map'
|
1
2
|
require 'more_core_extensions/core_ext/array/deletes'
|
2
3
|
require 'more_core_extensions/core_ext/array/duplicates'
|
3
4
|
require 'more_core_extensions/core_ext/array/element_counts'
|
@@ -5,5 +6,6 @@ require 'more_core_extensions/core_ext/array/inclusions'
|
|
5
6
|
require 'more_core_extensions/core_ext/array/math'
|
6
7
|
require 'more_core_extensions/core_ext/array/nested'
|
7
8
|
require 'more_core_extensions/core_ext/array/random'
|
9
|
+
require 'more_core_extensions/core_ext/array/sorting'
|
8
10
|
require 'more_core_extensions/core_ext/array/stretch'
|
9
11
|
require 'more_core_extensions/core_ext/array/tableize'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MoreCoreExtensions
|
2
|
+
module ArrayCompactMap
|
3
|
+
# Collect non-nil results from the block. Basically [].collect { |i| ... }.compact
|
4
|
+
#
|
5
|
+
# [1,2,3,4,5].compact_map { |i| i * 2 if i.odd?} # => [2,6,10]
|
6
|
+
def compact_map
|
7
|
+
return enum_for(:compact_map) unless block_given?
|
8
|
+
|
9
|
+
[].tap do |results|
|
10
|
+
each do |i|
|
11
|
+
result = yield(i)
|
12
|
+
results << result if result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Array.send(:include, MoreCoreExtensions::ArrayCompactMap)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module MoreCoreExtensions
|
2
|
+
module StableSorting
|
3
|
+
def tabular_sort(col_names = nil, order = nil, &block)
|
4
|
+
# stabilizer is needed because of
|
5
|
+
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170565
|
6
|
+
stabilizer = 0
|
7
|
+
nil_rows, sortable =
|
8
|
+
partition do |r|
|
9
|
+
Array(col_names).any? { |c| r[c].nil? }
|
10
|
+
end
|
11
|
+
|
12
|
+
data_array =
|
13
|
+
if col_names
|
14
|
+
sortable.sort_by do |r|
|
15
|
+
stabilizer += 1
|
16
|
+
[Array(col_names).map do |col|
|
17
|
+
val = r[col]
|
18
|
+
val = val.downcase if val.kind_of?(String)
|
19
|
+
val = val.to_s if val.kind_of?(FalseClass) || val.kind_of?(TrueClass)
|
20
|
+
val
|
21
|
+
end, stabilizer]
|
22
|
+
end
|
23
|
+
else
|
24
|
+
sortable.sort_by(&block)
|
25
|
+
end.to_a
|
26
|
+
|
27
|
+
data_array += nil_rows
|
28
|
+
|
29
|
+
data_array.reverse! if order == :descending
|
30
|
+
data_array
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Array.send(:include, MoreCoreExtensions::StableSorting)
|
@@ -24,6 +24,15 @@ module MoreCoreExtensions
|
|
24
24
|
def lineage
|
25
25
|
superclass.nil? ? [] : superclass.lineage.unshift(superclass)
|
26
26
|
end
|
27
|
+
|
28
|
+
# Returns an Array of all descendants which have no subclasses
|
29
|
+
#
|
30
|
+
# require 'socket'
|
31
|
+
# BasicSocket.leaf_subclasses
|
32
|
+
# # => [Socket, TCPServer, UDPSocket, UNIXServer]
|
33
|
+
def leaf_subclasses
|
34
|
+
descendants.select { |d| d.subclasses.empty? }
|
35
|
+
end
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
@@ -2,34 +2,10 @@ module MoreCoreExtensions
|
|
2
2
|
module StableSorting
|
3
3
|
def self.included(klass)
|
4
4
|
klass.class_eval do
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
nil_rows, sortable =
|
10
|
-
partition do |r|
|
11
|
-
Array(col_names).any? { |c| r[c].nil? }
|
12
|
-
end
|
13
|
-
|
14
|
-
data_array =
|
15
|
-
if col_names
|
16
|
-
sortable.sort_by do |r|
|
17
|
-
stabilizer += 1
|
18
|
-
[Array(col_names).map do |col|
|
19
|
-
val = r[col]
|
20
|
-
val = val.downcase if val.kind_of?(String)
|
21
|
-
val = val.to_s if val.kind_of?(FalseClass) || val.kind_of?(TrueClass)
|
22
|
-
val
|
23
|
-
end, stabilizer]
|
24
|
-
end
|
25
|
-
else
|
26
|
-
sortable.sort_by(&block)
|
27
|
-
end.to_a
|
28
|
-
|
29
|
-
data_array += nil_rows
|
30
|
-
|
31
|
-
data_array.reverse! if order == :descending
|
32
|
-
data_array
|
5
|
+
# <b>DEPRECATED:</b> Please use <tt>tabular_sort</tt> instead.
|
6
|
+
def stable_sort_by(*args)
|
7
|
+
warn "[DEPRECATION] `stable_sort_by` is deprecated. Please use `Array#tabular_sort` instead."
|
8
|
+
to_a.tabular_sort(*args)
|
33
9
|
end
|
34
10
|
end
|
35
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: more_core_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Frey
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- lib/more_core_extensions.rb
|
134
134
|
- lib/more_core_extensions/all.rb
|
135
135
|
- lib/more_core_extensions/core_ext/array.rb
|
136
|
+
- lib/more_core_extensions/core_ext/array/compact_map.rb
|
136
137
|
- lib/more_core_extensions/core_ext/array/deletes.rb
|
137
138
|
- lib/more_core_extensions/core_ext/array/duplicates.rb
|
138
139
|
- lib/more_core_extensions/core_ext/array/element_counts.rb
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- lib/more_core_extensions/core_ext/array/math.rb
|
141
142
|
- lib/more_core_extensions/core_ext/array/nested.rb
|
142
143
|
- lib/more_core_extensions/core_ext/array/random.rb
|
144
|
+
- lib/more_core_extensions/core_ext/array/sorting.rb
|
143
145
|
- lib/more_core_extensions/core_ext/array/stretch.rb
|
144
146
|
- lib/more_core_extensions/core_ext/array/tableize.rb
|
145
147
|
- lib/more_core_extensions/core_ext/benchmark.rb
|
@@ -195,8 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
197
|
- !ruby/object:Gem::Version
|
196
198
|
version: '0'
|
197
199
|
requirements: []
|
198
|
-
|
199
|
-
rubygems_version: 2.6.14.3
|
200
|
+
rubygems_version: 3.0.6
|
200
201
|
signing_key:
|
201
202
|
specification_version: 4
|
202
203
|
summary: MoreCoreExtensions are a set of core extensions beyond those provided by
|