appydays 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/appydays/loggable/sequel_logger.rb +6 -2
- data/lib/appydays/loggable/sidekiq_job_logger.rb +10 -4
- data/lib/appydays/spec_helpers.rb +81 -24
- data/lib/appydays/version.rb +1 -1
- metadata +37 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b299f65c7ee3543f139a2e705e1847144d49955dcab5fbe5c37a76fc9bb63a
|
4
|
+
data.tar.gz: 17179300f27c0f293a9ba7e1d106e87050c4ce1b73a99b69be572d51c07f982d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35fa1b0bc6933d9b76d509e0321e36a1281983694aa0f0362d17420ec7cab8878daf9e4676312948e70db58bc976d2c166f5e7b6191b7f1b357fffb41f763ede
|
7
|
+
data.tar.gz: b1efd166a9f7d28bc3c3a1bb4bcaa6703cb4fa2a1ae983aa57675c100a786354975ed8ee38a67b8a27f1374c068dd2ec08176d46e525f900b99e94d3e089bf1f
|
@@ -17,7 +17,11 @@ class Sequel::Database
|
|
17
17
|
log_each(
|
18
18
|
:info,
|
19
19
|
proc { args ? "#{message}; #{args.inspect}" : message },
|
20
|
-
proc
|
20
|
+
proc do
|
21
|
+
o = {message: message}
|
22
|
+
o[:args] = args unless args.nil?
|
23
|
+
["sequel_log", o]
|
24
|
+
end,
|
21
25
|
)
|
22
26
|
end
|
23
27
|
|
@@ -28,7 +32,7 @@ class Sequel::Database
|
|
28
32
|
log_each(
|
29
33
|
lwd && (duration >= lwd) ? :warn : sql_log_level,
|
30
34
|
proc { "(#{'%0.6fs' % duration}) #{message}" },
|
31
|
-
proc { ["sequel_query", {duration: duration, query: message}] },
|
35
|
+
proc { ["sequel_query", {duration: duration * 1000, query: message}] },
|
32
36
|
)
|
33
37
|
end
|
34
38
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "sidekiq"
|
4
|
+
require "sidekiq/version"
|
4
5
|
require "sidekiq/job_logger"
|
5
|
-
require "sidekiq/util"
|
6
6
|
|
7
7
|
require "appydays/loggable"
|
8
8
|
require "appydays/configurable"
|
@@ -10,7 +10,13 @@ require "appydays/configurable"
|
|
10
10
|
class Appydays::Loggable::SidekiqJobLogger < Sidekiq::JobLogger
|
11
11
|
include Appydays::Configurable
|
12
12
|
include Appydays::Loggable
|
13
|
-
|
13
|
+
begin
|
14
|
+
require "sidekiq/util"
|
15
|
+
include Sidekiq::Util
|
16
|
+
rescue LoadError
|
17
|
+
require "sidekiq/component"
|
18
|
+
include Sidekiq::Component
|
19
|
+
end
|
14
20
|
|
15
21
|
Sidekiq.logger = self.logger
|
16
22
|
|
@@ -37,10 +43,10 @@ class Appydays::Loggable::SidekiqJobLogger < Sidekiq::JobLogger
|
|
37
43
|
yield
|
38
44
|
duration = self.elapsed(start)
|
39
45
|
log_method = duration >= self.slow_job_seconds ? :warn : :info
|
40
|
-
self.logger.send(log_method, "job_done", duration: duration)
|
46
|
+
self.logger.send(log_method, "job_done", duration: duration * 1000)
|
41
47
|
rescue StandardError
|
42
48
|
# Do not log the error since it is probably a sidekiq retry error
|
43
|
-
self.logger.error("job_fail", duration: self.elapsed(start))
|
49
|
+
self.logger.error("job_fail", duration: self.elapsed(start) * 1000)
|
44
50
|
raise
|
45
51
|
end
|
46
52
|
|
@@ -25,6 +25,7 @@ module Appydays::SpecHelpers
|
|
25
25
|
|
26
26
|
def matches?(target)
|
27
27
|
@target = target
|
28
|
+
@target = @target.lines if @target.is_a?(String)
|
28
29
|
return @target.find do |obj|
|
29
30
|
obj.to_s.match(@regexp)
|
30
31
|
end
|
@@ -43,9 +44,9 @@ module Appydays::SpecHelpers
|
|
43
44
|
alias failure_message_for_should_not failure_message_when_negated
|
44
45
|
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
# RSpec matcher -- set up the expectation that the lefthand side
|
48
|
+
# is Enumerable, and that at least one of the objects yielded
|
49
|
+
# while iterating matches +regexp+ when converted to a String.
|
49
50
|
module_function def have_a_line_matching(regexp)
|
50
51
|
return HaveALineMatching.new(regexp)
|
51
52
|
end
|
@@ -54,39 +55,70 @@ module Appydays::SpecHelpers
|
|
54
55
|
return RSpec::Matchers::BuiltIn::HaveAttributes.new(length: x)
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
58
|
+
class MatchTime
|
59
|
+
def initialize(expected)
|
60
|
+
@expected = expected
|
61
|
+
if expected == :now
|
62
|
+
@expected_t = Time.now
|
63
|
+
@tolerance = 5
|
64
|
+
else
|
65
|
+
@expected_t = self.time(expected)
|
66
|
+
@tolerance = 0.001
|
67
|
+
end
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
def time(s)
|
71
|
+
return nil if s.nil?
|
72
|
+
return Time.parse(s) if s.is_a?(String)
|
73
|
+
return s.to_time
|
74
|
+
end
|
75
|
+
|
76
|
+
def matches?(actual)
|
77
|
+
@actual_t = self.time(actual)
|
78
|
+
@actual_t = self.change_tz(@actual_t, @expected_t.zone) if @actual_t
|
79
|
+
return RSpec::Matchers::BuiltIn::BeWithin.new(@tolerance).of(@expected_t).matches?(@actual_t)
|
71
80
|
end
|
72
81
|
|
73
|
-
|
82
|
+
protected def change_tz(t, zone)
|
83
|
+
return t.change(zone: zone) if t.respond_to?(:change)
|
84
|
+
prev_tz = ENV.fetch("TZ", nil)
|
85
|
+
begin
|
86
|
+
ENV["TZ"] = zone
|
87
|
+
return Time.at(t.to_f)
|
88
|
+
ensure
|
89
|
+
ENV["TZ"] = prev_tz
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def within(tolerance)
|
74
94
|
@tolerance = tolerance
|
95
|
+
return self
|
75
96
|
end
|
76
97
|
|
77
|
-
def
|
78
|
-
return
|
79
|
-
return s.to_time
|
98
|
+
def failure_message
|
99
|
+
return "expected %s to be within %s of %s" % [@actual_t, @tolerance, @expected_t]
|
80
100
|
end
|
81
101
|
end
|
82
102
|
|
103
|
+
# Matcher that will compare a string or time expected against a string or time actual,
|
104
|
+
# within a tolerance (default to 1 millisecond).
|
105
|
+
#
|
106
|
+
# Use match_time(:now) to automatically `match_time(Time.now).within(5.seconds)`.
|
107
|
+
#
|
108
|
+
# expect(last_response).to have_json_body.that_includes(
|
109
|
+
# closes_at: match_time('2025-12-01T00:00:00.000+00:00').within(1.second))
|
110
|
+
#
|
111
|
+
def match_time(expected)
|
112
|
+
return MatchTime.new(expected)
|
113
|
+
end
|
114
|
+
|
83
115
|
# Matcher that will compare a string or Money expected against a string or Money actual.
|
84
116
|
#
|
85
117
|
# expect(order.total).to cost('$25')
|
86
118
|
#
|
87
|
-
RSpec::Matchers.define(:cost) do |expected|
|
119
|
+
RSpec::Matchers.define(:cost) do |expected, currency|
|
88
120
|
match do |actual|
|
89
|
-
@base = RSpec::Matchers::BuiltIn::Eq.new(self.money(expected))
|
121
|
+
@base = RSpec::Matchers::BuiltIn::Eq.new(self.money(expected, currency))
|
90
122
|
@base.matches?(self.money(actual))
|
91
123
|
end
|
92
124
|
|
@@ -94,12 +126,37 @@ module Appydays::SpecHelpers
|
|
94
126
|
@base.failure_message
|
95
127
|
end
|
96
128
|
|
97
|
-
def money(s)
|
98
|
-
|
129
|
+
def money(s, currency=nil)
|
130
|
+
if (m = self.tryparse(s, currency))
|
131
|
+
return m
|
132
|
+
end
|
99
133
|
return s if s.is_a?(Money)
|
100
|
-
return Money.new(s) if s.is_a?(Integer)
|
134
|
+
return Money.new(s, currency) if s.is_a?(Integer)
|
101
135
|
return Money.new(s[:cents], s[:currency]) if s.respond_to?(:key?) && s.key?(:cents) && s.key?(:currency)
|
102
136
|
raise "#{s} type #{s.class.name} not convertable to Money (add support or use supported type)"
|
103
137
|
end
|
138
|
+
|
139
|
+
def tryparse(s, currency)
|
140
|
+
# We need to capture some global settings while we parse, and set them back after.
|
141
|
+
orig_default = Money.instance_variable_get(:@default_currency)
|
142
|
+
orig_assume = Monetize.assume_from_symbol
|
143
|
+
return nil unless s.is_a?(String)
|
144
|
+
# See https://github.com/RubyMoney/monetize/issues/161
|
145
|
+
# To get around this, need to use a valid custom currency
|
146
|
+
begin
|
147
|
+
Money::Currency.new("APPYDAYS")
|
148
|
+
rescue Money::Currency::UnknownCurrency
|
149
|
+
Money::Currency.register(iso_code: "APPYDAYS", subunit_to_unit: 1)
|
150
|
+
end
|
151
|
+
Money.default_currency = currency || orig_default || "APPYDAYS"
|
152
|
+
Monetize.assume_from_symbol = true
|
153
|
+
m = Monetize.parse!(s)
|
154
|
+
return m unless m.currency == "APPYDAYS"
|
155
|
+
raise Money::Currency::UnknownCurrency,
|
156
|
+
"Could not parse currency from '#{s}'. It needs a symbol, or set default_currency."
|
157
|
+
ensure
|
158
|
+
Money.default_currency = orig_default
|
159
|
+
Monetize.assume_from_symbol = orig_assume
|
160
|
+
end
|
104
161
|
end
|
105
162
|
end
|
data/lib/appydays/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appydays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lithic Tech
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: monetize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: money
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '6.0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rack
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -181,8 +209,8 @@ dependencies:
|
|
181
209
|
description: 'appydays provides support for env-based configuration, and common structured
|
182
210
|
logging capabilities
|
183
211
|
|
184
|
-
|
185
|
-
email:
|
212
|
+
'
|
213
|
+
email:
|
186
214
|
executables: []
|
187
215
|
extensions: []
|
188
216
|
extra_rdoc_files: []
|
@@ -199,8 +227,9 @@ files:
|
|
199
227
|
homepage: https://github.com/lithictech/appydays
|
200
228
|
licenses:
|
201
229
|
- MIT
|
202
|
-
metadata:
|
203
|
-
|
230
|
+
metadata:
|
231
|
+
rubygems_mfa_required: 'true'
|
232
|
+
post_install_message:
|
204
233
|
rdoc_options: []
|
205
234
|
require_paths:
|
206
235
|
- lib
|
@@ -216,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
245
|
version: '0'
|
217
246
|
requirements: []
|
218
247
|
rubygems_version: 3.1.6
|
219
|
-
signing_key:
|
248
|
+
signing_key:
|
220
249
|
specification_version: 4
|
221
250
|
summary: Provides support for env-based configuration, and common structured logging
|
222
251
|
capabilities
|