json_statham 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9241e02a36d573851c728c187de5200135c00a07cc50911c14da92447b7da2fb
4
- data.tar.gz: 86bc9cf226cc9229e776413c8953c00a65444ff817faf3d3477d070919d979f2
3
+ metadata.gz: e8086da405fa7309573448af4957f39283b821b40419269126c81e00d653aea0
4
+ data.tar.gz: 75e2b6b518a10367b81c28cc358e855aad94e603ca251a7dca3201df86e9a7ef
5
5
  SHA512:
6
- metadata.gz: cd2fc935a733ea0a3eb9f56f8ef8d8b78339a5e5f768a4cc45a38532cb1ea030a41cf040a84ae4cad8a3f1b2aa1a1816915511f09753e2b20a1d2dd54e743d64
7
- data.tar.gz: 39139005d3b156f53296b0c57607fdc4fc4c718a56dca022186ed773993743c63468ae4d09d2251eb3ebfb6b75ae6bcbe7a6da10da1f30021e9561392ae35074
6
+ metadata.gz: 7aa2487a098ad2ad6dee3ab47a7257c866b41ebdc3d676f09a99f6c86c43ff82180208e63be708aeb471694c1e82d750e02dcd685a91e17121c3728693cf659b
7
+ data.tar.gz: b548f34e21f7963ce62c4f957740fc312129c08e74fd2f8e7b552a1430a7be782e63017e00e3bd783b2c4db37e9ec9ed4c3d79d460351fb3b90e14aee76657c1
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7
3
3
  NewCops: enable
4
4
  SuggestExtensions: false
5
5
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Changelog
2
2
 
3
+ ### [0.1.3] - 2023-02-18
4
+
5
+ * Features:
6
+ * Add Rails support.
7
+
3
8
  ### [0.1.2] - 2023-02-07
4
9
 
5
10
  * Features:
data/Gemfile CHANGED
@@ -14,3 +14,10 @@ gem "rubocop", "~> 1.21"
14
14
  gem "pry", "~> 0.14.2"
15
15
 
16
16
  gem "simplecov", "~> 0.22.0"
17
+
18
+ gem "rails", "~> 6.1.7.1"
19
+
20
+ group :test do
21
+ gem "generator_spec"
22
+ gem "rspec-rails"
23
+ end
data/Gemfile.lock CHANGED
@@ -1,23 +1,149 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_statham (0.1.2)
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
@@ -180,6 +180,30 @@ RSpec.describe FooSerializer do
180
180
  end
181
181
  ```
182
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
+
183
207
  ## Development
184
208
 
185
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,8 @@
1
+ Description:
2
+ Adds json_statham initializer for configuration
3
+
4
+ Example:
5
+ rails generate json_statham:install
6
+
7
+ This will create:
8
+ config/initializers/json_statham.rb
@@ -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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ JsonStatham.configure do |config|
4
+ config.schemas_path = "schemas"
5
+ config.store_schema = true
6
+ config.raise_ratio = 10
7
+ 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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsonStatham
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks do
6
+ load File.expand_path("../tasks/json_statham_tasks.rake", __dir__)
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonStatham
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :statham do
4
+ task log_files_duration: :environment do
5
+ JsonStatham::Logger.new.call
6
+ end
7
+ end
8
+
9
+ task json_statham: ["statham:log_files_duration"]
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.2
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-07 00:00:00.000000000 Z
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.6.0
62
+ version: 2.7.0
57
63
  required_rubygems_version: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - ">="