rearmed 1.3.1 → 2.0.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 +54 -11
- data/Rakefile +5 -14
- data/lib/rearmed.rb +51 -2
- data/lib/rearmed/exceptions.rb +9 -3
- data/lib/rearmed/methods.rb +143 -91
- data/lib/rearmed/monkey_patches/array.rb +1 -1
- data/lib/rearmed/monkey_patches/date.rb +1 -1
- data/lib/rearmed/monkey_patches/enumerable.rb +6 -6
- data/lib/rearmed/monkey_patches/hash.rb +6 -6
- data/lib/rearmed/monkey_patches/integer.rb +11 -0
- data/lib/rearmed/monkey_patches/object.rb +20 -2
- data/lib/rearmed/monkey_patches/string.rb +11 -5
- data/lib/rearmed/version.rb +1 -1
- data/test/rearmed_test.rb +353 -0
- metadata +7 -8
- data/lib/rearmed/apply_patches.rb +0 -6
- data/lib/rearmed/default_enabled_patches.hash +0 -66
- data/test/tc_rearmed.rb +0 -215
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rearmed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
description: A collection of helpful methods and monkey patches for Objects, Strings,
|
56
56
|
Enumerables, Arrays, Hash, Dates, Minitest & Rails
|
57
|
-
email: westonganger
|
57
|
+
email: weston@westonganger.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
@@ -64,18 +64,17 @@ files:
|
|
64
64
|
- README.md
|
65
65
|
- Rakefile
|
66
66
|
- lib/rearmed.rb
|
67
|
-
- lib/rearmed/apply_patches.rb
|
68
|
-
- lib/rearmed/default_enabled_patches.hash
|
69
67
|
- lib/rearmed/exceptions.rb
|
70
68
|
- lib/rearmed/methods.rb
|
71
69
|
- lib/rearmed/monkey_patches/array.rb
|
72
70
|
- lib/rearmed/monkey_patches/date.rb
|
73
71
|
- lib/rearmed/monkey_patches/enumerable.rb
|
74
72
|
- lib/rearmed/monkey_patches/hash.rb
|
73
|
+
- lib/rearmed/monkey_patches/integer.rb
|
75
74
|
- lib/rearmed/monkey_patches/object.rb
|
76
75
|
- lib/rearmed/monkey_patches/string.rb
|
77
76
|
- lib/rearmed/version.rb
|
78
|
-
- test/
|
77
|
+
- test/rearmed_test.rb
|
79
78
|
homepage: https://github.com/westonganger/rearmed-rb
|
80
79
|
licenses: []
|
81
80
|
metadata: {}
|
@@ -95,10 +94,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
94
|
version: '0'
|
96
95
|
requirements: []
|
97
96
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.6
|
97
|
+
rubygems_version: 2.7.6
|
99
98
|
signing_key:
|
100
99
|
specification_version: 4
|
101
100
|
summary: A collection of helpful methods and monkey patches for Objects, Strings,
|
102
101
|
Enumerables, Arrays, Hash, Dates, Minitest & Rails
|
103
102
|
test_files:
|
104
|
-
- test/
|
103
|
+
- test/rearmed_test.rb
|
@@ -1,66 +0,0 @@
|
|
1
|
-
{
|
2
|
-
array: {
|
3
|
-
dig: false,
|
4
|
-
delete_first: false,
|
5
|
-
not_empty: false
|
6
|
-
},
|
7
|
-
date: {
|
8
|
-
now: false
|
9
|
-
},
|
10
|
-
enumerable: {
|
11
|
-
natural_sort: false,
|
12
|
-
natural_sort_by: false,
|
13
|
-
select_map: false
|
14
|
-
},
|
15
|
-
hash: {
|
16
|
-
compact: false,
|
17
|
-
dig: false,
|
18
|
-
join: false,
|
19
|
-
only: false,
|
20
|
-
to_struct: false
|
21
|
-
},
|
22
|
-
object: {
|
23
|
-
in: false,
|
24
|
-
not_nil: false
|
25
|
-
},
|
26
|
-
string: {
|
27
|
-
begins_with: false,
|
28
|
-
casecmp?: false,
|
29
|
-
ends_with: false,
|
30
|
-
starts_with: false,
|
31
|
-
to_bool: false,
|
32
|
-
valid_float: false,
|
33
|
-
valid_integer: false
|
34
|
-
},
|
35
|
-
minitest: {
|
36
|
-
assert_changed: false,
|
37
|
-
assert_not_changed: false
|
38
|
-
},
|
39
|
-
rails: {
|
40
|
-
active_record: {
|
41
|
-
find_duplicates: false,
|
42
|
-
find_in_relation_batches: false,
|
43
|
-
find_or_create: false,
|
44
|
-
find_relation_each: false,
|
45
|
-
newest: false,
|
46
|
-
pluck_to_hash: false,
|
47
|
-
pluck_to_struct: false,
|
48
|
-
reset_auto_increment: false,
|
49
|
-
reset_table: false
|
50
|
-
},
|
51
|
-
other: {
|
52
|
-
field_is_array: false,
|
53
|
-
options_for_select_include_blank: false,
|
54
|
-
options_from_collection_for_select_include_blank: false
|
55
|
-
}
|
56
|
-
},
|
57
|
-
rails_4: {
|
58
|
-
link_to_confirm: false,
|
59
|
-
or: false
|
60
|
-
},
|
61
|
-
rails_3: {
|
62
|
-
all: false,
|
63
|
-
pluck: false,
|
64
|
-
update_columns: false
|
65
|
-
}
|
66
|
-
}
|
data/test/tc_rearmed.rb
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -w
|
2
|
-
|
3
|
-
lib = File.expand_path('../lib', __FILE__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
|
-
require 'yaml'
|
7
|
-
require 'minitest'
|
8
|
-
|
9
|
-
require 'rearmed'
|
10
|
-
|
11
|
-
require 'minitest/autorun'
|
12
|
-
|
13
|
-
class TestRearmed < MiniTest::Test
|
14
|
-
def setup
|
15
|
-
Minitest::Assertions.module_eval do
|
16
|
-
alias_method :eql, :assert_equal
|
17
|
-
end
|
18
|
-
|
19
|
-
Rearmed.enabled_patches = {
|
20
|
-
array: true,
|
21
|
-
hash: true,
|
22
|
-
object: true,
|
23
|
-
string: true,
|
24
|
-
date: true,
|
25
|
-
enumerable: true,
|
26
|
-
rails_3: true,
|
27
|
-
rails_4: true,
|
28
|
-
rails: true,
|
29
|
-
minitest: true
|
30
|
-
}
|
31
|
-
require 'rearmed/apply_patches'
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_string
|
35
|
-
# Test String Methods
|
36
|
-
str = '32'
|
37
|
-
eql(str.valid_integer?, true)
|
38
|
-
|
39
|
-
str = '32.2'
|
40
|
-
eql(str.valid_integer?, false)
|
41
|
-
|
42
|
-
str = '32a'
|
43
|
-
eql(str.valid_integer?, false)
|
44
|
-
|
45
|
-
|
46
|
-
str = '12'
|
47
|
-
eql(Rearmed.valid_integer?(str), true)
|
48
|
-
|
49
|
-
str = '132.2'
|
50
|
-
eql(str.valid_float?, true)
|
51
|
-
|
52
|
-
str = '132.2.2'
|
53
|
-
eql(str.valid_float?, false)
|
54
|
-
|
55
|
-
str = '12.1a'
|
56
|
-
eql(str.valid_float?, false)
|
57
|
-
|
58
|
-
str = '1.2'
|
59
|
-
eql(Rearmed.valid_float?(str), true)
|
60
|
-
|
61
|
-
|
62
|
-
str = 'true'
|
63
|
-
eql(str.to_bool, true)
|
64
|
-
|
65
|
-
str = 'false'
|
66
|
-
eql(str.to_bool, false)
|
67
|
-
|
68
|
-
str = 'not true'
|
69
|
-
assert_nil(str.to_bool)
|
70
|
-
|
71
|
-
str = 'true'
|
72
|
-
eql(Rearmed.to_bool(str), true)
|
73
|
-
|
74
|
-
|
75
|
-
str1 = 'foo'
|
76
|
-
str2 = 'foo'
|
77
|
-
eql(str1.casecmp?(str2), true)
|
78
|
-
|
79
|
-
str1 = 'foo'
|
80
|
-
str2 = 'FOO'
|
81
|
-
eql(str1.casecmp?(str2), true)
|
82
|
-
|
83
|
-
str1 = 'foo'
|
84
|
-
str2 = 'foobar'
|
85
|
-
eql(str1.casecmp?(str2), false)
|
86
|
-
|
87
|
-
str1 = 'foo'
|
88
|
-
str2 = 'fo'
|
89
|
-
eql(str1.casecmp?(str2), false)
|
90
|
-
|
91
|
-
str1 = 'foo'
|
92
|
-
str2 = 'foo'
|
93
|
-
eql(Rearmed.casecmp?(str1, str2), true)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_date
|
97
|
-
Date.now
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_enumerable
|
101
|
-
items = ['1.1', '1.11', '1.2']
|
102
|
-
eql(items.natural_sort, ['1.1','1.2','1.11'])
|
103
|
-
eql(items.natural_sort(reverse: true), ['1.11','1.2','1.1'])
|
104
|
-
eql(Rearmed.natural_sort(items), ['1.1','1.2','1.11'])
|
105
|
-
eql(Rearmed.natural_sort(items, reverse: true), ['1.11','1.2','1.1'])
|
106
|
-
|
107
|
-
items = [{version: "1.1"}, {version: "1.11"}, {version: "1.2"}]
|
108
|
-
eql(items.natural_sort_by{|x| x[:version]}, [{version: "1.1"}, {version: "1.2"}, {version: "1.11"}])
|
109
|
-
eql(Rearmed.natural_sort_by(items){|x| x[:version]}, [{version: "1.1"}, {version: "1.2"}, {version: "1.11"}])
|
110
|
-
|
111
|
-
items = [0, 1, 2, 3, nil, false]
|
112
|
-
eql(items.select_map{|x| x}, [0,1,2,3])
|
113
|
-
eql(Rearmed.select_map(items){|x| x}, [0,1,2,3])
|
114
|
-
|
115
|
-
assert items.select_map.is_a?(Enumerator)
|
116
|
-
assert Rearmed.select_map(items).is_a?(Enumerator)
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_array
|
120
|
-
array = [1,3,2,1,3,4,1]
|
121
|
-
array.delete_first(3)
|
122
|
-
eql(array, [1,2,1,3,4,1])
|
123
|
-
|
124
|
-
array = [1,3,2,1,3,4,1]
|
125
|
-
array.delete_first
|
126
|
-
eql(array, [3,2,1,3,4,1])
|
127
|
-
|
128
|
-
array = [1,3,2,1,3,4,1]
|
129
|
-
array.delete_first{|x| x != 1}
|
130
|
-
eql(array, [1,2,1,3,4,1])
|
131
|
-
|
132
|
-
eql(array.not_empty?, true)
|
133
|
-
|
134
|
-
array = [{foo: ['foo','bar']}, {test: 'thing'}]
|
135
|
-
eql(array.dig(0, :foo, 1), 'bar')
|
136
|
-
assert_nil(array.dig(0, :foo, 2))
|
137
|
-
eql(Rearmed.dig(array, 1, :test), 'thing')
|
138
|
-
assert_nil(Rearmed.dig(array, 1, :bar))
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_hash
|
142
|
-
hash = {foo: 'foo', bar: 'bar', other: 'other'}
|
143
|
-
eql(hash.only(:foo, :bar), {foo: 'foo', bar: 'bar'})
|
144
|
-
|
145
|
-
hash = {foo: 'foo', bar: 'bar', other: 'other'}
|
146
|
-
hash.only!(:foo, :bar)
|
147
|
-
eql(hash, {foo: 'foo', bar: 'bar'})
|
148
|
-
|
149
|
-
hash = {foo: 'foo', bar: 'bar', other: 'other'}
|
150
|
-
eql(Rearmed.hash_only(hash, :foo, :bar), {foo: 'foo', bar: 'bar'})
|
151
|
-
|
152
|
-
hash = {foo: nil, bar: nil, other: 'other'}
|
153
|
-
eql(hash.compact, {other: 'other'})
|
154
|
-
eql(Rearmed.hash_compact(hash), {other: 'other'})
|
155
|
-
|
156
|
-
hash = {foo: nil, bar: nil, other: 'other'}
|
157
|
-
hash.compact!
|
158
|
-
eql(hash, {other: 'other'})
|
159
|
-
|
160
|
-
hash = {foo: :bar, bar: :foo}
|
161
|
-
eql(hash.join, "foo: bar, bar: foo")
|
162
|
-
eql(hash.join('___'), "foo: bar___bar: foo")
|
163
|
-
eql(hash.join{|k,v| v}, "bar, foo")
|
164
|
-
eql(hash.join('___'){|k,v| v}, "bar___foo")
|
165
|
-
eql(Rearmed.hash_join(hash), "foo: bar, bar: foo")
|
166
|
-
eql(Rearmed.hash_join(hash, '___'), "foo: bar___bar: foo")
|
167
|
-
eql(Rearmed.hash_join(hash){|k,v| v}, "bar, foo")
|
168
|
-
eql(Rearmed.hash_join(hash, '___'){|k,v| v}, "bar___foo")
|
169
|
-
|
170
|
-
hash = {foo: :bar, bar: 'foo'}
|
171
|
-
struct = hash.to_struct
|
172
|
-
assert(struct.is_a?(Struct))
|
173
|
-
eql(struct.foo, :bar)
|
174
|
-
eql(struct.bar, 'foo')
|
175
|
-
|
176
|
-
struct = Rearmed.hash_to_struct(hash)
|
177
|
-
assert(struct.is_a?(Struct))
|
178
|
-
eql(struct.foo, :bar)
|
179
|
-
eql(struct.bar, 'foo')
|
180
|
-
|
181
|
-
hash = {a: {foo: ['bar']}, b: {c: 'c'}}
|
182
|
-
eql(hash.dig(:a, :foo, 0), 'bar')
|
183
|
-
eql(Rearmed.dig(hash, :b, :c), 'c')
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_object
|
187
|
-
str = 'test'
|
188
|
-
eql(str.not_nil?, true)
|
189
|
-
|
190
|
-
str = nil
|
191
|
-
eql(str.not_nil?, false)
|
192
|
-
|
193
|
-
str = false
|
194
|
-
eql(str.not_nil?, true)
|
195
|
-
|
196
|
-
str = 'test'
|
197
|
-
eql(str.in?(['test','abc']), true)
|
198
|
-
|
199
|
-
str = 'test'
|
200
|
-
eql(str.in?(['abc','def']), false)
|
201
|
-
|
202
|
-
str = 'test'
|
203
|
-
eql(str.in?('test','abc'), true)
|
204
|
-
|
205
|
-
str = 'test'
|
206
|
-
eql(str.in?('abc','def'), false)
|
207
|
-
|
208
|
-
str = 'test'
|
209
|
-
eql(str.in?('a test string'), true)
|
210
|
-
|
211
|
-
str = 'test'
|
212
|
-
eql(str.in?('a real string'), false)
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|