trick_bag 0.31.0 → 0.32.0
Sign up to get free protection for your applications and to get access to all the features.
- data/RELEASE_NOTES.md +5 -0
- data/lib/trick_bag/enumerables/compound_enumerable.rb +0 -1
- data/lib/trick_bag/formatters/formatters.rb +14 -0
- data/lib/trick_bag/numeric/multi_counter.rb +1 -1
- data/lib/trick_bag/version.rb +1 -1
- data/spec/trick_bag/formatters/formatters_spec.rb +17 -0
- data/spec/trick_bag/meta/classes_spec.rb +20 -69
- data/spec/trick_bag/operators/operators_spec.rb +10 -10
- metadata +2 -2
data/RELEASE_NOTES.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
1
3
|
module TrickBag
|
2
4
|
module Formatters
|
3
5
|
|
@@ -49,6 +51,18 @@ module Formatters
|
|
49
51
|
needs_modifying = string && string.size > 0 && string[-1] != "\n"
|
50
52
|
needs_modifying ? "#{string}\n" : string
|
51
53
|
end
|
54
|
+
|
55
|
+
|
56
|
+
def timestamp(datetime = DateTime.now)
|
57
|
+
datetime.strftime('%Y-%m-%d_%H-%M-%S')
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# Replaces all occurrences of marker with the current date/time in
|
62
|
+
# YYYYMMDD-HHMMSS format.
|
63
|
+
def replace_with_timestamp(string, marker = '*', datetime = DateTime.now)
|
64
|
+
string.gsub(marker, timestamp(datetime))
|
65
|
+
end
|
52
66
|
end
|
53
67
|
end
|
54
68
|
|
data/lib/trick_bag/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
|
3
|
+
require 'date'
|
3
4
|
require 'trick_bag/formatters/formatters'
|
4
5
|
|
5
6
|
module TrickBag
|
@@ -57,5 +58,21 @@ describe Formatters do
|
|
57
58
|
expect(Formatters.end_with_nl(3)).to eq("3\n")
|
58
59
|
end
|
59
60
|
end
|
61
|
+
|
62
|
+
|
63
|
+
context ".replace_with_timestamp" do
|
64
|
+
|
65
|
+
let(:a_date) { DateTime.new(2000, 1, 2, 15, 44, 37) }
|
66
|
+
|
67
|
+
specify "returns the correct string" do
|
68
|
+
s = Formatters.replace_with_timestamp('*', '*', a_date)
|
69
|
+
expect(s).to eq('2000-01-02_15-44-37')
|
70
|
+
#regex = /^\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d$/
|
71
|
+
#puts s
|
72
|
+
#expect(regex === s).to be_true
|
73
|
+
#
|
74
|
+
#
|
75
|
+
end
|
76
|
+
end
|
60
77
|
end
|
61
78
|
end
|
@@ -6,7 +6,7 @@ module Meta
|
|
6
6
|
|
7
7
|
describe Classes do
|
8
8
|
|
9
|
-
after(:each) { Classes.undef_class('ClassPatchTestClass') }
|
9
|
+
after(:each) { Classes.undef_class('ClassPatchTestClass', TrickBag::Meta) }
|
10
10
|
|
11
11
|
|
12
12
|
####################################################### class?
|
@@ -17,7 +17,7 @@ context 'class?' do
|
|
17
17
|
expect(Classes.class?('String')).to be_true
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'should recognize that RUBY_PLATFORM is
|
20
|
+
it 'should recognize that RUBY_PLATFORM is not a class even though it is a defined constant' do
|
21
21
|
expect(Classes.class?('RUBY_PLATFORM')).to be_false
|
22
22
|
end
|
23
23
|
|
@@ -46,30 +46,17 @@ end
|
|
46
46
|
|
47
47
|
context 'private_attr_reader' do
|
48
48
|
|
49
|
-
after(:each) { Classes.undef_class('ClassPatchTestClass') }
|
50
|
-
|
51
49
|
fn_create_class = ->do
|
52
50
|
class ClassPatchTestClass
|
53
|
-
|
54
51
|
extend Classes
|
55
|
-
|
56
52
|
private_attr_reader :foo
|
57
|
-
|
58
|
-
def initialize
|
59
|
-
@foo = 123
|
60
|
-
puts "foo = #{self.foo}"
|
61
|
-
end
|
62
53
|
end
|
63
54
|
end
|
64
55
|
|
65
56
|
|
66
|
-
|
67
|
-
expect(fn_create_class).not_to raise_error
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should be invisible outside the class" do
|
57
|
+
it "should be a private method" do
|
71
58
|
fn_create_class.()
|
72
|
-
expect(
|
59
|
+
expect(ClassPatchTestClass.private_method_defined?(:foo)).to be_true
|
73
60
|
end
|
74
61
|
end
|
75
62
|
|
@@ -80,27 +67,15 @@ end
|
|
80
67
|
|
81
68
|
fn_create_class = ->do
|
82
69
|
class ClassPatchTestClass
|
83
|
-
|
84
70
|
extend Classes
|
85
|
-
|
86
71
|
private_attr_writer :foo
|
87
|
-
|
88
|
-
def initialize
|
89
|
-
self.foo = 123
|
90
|
-
end
|
91
72
|
end
|
92
73
|
end
|
93
74
|
|
94
|
-
|
95
|
-
it "should be visible inside the class" do
|
96
|
-
expect(fn_create_class).not_to raise_error
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should be invisible outside the class" do
|
75
|
+
it "should be a private method" do
|
100
76
|
fn_create_class.()
|
101
|
-
expect(
|
77
|
+
expect(ClassPatchTestClass.private_method_defined?(:foo=)).to be_true
|
102
78
|
end
|
103
|
-
|
104
79
|
end
|
105
80
|
|
106
81
|
####################################################### private_attr_accessor
|
@@ -122,16 +97,11 @@ end
|
|
122
97
|
end
|
123
98
|
|
124
99
|
|
125
|
-
it "should be
|
126
|
-
expect(fn_create_class).not_to raise_error
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should be invisible outside the class" do
|
100
|
+
it "should be private reader and writer" do
|
130
101
|
fn_create_class.()
|
131
|
-
expect(
|
132
|
-
expect(
|
102
|
+
expect(ClassPatchTestClass.private_method_defined?(:foo)).to be_true
|
103
|
+
expect(ClassPatchTestClass.private_method_defined?(:foo=)).to be_true
|
133
104
|
end
|
134
|
-
|
135
105
|
end
|
136
106
|
|
137
107
|
|
@@ -154,56 +124,37 @@ end
|
|
154
124
|
end
|
155
125
|
|
156
126
|
|
157
|
-
it "should be
|
158
|
-
expect(fn_create_class).not_to raise_error
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should be readable outside the class" do
|
127
|
+
it "should be a public reader" do
|
162
128
|
fn_create_class.()
|
163
|
-
expect(
|
129
|
+
expect(ClassPatchTestClass.public_method_defined?(:foo)).to be_true
|
164
130
|
end
|
165
131
|
|
166
|
-
it "should
|
132
|
+
it "should be a private writer" do
|
167
133
|
fn_create_class.()
|
168
|
-
expect(
|
134
|
+
expect(ClassPatchTestClass.private_method_defined?(:foo=)).to be_true
|
169
135
|
end
|
170
136
|
end
|
171
137
|
|
138
|
+
|
172
139
|
context 'attr_access(:private, :none, :foo)' do
|
173
140
|
|
174
141
|
fn_create_class = ->do
|
175
142
|
class ClassPatchTestClass
|
176
|
-
|
177
143
|
extend Classes
|
178
|
-
|
179
144
|
attr_access :private, :none, :foo
|
180
|
-
|
181
|
-
def initialize
|
182
|
-
@foo = 1
|
183
|
-
self.foo
|
184
|
-
end
|
185
145
|
end
|
186
146
|
end
|
187
147
|
|
188
|
-
|
189
|
-
it "should be readable inside the class" do
|
190
|
-
expect(fn_create_class).not_to raise_error
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
it "should not be readable outside the class" do
|
195
|
-
fn_create_class.()
|
196
|
-
expect(->{ ClassPatchTestClass.new.foo }).to raise_error
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should not be readable outside the class" do
|
148
|
+
it "should be a private reader" do
|
200
149
|
fn_create_class.()
|
201
|
-
expect(
|
150
|
+
expect(ClassPatchTestClass.private_method_defined?(:foo)).to be_true
|
202
151
|
end
|
203
152
|
|
204
|
-
it
|
153
|
+
it 'should not contain a writer at all' do
|
205
154
|
fn_create_class.()
|
206
|
-
expect(
|
155
|
+
expect(ClassPatchTestClass.private_method_defined?(:foo=)).to be_false
|
156
|
+
expect(ClassPatchTestClass.protected_method_defined?(:foo=)).to be_false
|
157
|
+
expect(ClassPatchTestClass.public_method_defined?(:foo=)).to be_false
|
207
158
|
end
|
208
159
|
end
|
209
160
|
end
|
@@ -14,20 +14,20 @@ module TrickBag
|
|
14
14
|
expect(->{ Operators.multi_eq(1) }).to raise_error
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
test_return_value = ->(true_or_false, *values) do
|
18
18
|
specify "that #{values.map(&:to_s).join(', ')} returns #{true_or_false}}" do
|
19
|
-
|
19
|
+
expect(Operators.multi_eq(*values)).to eq(true_or_false)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
test_return_value.(true, 12, 12)
|
24
|
+
test_return_value.(false, 0, 12)
|
25
|
+
test_return_value.(true, :foo, :foo, :foo)
|
26
|
+
test_return_value.(false, :bar, :foo, :foo)
|
27
|
+
test_return_value.(false, :foo, :bar, :foo)
|
28
|
+
test_return_value.(false, :foo, :foo, :bar)
|
29
|
+
test_return_value.(true, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7)
|
30
|
+
test_return_value.(false, 7, 7, 7, 7, 7, 9999, 7, 7, 7, 7, 7)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trick_bag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.32.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: vrsn-ie-dnsruby
|