json_statham 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +16 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +153 -1
- data/README.md +72 -7
- data/lib/generators/json_statham/USAGE +8 -0
- data/lib/generators/json_statham/install_generator.rb +13 -0
- data/lib/generators/json_statham/templates/json_statham.rb.tt +7 -0
- data/lib/json_statham/config.rb +9 -9
- data/lib/json_statham/logger.rb +58 -0
- data/lib/json_statham/parser.rb +2 -1
- data/lib/json_statham/railtie.rb +9 -0
- data/lib/json_statham/result.rb +28 -7
- data/lib/json_statham/version.rb +1 -1
- data/lib/json_statham.rb +2 -0
- data/lib/tasks/json_statham_tasks.rake +9 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8086da405fa7309573448af4957f39283b821b40419269126c81e00d653aea0
|
4
|
+
data.tar.gz: 75e2b6b518a10367b81c28cc358e855aad94e603ca251a7dca3201df86e9a7ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aa2487a098ad2ad6dee3ab47a7257c866b41ebdc3d676f09a99f6c86c43ff82180208e63be708aeb471694c1e82d750e02dcd685a91e17121c3728693cf659b
|
7
|
+
data.tar.gz: b548f34e21f7963ce62c4f957740fc312129c08e74fd2f8e7b552a1430a7be782e63017e00e3bd783b2c4db37e9ec9ed4c3d79d460351fb3b90e14aee76657c1
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
### [0.1.3] - 2023-02-18
|
4
|
+
|
5
|
+
* Features:
|
6
|
+
* Add Rails support.
|
7
|
+
|
8
|
+
### [0.1.2] - 2023-02-07
|
9
|
+
|
10
|
+
* Features:
|
11
|
+
* Add `raise_ratio` to config.
|
12
|
+
|
13
|
+
* Deprecations:
|
14
|
+
* Remove `logger` from config.
|
15
|
+
|
16
|
+
### [0.1.1] - 2023-02-07
|
17
|
+
yanked
|
18
|
+
|
3
19
|
### [0.1.0] - 2023-02-06
|
4
20
|
|
5
21
|
- Initial release
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,149 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
json_statham (0.1.
|
4
|
+
json_statham (0.1.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
actioncable (6.1.7.1)
|
10
|
+
actionpack (= 6.1.7.1)
|
11
|
+
activesupport (= 6.1.7.1)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (>= 0.6.1)
|
14
|
+
actionmailbox (6.1.7.1)
|
15
|
+
actionpack (= 6.1.7.1)
|
16
|
+
activejob (= 6.1.7.1)
|
17
|
+
activerecord (= 6.1.7.1)
|
18
|
+
activestorage (= 6.1.7.1)
|
19
|
+
activesupport (= 6.1.7.1)
|
20
|
+
mail (>= 2.7.1)
|
21
|
+
actionmailer (6.1.7.1)
|
22
|
+
actionpack (= 6.1.7.1)
|
23
|
+
actionview (= 6.1.7.1)
|
24
|
+
activejob (= 6.1.7.1)
|
25
|
+
activesupport (= 6.1.7.1)
|
26
|
+
mail (~> 2.5, >= 2.5.4)
|
27
|
+
rails-dom-testing (~> 2.0)
|
28
|
+
actionpack (6.1.7.1)
|
29
|
+
actionview (= 6.1.7.1)
|
30
|
+
activesupport (= 6.1.7.1)
|
31
|
+
rack (~> 2.0, >= 2.0.9)
|
32
|
+
rack-test (>= 0.6.3)
|
33
|
+
rails-dom-testing (~> 2.0)
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
35
|
+
actiontext (6.1.7.1)
|
36
|
+
actionpack (= 6.1.7.1)
|
37
|
+
activerecord (= 6.1.7.1)
|
38
|
+
activestorage (= 6.1.7.1)
|
39
|
+
activesupport (= 6.1.7.1)
|
40
|
+
nokogiri (>= 1.8.5)
|
41
|
+
actionview (6.1.7.1)
|
42
|
+
activesupport (= 6.1.7.1)
|
43
|
+
builder (~> 3.1)
|
44
|
+
erubi (~> 1.4)
|
45
|
+
rails-dom-testing (~> 2.0)
|
46
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
47
|
+
activejob (6.1.7.1)
|
48
|
+
activesupport (= 6.1.7.1)
|
49
|
+
globalid (>= 0.3.6)
|
50
|
+
activemodel (6.1.7.1)
|
51
|
+
activesupport (= 6.1.7.1)
|
52
|
+
activerecord (6.1.7.1)
|
53
|
+
activemodel (= 6.1.7.1)
|
54
|
+
activesupport (= 6.1.7.1)
|
55
|
+
activestorage (6.1.7.1)
|
56
|
+
actionpack (= 6.1.7.1)
|
57
|
+
activejob (= 6.1.7.1)
|
58
|
+
activerecord (= 6.1.7.1)
|
59
|
+
activesupport (= 6.1.7.1)
|
60
|
+
marcel (~> 1.0)
|
61
|
+
mini_mime (>= 1.1.0)
|
62
|
+
activesupport (6.1.7.1)
|
63
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
64
|
+
i18n (>= 1.6, < 2)
|
65
|
+
minitest (>= 5.1)
|
66
|
+
tzinfo (~> 2.0)
|
67
|
+
zeitwerk (~> 2.3)
|
9
68
|
ast (2.4.2)
|
69
|
+
builder (3.2.4)
|
10
70
|
coderay (1.1.3)
|
71
|
+
concurrent-ruby (1.2.0)
|
72
|
+
crass (1.0.6)
|
73
|
+
date (3.3.3)
|
11
74
|
diff-lcs (1.5.0)
|
12
75
|
docile (1.4.0)
|
76
|
+
erubi (1.12.0)
|
77
|
+
generator_spec (0.9.4)
|
78
|
+
activesupport (>= 3.0.0)
|
79
|
+
railties (>= 3.0.0)
|
80
|
+
globalid (1.1.0)
|
81
|
+
activesupport (>= 5.0)
|
82
|
+
i18n (1.12.0)
|
83
|
+
concurrent-ruby (~> 1.0)
|
13
84
|
json (2.6.3)
|
85
|
+
loofah (2.19.1)
|
86
|
+
crass (~> 1.0.2)
|
87
|
+
nokogiri (>= 1.5.9)
|
88
|
+
mail (2.8.1)
|
89
|
+
mini_mime (>= 0.1.1)
|
90
|
+
net-imap
|
91
|
+
net-pop
|
92
|
+
net-smtp
|
93
|
+
marcel (1.0.2)
|
14
94
|
method_source (1.0.0)
|
95
|
+
mini_mime (1.1.2)
|
96
|
+
minitest (5.17.0)
|
97
|
+
net-imap (0.3.4)
|
98
|
+
date
|
99
|
+
net-protocol
|
100
|
+
net-pop (0.1.2)
|
101
|
+
net-protocol
|
102
|
+
net-protocol (0.2.1)
|
103
|
+
timeout
|
104
|
+
net-smtp (0.3.3)
|
105
|
+
net-protocol
|
106
|
+
nio4r (2.5.8)
|
107
|
+
nokogiri (1.14.1-arm64-darwin)
|
108
|
+
racc (~> 1.4)
|
109
|
+
nokogiri (1.14.1-x86_64-linux)
|
110
|
+
racc (~> 1.4)
|
15
111
|
parallel (1.22.1)
|
16
112
|
parser (3.2.0.0)
|
17
113
|
ast (~> 2.4.1)
|
18
114
|
pry (0.14.2)
|
19
115
|
coderay (~> 1.1)
|
20
116
|
method_source (~> 1.0)
|
117
|
+
racc (1.6.2)
|
118
|
+
rack (2.2.6.2)
|
119
|
+
rack-test (2.0.2)
|
120
|
+
rack (>= 1.3)
|
121
|
+
rails (6.1.7.1)
|
122
|
+
actioncable (= 6.1.7.1)
|
123
|
+
actionmailbox (= 6.1.7.1)
|
124
|
+
actionmailer (= 6.1.7.1)
|
125
|
+
actionpack (= 6.1.7.1)
|
126
|
+
actiontext (= 6.1.7.1)
|
127
|
+
actionview (= 6.1.7.1)
|
128
|
+
activejob (= 6.1.7.1)
|
129
|
+
activemodel (= 6.1.7.1)
|
130
|
+
activerecord (= 6.1.7.1)
|
131
|
+
activestorage (= 6.1.7.1)
|
132
|
+
activesupport (= 6.1.7.1)
|
133
|
+
bundler (>= 1.15.0)
|
134
|
+
railties (= 6.1.7.1)
|
135
|
+
sprockets-rails (>= 2.0.0)
|
136
|
+
rails-dom-testing (2.0.3)
|
137
|
+
activesupport (>= 4.2.0)
|
138
|
+
nokogiri (>= 1.6)
|
139
|
+
rails-html-sanitizer (1.5.0)
|
140
|
+
loofah (~> 2.19, >= 2.19.1)
|
141
|
+
railties (6.1.7.1)
|
142
|
+
actionpack (= 6.1.7.1)
|
143
|
+
activesupport (= 6.1.7.1)
|
144
|
+
method_source
|
145
|
+
rake (>= 12.2)
|
146
|
+
thor (~> 1.0)
|
21
147
|
rainbow (3.1.1)
|
22
148
|
rake (13.0.6)
|
23
149
|
regexp_parser (2.6.2)
|
@@ -34,6 +160,14 @@ GEM
|
|
34
160
|
rspec-mocks (3.12.3)
|
35
161
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
162
|
rspec-support (~> 3.12.0)
|
163
|
+
rspec-rails (6.0.1)
|
164
|
+
actionpack (>= 6.1)
|
165
|
+
activesupport (>= 6.1)
|
166
|
+
railties (>= 6.1)
|
167
|
+
rspec-core (~> 3.11)
|
168
|
+
rspec-expectations (~> 3.11)
|
169
|
+
rspec-mocks (~> 3.11)
|
170
|
+
rspec-support (~> 3.11)
|
37
171
|
rspec-support (3.12.0)
|
38
172
|
rubocop (1.44.1)
|
39
173
|
json (~> 2.3)
|
@@ -54,17 +188,35 @@ GEM
|
|
54
188
|
simplecov_json_formatter (~> 0.1)
|
55
189
|
simplecov-html (0.12.3)
|
56
190
|
simplecov_json_formatter (0.1.4)
|
191
|
+
sprockets (4.2.0)
|
192
|
+
concurrent-ruby (~> 1.0)
|
193
|
+
rack (>= 2.2.4, < 4)
|
194
|
+
sprockets-rails (3.4.2)
|
195
|
+
actionpack (>= 5.2)
|
196
|
+
activesupport (>= 5.2)
|
197
|
+
sprockets (>= 3.0.0)
|
198
|
+
thor (1.2.1)
|
199
|
+
timeout (0.3.1)
|
200
|
+
tzinfo (2.0.6)
|
201
|
+
concurrent-ruby (~> 1.0)
|
57
202
|
unicode-display_width (2.4.2)
|
203
|
+
websocket-driver (0.7.5)
|
204
|
+
websocket-extensions (>= 0.1.0)
|
205
|
+
websocket-extensions (0.1.5)
|
206
|
+
zeitwerk (2.6.6)
|
58
207
|
|
59
208
|
PLATFORMS
|
60
209
|
arm64-darwin-21
|
61
210
|
x86_64-linux
|
62
211
|
|
63
212
|
DEPENDENCIES
|
213
|
+
generator_spec
|
64
214
|
json_statham!
|
65
215
|
pry (~> 0.14.2)
|
216
|
+
rails (~> 6.1.7.1)
|
66
217
|
rake (~> 13.0)
|
67
218
|
rspec (~> 3.0)
|
219
|
+
rspec-rails
|
68
220
|
rubocop (~> 1.21)
|
69
221
|
simplecov (~> 0.22.0)
|
70
222
|
|
data/README.md
CHANGED
@@ -69,19 +69,22 @@ Available configuration attributes:
|
|
69
69
|
JsonStatham.configure do |config|
|
70
70
|
config.schemas_path = "schemas"
|
71
71
|
config.store_schema = true
|
72
|
-
config.
|
72
|
+
config.raise_ratio = 10
|
73
73
|
end
|
74
74
|
```
|
75
75
|
|
76
76
|
*Required attributes:*
|
77
77
|
|
78
|
-
- `schemas_path`
|
78
|
+
- `schemas_path` String.
|
79
|
+
The path where the json files will be read and created.
|
79
80
|
|
80
81
|
*Optional attributes:*
|
81
82
|
|
82
|
-
- `store_schema`
|
83
|
+
- `store_schema` Boolean, default to `false`.
|
84
|
+
It allows to create or not a new file.
|
83
85
|
|
84
|
-
- `
|
86
|
+
- `raise_ratio` Integer, default to `nil`.
|
87
|
+
The ratio of increase in execution time. This allows to raise an error when the execution of the block takes longer than expected.
|
85
88
|
|
86
89
|
## Example using RSpec
|
87
90
|
|
@@ -114,7 +117,7 @@ You can thenuse stathamnize with different traits in your spec file.
|
|
114
117
|
```ruby
|
115
118
|
RSpec.describe UserSerializer do
|
116
119
|
describe "Schema" do
|
117
|
-
subject { stathamnize(trait) { serializer }
|
120
|
+
subject { stathamnize(trait) { serializer } }
|
118
121
|
|
119
122
|
context "Given a valid user" do
|
120
123
|
let(:serializer) { UserSerializer.new(user).to_h }
|
@@ -122,7 +125,7 @@ RSpec.describe UserSerializer do
|
|
122
125
|
let(:user) { create(:user, :valid) }
|
123
126
|
|
124
127
|
it "has a valid schema" do
|
125
|
-
expect(subject).to eq(true)
|
128
|
+
expect(subject.success?).to eq(true)
|
126
129
|
end
|
127
130
|
end
|
128
131
|
|
@@ -132,13 +135,75 @@ RSpec.describe UserSerializer do
|
|
132
135
|
let(:user) { create(:user, :invalid) }
|
133
136
|
|
134
137
|
it "has a valid schema" do
|
135
|
-
expect(subject).to eq(true)
|
138
|
+
expect(subject.success?).to eq(true)
|
136
139
|
end
|
137
140
|
end
|
138
141
|
end
|
139
142
|
end
|
140
143
|
```
|
141
144
|
|
145
|
+
Or you can create a shared example
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
RSpec.shared_examples 'a serializer' do |schema_name|
|
149
|
+
describe "#as_json" do
|
150
|
+
subject do
|
151
|
+
stathamnize("#{serializer_path}/#{schema_name}") do
|
152
|
+
described_class.new(record).as_json
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
let(:serializer_path) { described_class.name.underscore }
|
157
|
+
|
158
|
+
it "returns #{schema_name} object as json" do
|
159
|
+
expect(subject.success?).to eq(true)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
```
|
164
|
+
|
165
|
+
Then you can use it inside your specs
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
require "spec_helper"
|
169
|
+
|
170
|
+
RSpec.describe FooSerializer do
|
171
|
+
it_behaves_like "a serializer", "foo" do
|
172
|
+
let(:record) { create(:foo) }
|
173
|
+
end
|
174
|
+
|
175
|
+
FactoryBot.factories[:foo].definition.defined_traits.map(&:name).each do |trait|
|
176
|
+
it_behaves_like "a serializer", trait do
|
177
|
+
let(:record) { create(:foo, trait) }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
## Rails
|
184
|
+
|
185
|
+
Run the generator:
|
186
|
+
|
187
|
+
$ rails g json_statham:install
|
188
|
+
|
189
|
+
This will create a new initializer at **config/initializers/json_statham.rb**.
|
190
|
+
After running your tests to generate the json files you can now run `rails json_statham`.
|
191
|
+
|
192
|
+
$ rails json_statham
|
193
|
+
|
194
|
+
This will show you a list of your json files ordered by duration.
|
195
|
+
|
196
|
+
```
|
197
|
+
+------------------------------------------------------------------------+-----------------------+
|
198
|
+
| File path | Duration |
|
199
|
+
+------------------------------------------------------------------------+-----------------------+
|
200
|
+
| schemas/user_serializer/valid_user.json | 0.5460864380002022 |
|
201
|
+
| schemas/user_serializer/invalid_user.json | 0.2532647902998724 |
|
202
|
+
| schemas/post_serializer/published.json | 0.2153625870094402 |
|
203
|
+
| schemas/post_serializer/draft.json | 0.1238838530000066 |
|
204
|
+
+------------------------------------------------------------------------+-----------------------+
|
205
|
+
```
|
206
|
+
|
142
207
|
## Development
|
143
208
|
|
144
209
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
|
5
|
+
module JsonStatham
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
def add_initializer
|
10
|
+
template "json_statham.rb", "config/initializers/json_statham.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/json_statham/config.rb
CHANGED
@@ -2,26 +2,26 @@
|
|
2
2
|
|
3
3
|
module JsonStatham
|
4
4
|
class Config
|
5
|
-
attr_reader :schemas_path, :store_schema, :
|
5
|
+
attr_reader :schemas_path, :store_schema, :raise_ratio
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@schemas_path = nil
|
9
9
|
@store_schema = nil
|
10
|
-
@
|
10
|
+
@raise_ratio = nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def store_schema?
|
14
14
|
!!store_schema
|
15
15
|
end
|
16
16
|
|
17
|
-
def logger?
|
18
|
-
!!logger
|
19
|
-
end
|
20
|
-
|
21
17
|
def schemas_path_present?
|
22
18
|
!!schemas_path
|
23
19
|
end
|
24
20
|
|
21
|
+
def raise_on_failure?
|
22
|
+
!!raise_ratio
|
23
|
+
end
|
24
|
+
|
25
25
|
def schemas_path=(value)
|
26
26
|
Validation.check_object_class(value, [String])
|
27
27
|
|
@@ -34,10 +34,10 @@ module JsonStatham
|
|
34
34
|
@store_schema = value
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
Validation.check_object_class(value, [
|
37
|
+
def raise_ratio=(value)
|
38
|
+
Validation.check_object_class(value, [Integer])
|
39
39
|
|
40
|
-
@
|
40
|
+
@raise_ratio = value
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JsonStatham
|
4
|
+
class Logger
|
5
|
+
COL_LABELS = { file_path: "File path", duration: "Duration" }.freeze
|
6
|
+
|
7
|
+
def config
|
8
|
+
@_config = JsonStatham.config
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
log_header
|
13
|
+
log_values
|
14
|
+
log_divider
|
15
|
+
end
|
16
|
+
|
17
|
+
def columns
|
18
|
+
@_columns ||= COL_LABELS.each_with_object({}) do |(col, label), hash|
|
19
|
+
hash[col] = { label: label, width: [max_val(col), label.size].max }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def max_val(col)
|
24
|
+
values.map { |val| val[col].to_s.size }.max
|
25
|
+
end
|
26
|
+
|
27
|
+
def values
|
28
|
+
@_values ||= Dir["#{config.schemas_path}/**/*.json"].map do |file_path|
|
29
|
+
duration = JSON.parse(File.read(file_path))["duration"]
|
30
|
+
|
31
|
+
{ file_path: file_path, duration: duration }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def log_values
|
38
|
+
values
|
39
|
+
.sort_by { |hash| hash[:duration] }
|
40
|
+
.reverse
|
41
|
+
.each { |hash| log_schema(hash) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def log_header
|
45
|
+
log_divider
|
46
|
+
puts "| #{columns.map { |_, col| col[:label].ljust(col[:width]) }.join(' | ')} |"
|
47
|
+
log_divider
|
48
|
+
end
|
49
|
+
|
50
|
+
def log_divider
|
51
|
+
puts "+-#{columns.map { |_, col| '-' * col[:width] }.join('-+-')}-+"
|
52
|
+
end
|
53
|
+
|
54
|
+
def log_schema(hash)
|
55
|
+
puts "| #{hash.keys.map { |key| hash[key].to_s.ljust(columns[key][:width]) }.join(' | ')} |"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/json_statham/parser.rb
CHANGED
@@ -18,10 +18,11 @@ module JsonStatham
|
|
18
18
|
def call
|
19
19
|
@reader = JsonStatham::Requests::Reader.call(self)
|
20
20
|
@observer = JsonStatham::Requests::Observer.call(self)
|
21
|
+
result = JsonStatham::Result.call(self)
|
21
22
|
|
22
23
|
store_current_schema
|
23
24
|
|
24
|
-
|
25
|
+
result
|
25
26
|
end
|
26
27
|
|
27
28
|
def store_current_schema
|
data/lib/json_statham/result.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module JsonStatham
|
4
|
+
class InvalidRatioError < StandardError
|
5
|
+
end
|
6
|
+
|
4
7
|
class Result
|
5
|
-
attr_reader :parser
|
8
|
+
attr_reader :parser, :config
|
6
9
|
|
7
10
|
def self.call(parser)
|
8
11
|
new(parser).call
|
@@ -12,15 +15,11 @@ module JsonStatham
|
|
12
15
|
Validation.check_object_class(parser, [JsonStatham::Parser])
|
13
16
|
|
14
17
|
@parser = parser
|
18
|
+
@config = JsonStatham.config
|
15
19
|
end
|
16
20
|
|
17
21
|
def call
|
18
|
-
|
19
|
-
puts <<-RESULT_MSG
|
20
|
-
Previous duration: #{previous_duration}
|
21
|
-
Current duration: #{current_duration}
|
22
|
-
RESULT_MSG
|
23
|
-
end
|
22
|
+
ensure_valid_ratio
|
24
23
|
|
25
24
|
self
|
26
25
|
end
|
@@ -39,6 +38,10 @@ module JsonStatham
|
|
39
38
|
parser.previous_duration
|
40
39
|
end
|
41
40
|
|
41
|
+
def previous_duration?
|
42
|
+
!!previous_duration
|
43
|
+
end
|
44
|
+
|
42
45
|
def success?
|
43
46
|
parser.valid?
|
44
47
|
end
|
@@ -46,5 +49,23 @@ module JsonStatham
|
|
46
49
|
def failure?
|
47
50
|
!success?
|
48
51
|
end
|
52
|
+
|
53
|
+
def ratio
|
54
|
+
return 0 unless observed?
|
55
|
+
|
56
|
+
current_duration.fdiv(previous_duration)
|
57
|
+
end
|
58
|
+
|
59
|
+
def raise_ratio
|
60
|
+
config.raise_ratio
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def ensure_valid_ratio
|
66
|
+
return unless config.raise_on_failure? && previous_duration? && ratio > raise_ratio
|
67
|
+
|
68
|
+
raise JsonStatham::InvalidRatioError, "raise_ratio: #{raise_ratio}. current_ratio: #{ratio}"
|
69
|
+
end
|
49
70
|
end
|
50
71
|
end
|
data/lib/json_statham/version.rb
CHANGED
data/lib/json_statham.rb
CHANGED
@@ -4,12 +4,14 @@ require_relative "json_statham/helper"
|
|
4
4
|
require_relative "json_statham/version"
|
5
5
|
require_relative "json_statham/requests"
|
6
6
|
require_relative "json_statham/validation"
|
7
|
+
require_relative "json_statham/railtie" if defined?(Rails::Railtie)
|
7
8
|
|
8
9
|
module JsonStatham
|
9
10
|
autoload :Config, "json_statham/config"
|
10
11
|
autoload :Parser, "json_statham/parser"
|
11
12
|
autoload :Schema, "json_statham/schema"
|
12
13
|
autoload :Result, "json_statham/result"
|
14
|
+
autoload :Logger, "json_statham/logger"
|
13
15
|
|
14
16
|
class << self
|
15
17
|
def configure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_statham
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: JsonStatham allows to check the structure changes in a json
|
14
14
|
email:
|
@@ -27,10 +27,15 @@ files:
|
|
27
27
|
- LICENSE.txt
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
|
+
- lib/generators/json_statham/USAGE
|
31
|
+
- lib/generators/json_statham/install_generator.rb
|
32
|
+
- lib/generators/json_statham/templates/json_statham.rb.tt
|
30
33
|
- lib/json_statham.rb
|
31
34
|
- lib/json_statham/config.rb
|
32
35
|
- lib/json_statham/helper.rb
|
36
|
+
- lib/json_statham/logger.rb
|
33
37
|
- lib/json_statham/parser.rb
|
38
|
+
- lib/json_statham/railtie.rb
|
34
39
|
- lib/json_statham/requests.rb
|
35
40
|
- lib/json_statham/requests/base.rb
|
36
41
|
- lib/json_statham/requests/observer.rb
|
@@ -40,6 +45,7 @@ files:
|
|
40
45
|
- lib/json_statham/schema.rb
|
41
46
|
- lib/json_statham/validation.rb
|
42
47
|
- lib/json_statham/version.rb
|
48
|
+
- lib/tasks/json_statham_tasks.rake
|
43
49
|
- sig/json_statham.rbs
|
44
50
|
homepage: https://github.com/victorauthiat/json_statham
|
45
51
|
licenses:
|
@@ -53,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
59
|
requirements:
|
54
60
|
- - ">="
|
55
61
|
- !ruby/object:Gem::Version
|
56
|
-
version: 2.
|
62
|
+
version: 2.7.0
|
57
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - ">="
|