grape-app 0.8.8 → 0.10.1

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: ba29de5fd70e82430c9bedfe0381fbabf43cd420d16c416e162582926f7bbec1
4
- data.tar.gz: 71f550566eb3fccf9d66baf45c2e987bef0876a48daf139aac0eedf0746f350e
3
+ metadata.gz: 74079cb85645ce520a781a57a58de041ea2fd7d99d6a8fbbb2f8666a98cd1c2e
4
+ data.tar.gz: 1cf09f82decf2ca06f82857d6865eeb1e0e0271a4abaf701bba1aa3018097c5b
5
5
  SHA512:
6
- metadata.gz: 74835d8b690aacee9164288561974a4954823cb9cac45206e93927c17fbde803f2b13a8bbab437fea84470c36cf518d17c20b00e3459702c965e9c74522ddfd5
7
- data.tar.gz: 97cbb35a1ade9fb541759efc71789163161c2bf255b36a94febe0ba1698a364d333dbec8a30a8e923d6f2ecbce80edffa164557737d071ae6a8016db2bde94f4
6
+ metadata.gz: 77ae37fd42d9e2fd696801599fccc387bcd39c081f53d2fd4995c59b166cff43041b4ca0fa35cd7187e37775cd0441f15cab3212adb355306ef3ff59da12feca
7
+ data.tar.gz: 544d948b260b034f26bdc7dc11e2b7961186ed6f0ce3fabacbc16fe890f3b85ecab4a32ea578fc578009053a1f43570987b2adff2e972cbb968b7c24704b99e6
@@ -11,7 +11,10 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: ["2.6", "2.7", "3.0"]
14
+ ruby-version: ["2.7", "3.0", "3.1"]
15
+ gemfiles: ["Gemfile", "Gemfile.rails6"]
16
+ env:
17
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
15
18
  steps:
16
19
  - uses: actions/checkout@v2
17
20
  - uses: ruby/setup-ruby@v1
data/.rubocop.yml CHANGED
@@ -6,7 +6,7 @@ inherit_mode:
6
6
  - Exclude
7
7
 
8
8
  AllCops:
9
- TargetRubyVersion: "2.6"
9
+ TargetRubyVersion: "2.7"
10
10
  Metrics/ParameterLists:
11
11
  Exclude:
12
12
  - lib/grape/app/helpers/caching.rb
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-app (0.8.8)
4
+ grape-app (0.10.1)
5
5
  activesupport
6
6
  grape (>= 1.2)
7
7
  grape-entity
8
+ openssl
8
9
  rack-cors (>= 1.1)
9
10
  rack-ssl-enforcer
10
11
  thor
@@ -13,31 +14,33 @@ PATH
13
14
  GEM
14
15
  remote: https://rubygems.org/
15
16
  specs:
16
- activemodel (6.1.3.1)
17
- activesupport (= 6.1.3.1)
18
- activerecord (6.1.3.1)
19
- activemodel (= 6.1.3.1)
20
- activesupport (= 6.1.3.1)
21
- activesupport (6.1.3.1)
17
+ activejob (7.0.3)
18
+ activesupport (= 7.0.3)
19
+ globalid (>= 0.3.6)
20
+ activemodel (7.0.3)
21
+ activesupport (= 7.0.3)
22
+ activerecord (7.0.3)
23
+ activemodel (= 7.0.3)
24
+ activesupport (= 7.0.3)
25
+ activesupport (7.0.3)
22
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
23
27
  i18n (>= 1.6, < 2)
24
28
  minitest (>= 5.1)
25
29
  tzinfo (~> 2.0)
26
- zeitwerk (~> 2.3)
27
30
  ast (2.4.2)
28
31
  builder (3.2.4)
29
- concurrent-ruby (1.1.8)
30
- diff-lcs (1.4.4)
31
- dry-configurable (0.12.1)
32
+ concurrent-ruby (1.1.10)
33
+ diff-lcs (1.5.0)
34
+ dry-configurable (0.15.0)
32
35
  concurrent-ruby (~> 1.0)
33
- dry-core (~> 0.5, >= 0.5.0)
34
- dry-container (0.7.2)
36
+ dry-core (~> 0.6)
37
+ dry-container (0.9.0)
35
38
  concurrent-ruby (~> 1.0)
36
- dry-configurable (~> 0.1, >= 0.1.3)
37
- dry-core (0.5.0)
39
+ dry-configurable (~> 0.13, >= 0.13.0)
40
+ dry-core (0.7.1)
38
41
  concurrent-ruby (~> 1.0)
39
- dry-inflector (0.2.0)
40
- dry-logic (1.1.1)
42
+ dry-inflector (0.2.1)
43
+ dry-logic (1.2.0)
41
44
  concurrent-ruby (~> 1.0)
42
45
  dry-core (~> 0.5, >= 0.5)
43
46
  dry-types (1.5.1)
@@ -46,28 +49,31 @@ GEM
46
49
  dry-core (~> 0.5, >= 0.5)
47
50
  dry-inflector (~> 0.1, >= 0.1.2)
48
51
  dry-logic (~> 1.0, >= 1.0.2)
49
- grape (1.5.3)
52
+ globalid (1.0.0)
53
+ activesupport (>= 5.0)
54
+ grape (1.6.2)
50
55
  activesupport
51
56
  builder
52
57
  dry-types (>= 1.1)
53
58
  mustermann-grape (~> 1.0.0)
54
59
  rack (>= 1.3.0)
55
60
  rack-accept
56
- grape-entity (0.9.0)
61
+ grape-entity (0.10.1)
57
62
  activesupport (>= 3.0.0)
58
63
  multi_json (>= 1.3.2)
59
- i18n (1.8.10)
64
+ i18n (1.10.0)
60
65
  concurrent-ruby (~> 1.0)
61
- minitest (5.14.4)
66
+ minitest (5.15.0)
62
67
  multi_json (1.15.0)
63
68
  mustermann (1.1.1)
64
69
  ruby2_keywords (~> 0.0.1)
65
- mustermann-grape (1.0.1)
70
+ mustermann-grape (1.0.2)
66
71
  mustermann (>= 1.0.0)
67
- parallel (1.20.1)
68
- parser (3.0.1.0)
72
+ openssl (3.0.0)
73
+ parallel (1.22.1)
74
+ parser (3.1.2.0)
69
75
  ast (~> 2.4.1)
70
- rack (2.2.3)
76
+ rack (2.2.3.1)
71
77
  rack-accept (0.4.5)
72
78
  rack (>= 0.4)
73
79
  rack-cors (1.1.1)
@@ -75,65 +81,60 @@ GEM
75
81
  rack-ssl-enforcer (0.2.9)
76
82
  rack-test (1.1.0)
77
83
  rack (>= 1.0, < 3)
78
- rainbow (3.0.0)
79
- rake (13.0.3)
80
- regexp_parser (2.1.1)
84
+ rainbow (3.1.1)
85
+ rake (13.0.6)
86
+ regexp_parser (2.5.0)
81
87
  rexml (3.2.5)
82
- rspec (3.10.0)
83
- rspec-core (~> 3.10.0)
84
- rspec-expectations (~> 3.10.0)
85
- rspec-mocks (~> 3.10.0)
86
- rspec-core (3.10.1)
87
- rspec-support (~> 3.10.0)
88
- rspec-expectations (3.10.1)
88
+ rspec (3.11.0)
89
+ rspec-core (~> 3.11.0)
90
+ rspec-expectations (~> 3.11.0)
91
+ rspec-mocks (~> 3.11.0)
92
+ rspec-core (3.11.0)
93
+ rspec-support (~> 3.11.0)
94
+ rspec-expectations (3.11.0)
89
95
  diff-lcs (>= 1.2.0, < 2.0)
90
- rspec-support (~> 3.10.0)
91
- rspec-mocks (3.10.2)
96
+ rspec-support (~> 3.11.0)
97
+ rspec-mocks (3.11.1)
92
98
  diff-lcs (>= 1.2.0, < 2.0)
93
- rspec-support (~> 3.10.0)
94
- rspec-support (3.10.2)
95
- rubocop (1.12.1)
99
+ rspec-support (~> 3.11.0)
100
+ rspec-support (3.11.0)
101
+ rubocop (1.30.1)
96
102
  parallel (~> 1.10)
97
- parser (>= 3.0.0.0)
103
+ parser (>= 3.1.0.0)
98
104
  rainbow (>= 2.2.2, < 4.0)
99
105
  regexp_parser (>= 1.8, < 3.0)
100
- rexml
101
- rubocop-ast (>= 1.2.0, < 2.0)
106
+ rexml (>= 3.2.5, < 4.0)
107
+ rubocop-ast (>= 1.18.0, < 2.0)
102
108
  ruby-progressbar (~> 1.7)
103
109
  unicode-display_width (>= 1.4.0, < 3.0)
104
- rubocop-ast (1.4.1)
105
- parser (>= 2.7.1.5)
106
- rubocop-bsm (0.5.6)
110
+ rubocop-ast (1.18.0)
111
+ parser (>= 3.1.1.0)
112
+ rubocop-bsm (0.6.0)
107
113
  rubocop (~> 1.0)
108
114
  rubocop-performance
109
- rubocop-rails
110
115
  rubocop-rake
111
116
  rubocop-rspec
112
- rubocop-performance (1.10.2)
113
- rubocop (>= 0.90.0, < 2.0)
117
+ rubocop-performance (1.14.1)
118
+ rubocop (>= 1.7.0, < 2.0)
114
119
  rubocop-ast (>= 0.4.0)
115
- rubocop-rails (2.9.1)
116
- activesupport (>= 4.2.0)
117
- rack (>= 1.1)
118
- rubocop (>= 0.90.0, < 2.0)
119
- rubocop-rake (0.5.1)
120
- rubocop
121
- rubocop-rspec (2.2.0)
120
+ rubocop-rake (0.6.0)
122
121
  rubocop (~> 1.0)
123
- rubocop-ast (>= 1.1.0)
122
+ rubocop-rspec (2.11.1)
123
+ rubocop (~> 1.19)
124
124
  ruby-progressbar (1.11.0)
125
- ruby2_keywords (0.0.4)
125
+ ruby2_keywords (0.0.5)
126
126
  sqlite3 (1.4.2)
127
- thor (1.1.0)
127
+ thor (1.2.1)
128
128
  tzinfo (2.0.4)
129
129
  concurrent-ruby (~> 1.0)
130
- unicode-display_width (2.0.0)
131
- zeitwerk (2.4.2)
130
+ unicode-display_width (2.1.0)
131
+ zeitwerk (2.5.4)
132
132
 
133
133
  PLATFORMS
134
134
  ruby
135
135
 
136
136
  DEPENDENCIES
137
+ activejob
137
138
  activerecord
138
139
  bundler
139
140
  grape-app!
@@ -144,4 +145,4 @@ DEPENDENCIES
144
145
  sqlite3
145
146
 
146
147
  BUNDLED WITH
147
- 2.2.5
148
+ 2.3.9
data/Gemfile.rails6 ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'activesupport', '~> 6.1'
5
+ gem 'activerecord', '~> 6.1'
6
+ gem 'activejob', '~> 6.1'
@@ -0,0 +1,150 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grape-app (0.10.0)
5
+ activesupport
6
+ grape (>= 1.2)
7
+ grape-entity
8
+ openssl
9
+ rack-cors (>= 1.1)
10
+ rack-ssl-enforcer
11
+ thor
12
+ zeitwerk (>= 2.1)
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ activejob (6.1.4.4)
18
+ activesupport (= 6.1.4.4)
19
+ globalid (>= 0.3.6)
20
+ activemodel (6.1.4.4)
21
+ activesupport (= 6.1.4.4)
22
+ activerecord (6.1.4.4)
23
+ activemodel (= 6.1.4.4)
24
+ activesupport (= 6.1.4.4)
25
+ activesupport (6.1.4.4)
26
+ concurrent-ruby (~> 1.0, >= 1.0.2)
27
+ i18n (>= 1.6, < 2)
28
+ minitest (>= 5.1)
29
+ tzinfo (~> 2.0)
30
+ zeitwerk (~> 2.3)
31
+ ast (2.4.2)
32
+ builder (3.2.4)
33
+ concurrent-ruby (1.1.9)
34
+ diff-lcs (1.5.0)
35
+ dry-configurable (0.14.0)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-core (~> 0.6)
38
+ dry-container (0.9.0)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-configurable (~> 0.13, >= 0.13.0)
41
+ dry-core (0.7.1)
42
+ concurrent-ruby (~> 1.0)
43
+ dry-inflector (0.2.1)
44
+ dry-logic (1.2.0)
45
+ concurrent-ruby (~> 1.0)
46
+ dry-core (~> 0.5, >= 0.5)
47
+ dry-types (1.5.1)
48
+ concurrent-ruby (~> 1.0)
49
+ dry-container (~> 0.3)
50
+ dry-core (~> 0.5, >= 0.5)
51
+ dry-inflector (~> 0.1, >= 0.1.2)
52
+ dry-logic (~> 1.0, >= 1.0.2)
53
+ globalid (1.0.0)
54
+ activesupport (>= 5.0)
55
+ grape (1.6.2)
56
+ activesupport
57
+ builder
58
+ dry-types (>= 1.1)
59
+ mustermann-grape (~> 1.0.0)
60
+ rack (>= 1.3.0)
61
+ rack-accept
62
+ grape-entity (0.10.1)
63
+ activesupport (>= 3.0.0)
64
+ multi_json (>= 1.3.2)
65
+ i18n (1.9.1)
66
+ concurrent-ruby (~> 1.0)
67
+ minitest (5.15.0)
68
+ multi_json (1.15.0)
69
+ mustermann (1.1.1)
70
+ ruby2_keywords (~> 0.0.1)
71
+ mustermann-grape (1.0.1)
72
+ mustermann (>= 1.0.0)
73
+ openssl (3.0.0)
74
+ parallel (1.21.0)
75
+ parser (3.1.0.0)
76
+ ast (~> 2.4.1)
77
+ rack (2.2.3)
78
+ rack-accept (0.4.5)
79
+ rack (>= 0.4)
80
+ rack-cors (1.1.1)
81
+ rack (>= 2.0.0)
82
+ rack-ssl-enforcer (0.2.9)
83
+ rack-test (1.1.0)
84
+ rack (>= 1.0, < 3)
85
+ rainbow (3.1.1)
86
+ rake (13.0.6)
87
+ regexp_parser (2.2.0)
88
+ rexml (3.2.5)
89
+ rspec (3.10.0)
90
+ rspec-core (~> 3.10.0)
91
+ rspec-expectations (~> 3.10.0)
92
+ rspec-mocks (~> 3.10.0)
93
+ rspec-core (3.10.2)
94
+ rspec-support (~> 3.10.0)
95
+ rspec-expectations (3.10.2)
96
+ diff-lcs (>= 1.2.0, < 2.0)
97
+ rspec-support (~> 3.10.0)
98
+ rspec-mocks (3.10.3)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.10.0)
101
+ rspec-support (3.10.3)
102
+ rubocop (1.25.1)
103
+ parallel (~> 1.10)
104
+ parser (>= 3.1.0.0)
105
+ rainbow (>= 2.2.2, < 4.0)
106
+ regexp_parser (>= 1.8, < 3.0)
107
+ rexml
108
+ rubocop-ast (>= 1.15.1, < 2.0)
109
+ ruby-progressbar (~> 1.7)
110
+ unicode-display_width (>= 1.4.0, < 3.0)
111
+ rubocop-ast (1.15.1)
112
+ parser (>= 3.0.1.1)
113
+ rubocop-bsm (0.6.0)
114
+ rubocop (~> 1.0)
115
+ rubocop-performance
116
+ rubocop-rake
117
+ rubocop-rspec
118
+ rubocop-performance (1.13.2)
119
+ rubocop (>= 1.7.0, < 2.0)
120
+ rubocop-ast (>= 0.4.0)
121
+ rubocop-rake (0.6.0)
122
+ rubocop (~> 1.0)
123
+ rubocop-rspec (2.8.0)
124
+ rubocop (~> 1.19)
125
+ ruby-progressbar (1.11.0)
126
+ ruby2_keywords (0.0.5)
127
+ sqlite3 (1.4.2)
128
+ thor (1.2.1)
129
+ tzinfo (2.0.4)
130
+ concurrent-ruby (~> 1.0)
131
+ unicode-display_width (2.1.0)
132
+ zeitwerk (2.5.4)
133
+
134
+ PLATFORMS
135
+ x86_64-linux
136
+
137
+ DEPENDENCIES
138
+ activejob (~> 6.1)
139
+ activerecord (~> 6.1)
140
+ activesupport (~> 6.1)
141
+ bundler
142
+ grape-app!
143
+ rack-test
144
+ rake
145
+ rspec
146
+ rubocop-bsm
147
+ sqlite3
148
+
149
+ BUNDLED WITH
150
+ 2.3.4
data/grape-app.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'grape-app'
3
- s.version = '0.8.8'
3
+ s.version = '0.10.1'
4
4
  s.authors = ['Black Square Media Ltd']
5
5
  s.email = ['info@blacksquaremedia.com']
6
6
  s.summary = %(Standalone Grape API apps)
@@ -9,19 +9,20 @@ Gem::Specification.new do |s|
9
9
  s.license = 'MIT'
10
10
 
11
11
  s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
12
- s.test_files = `git ls-files -z -- spec/*`.split("\x0")
13
12
  s.executables = ['grape-app']
14
13
  s.require_paths = ['lib']
15
- s.required_ruby_version = '>= 2.6'
14
+ s.required_ruby_version = '>= 2.7'
16
15
 
17
16
  s.add_dependency 'activesupport'
18
17
  s.add_dependency 'grape', '>= 1.2'
19
18
  s.add_dependency 'grape-entity'
19
+ s.add_dependency 'openssl'
20
20
  s.add_dependency 'rack-cors', '>= 1.1'
21
21
  s.add_dependency 'rack-ssl-enforcer'
22
22
  s.add_dependency 'thor'
23
23
  s.add_dependency 'zeitwerk', '>= 2.1'
24
24
 
25
+ s.add_development_dependency 'activejob'
25
26
  s.add_development_dependency 'activerecord'
26
27
  s.add_development_dependency 'bundler'
27
28
  s.add_development_dependency 'rack-test'
@@ -29,4 +30,5 @@ Gem::Specification.new do |s|
29
30
  s.add_development_dependency 'rspec'
30
31
  s.add_development_dependency 'rubocop-bsm'
31
32
  s.add_development_dependency 'sqlite3'
33
+ s.metadata['rubygems_mfa_required'] = 'true'
32
34
  end
@@ -1,8 +1,3 @@
1
- if Grape::App.config.raise_on_missing_translations
2
- handler = ->(exception, *) { exception = exception.to_exception if exception.respond_to?(:to_exception); raise exception }
3
- I18n.exception_handler = handler
4
- end
5
-
6
1
  if defined?(ActiveRecord)
7
2
  require 'yaml'
8
3
  require 'erb'
@@ -12,9 +7,7 @@ if defined?(ActiveRecord)
12
7
  configurations[Grape::App.env.to_s] ||= {}
13
8
  configurations[Grape::App.env.to_s]['url'] ||= ENV['DATABASE_URL']
14
9
  end
15
-
16
10
  ActiveRecord::Base.configurations = configurations
17
- ActiveRecord::Base.default_timezone = :utc
18
11
  ActiveRecord::Base.establish_connection(Grape::App.env.to_sym)
19
12
 
20
13
  Grape::App.middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement if defined?(ActiveRecord::ConnectionAdapters::ConnectionManagement)
@@ -1,6 +1,72 @@
1
+ # Configure ActiveSupport defaults
2
+ # https://github.com/rails/rails/blob/main/railties/lib/rails/application/configuration.rb
3
+ ActiveSupport.tap do |c|
4
+ c.to_time_preserves_timezone = true
5
+ c.utc_to_local_returns_utc_offset_times = true
6
+ end
7
+ ActiveSupport::Digest.hash_digest_class = OpenSSL::Digest::SHA256
8
+ ActiveSupport::KeyGenerator.hash_digest_class = OpenSSL::Digest::SHA256 if ActiveSupport::KeyGenerator.respond_to?(:hash_digest_class=)
9
+ ActiveSupport::MessageEncryptor.use_authenticated_message_encryption = true
10
+ ActiveSupport::IsolatedExecutionState.isolation_level = :thread if defined?(ActiveSupport::IsolatedExecutionState)
11
+ Digest::UUID.use_rfc4122_namespaced_uuids = true if Digest::UUID.respond_to?(:use_rfc4122_namespaced_uuids=)
12
+
1
13
  # Set default time-zone
14
+ begin
15
+ TZInfo::DataSource.get
16
+ rescue TZInfo::DataSourceNotFound => e
17
+ raise e.exception "tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install"
18
+ end
19
+ require 'active_support/core_ext/time/zones'
2
20
  Time.zone_default = Time.find_zone!('UTC')
3
21
 
4
22
  # Add default I18n paths and set default locale
5
23
  I18n.load_path += Dir[Grape::App.root.join('config', 'locales', '*.{rb,yml}').to_s]
6
24
  I18n.default_locale = :en
25
+
26
+ if Grape::App.config.raise_on_missing_translations
27
+ handler = Class.new(I18n::ExceptionHandler) do
28
+ def call(exception, *)
29
+ raise exception.to_exception if exception.is_a?(I18n::MissingTranslation)
30
+
31
+ super
32
+ end
33
+ end
34
+ I18n.exception_handler = handler.new
35
+ end
36
+
37
+ # Configure ActiveRecord defaults
38
+ # https://github.com/rails/rails/blob/main/railties/lib/rails/application/configuration.rb
39
+ if defined?(ActiveRecord)
40
+ if ActiveRecord.respond_to?(:default_timezone=)
41
+ ActiveRecord.default_timezone = :utc
42
+ else
43
+ ActiveRecord::Base.default_timezone = :utc
44
+ end
45
+
46
+ if ActiveRecord.respond_to?(:legacy_connection_handling=)
47
+ ActiveRecord.legacy_connection_handling = false
48
+ else
49
+ ActiveRecord::Base.legacy_connection_handling = false
50
+ end
51
+
52
+ ActiveRecord.tap do |c|
53
+ c.verify_foreign_keys_for_fixtures = true if c.respond_to?(:verify_foreign_keys_for_fixtures=)
54
+ end
55
+
56
+ ActiveRecord::Base.tap do |c|
57
+ c.belongs_to_required_by_default = true
58
+ c.cache_versioning = true
59
+ c.collection_cache_versioning = true
60
+ c.has_many_inversing = true
61
+ c.partial_inserts = false if c.respond_to?(:partial_inserts=)
62
+ c.automatic_scope_inversing = true if c.respond_to?(:automatic_scope_inversing=)
63
+ end
64
+ end
65
+
66
+ # Configure ActiveJob defaults
67
+ # https://github.com/rails/rails/blob/main/railties/lib/rails/application/configuration.rb
68
+ if defined?(ActiveJob)
69
+ ActiveJob::Base.tap do |c|
70
+ c.retry_jitter = 0.15
71
+ end
72
+ end
@@ -23,11 +23,10 @@ namespace :db do
23
23
 
24
24
  desc 'Create a new migration using NAME'
25
25
  task migration: :environment do
26
- abort 'No NAME specified. Example usage: `rake db:migration NAME=create_widgets`' unless ENV['NAME']
26
+ name = ENV.fetch('NAME', nil)
27
+ abort 'No NAME specified. Example usage: `rake db:migration NAME=create_widgets`' unless name
27
28
 
28
29
  migrations_path = ActiveRecord::Migrator.migrations_paths.first
29
-
30
- name = ENV['NAME']
31
30
  path = File.join(migrations_path, "#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{name}.rb")
32
31
 
33
32
  ar_version = [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR].join('.')
@@ -1,4 +1,12 @@
1
1
  Grape::App.configure do |config|
2
+ # Eager load code on boot. This eager loads most of your application in
3
+ # memory, allowing both threaded web servers and those relying on copy on
4
+ # write to perform better.
5
+ config.eager_load = true
6
+
7
+ # Don't raise errors on missing translations
8
+ # config.raise_on_missing_translations = false
9
+
2
10
  # Force SSL, please see https://github.com/tobmatth/rack-ssl-enforcer
3
11
  # for configuration options.
4
12
  #
@@ -20,7 +28,4 @@ Grape::App.configure do |config|
20
28
  # use Rack::ETag
21
29
  # insert_before Rack::Cors, Rack::ContentLength
22
30
  # end
23
-
24
- # Don't raise errors on missing translations
25
- # config.raise_on_missing_translations = false
26
31
  end
data/lib/grape/app.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require 'bundler/setup'
2
2
  require 'pathname'
3
+ require 'openssl'
3
4
  require 'grape'
4
- require 'active_support/string_inquirer'
5
- require 'active_support/configurable'
6
- require 'active_support/core_ext/time/zones'
7
5
  require 'rack/cors'
8
6
  require 'rack/ssl-enforcer'
9
7
  require 'zeitwerk'
10
8
 
9
+ ENV['RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION'] ||= 'true'
10
+ require 'active_support/all'
11
+ require 'active_support/string_inquirer'
12
+ require 'active_support/configurable'
13
+
11
14
  class Grape::App < Grape::API
12
15
  class << self
13
16
  # Run initializers
@@ -35,6 +38,7 @@ class Grape::App < Grape::API
35
38
 
36
39
  # Load app
37
40
  require_one 'app', 'api'
41
+ Zeitwerk::Loader.eager_load_all if Grape::App.config.eager_load
38
42
  end
39
43
 
40
44
  # @return [Grape::App::Configuration] the configuration
@@ -58,7 +62,7 @@ class Grape::App < Grape::API
58
62
 
59
63
  # @return [ActiveSupport::StringInquirer] env name
60
64
  def env
61
- @env ||= ActiveSupport::StringInquirer.new(ENV['GRAPE_ENV'] || ENV['RACK_ENV'] || 'development')
65
+ @env ||= ActiveSupport::StringInquirer.new(ENV.fetch('GRAPE_ENV') { ENV.fetch('RACK_ENV', 'development') })
62
66
  end
63
67
 
64
68
  # @return [Zeitwerk::Loader] loader
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-16 00:00:00.000000000 Z
11
+ date: 2022-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: openssl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rack-cors
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '2.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activejob
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: activerecord
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +248,8 @@ files:
220
248
  - ".rubocop.yml"
221
249
  - Gemfile
222
250
  - Gemfile.lock
251
+ - Gemfile.rails6
252
+ - Gemfile.rails6.lock
223
253
  - LICENSE
224
254
  - README.md
225
255
  - Rakefile
@@ -255,23 +285,11 @@ files:
255
285
  - lib/grape/app/templates/db/seeds.rb
256
286
  - lib/grape/app/templates/spec/spec_helper.rb
257
287
  - lib/grape_app.rb
258
- - spec/grape/app/helpers/caching_spec.rb
259
- - spec/grape/app/helpers/params_spec.rb
260
- - spec/grape/app/middleware/connection_management_spec.rb
261
- - spec/grape/app_spec.rb
262
- - spec/scenario/Gemfile
263
- - spec/scenario/app/api.rb
264
- - spec/scenario/app/api/posts.rb
265
- - spec/scenario/app/api/v1.rb
266
- - spec/scenario/config/database.yml
267
- - spec/scenario/config/environments/test.rb
268
- - spec/scenario/config/locales/en.yml
269
- - spec/scenario/lib/my_lib.rb
270
- - spec/spec_helper.rb
271
288
  homepage: https://github.com/bsm/grape-app
272
289
  licenses:
273
290
  - MIT
274
- metadata: {}
291
+ metadata:
292
+ rubygems_mfa_required: 'true'
275
293
  post_install_message:
276
294
  rdoc_options: []
277
295
  require_paths:
@@ -280,28 +298,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
280
298
  requirements:
281
299
  - - ">="
282
300
  - !ruby/object:Gem::Version
283
- version: '2.6'
301
+ version: '2.7'
284
302
  required_rubygems_version: !ruby/object:Gem::Requirement
285
303
  requirements:
286
304
  - - ">="
287
305
  - !ruby/object:Gem::Version
288
306
  version: '0'
289
307
  requirements: []
290
- rubygems_version: 3.1.4
308
+ rubygems_version: 3.3.7
291
309
  signing_key:
292
310
  specification_version: 4
293
311
  summary: Standalone Grape API apps
294
- test_files:
295
- - spec/grape/app/helpers/caching_spec.rb
296
- - spec/grape/app/helpers/params_spec.rb
297
- - spec/grape/app/middleware/connection_management_spec.rb
298
- - spec/grape/app_spec.rb
299
- - spec/scenario/Gemfile
300
- - spec/scenario/app/api.rb
301
- - spec/scenario/app/api/posts.rb
302
- - spec/scenario/app/api/v1.rb
303
- - spec/scenario/config/database.yml
304
- - spec/scenario/config/environments/test.rb
305
- - spec/scenario/config/locales/en.yml
306
- - spec/scenario/lib/my_lib.rb
307
- - spec/spec_helper.rb
312
+ test_files: []
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Grape::App::Helpers::Caching do
4
- include Rack::Test::Methods
5
-
6
- let :app do
7
- helper = described_class
8
- Class.new(Grape::API) do
9
- format :json
10
-
11
- helpers helper
12
-
13
- get '/articles' do
14
- scope = Article.order(:id)
15
- opts = params[:public] ? { public: params[:public] } : {}
16
- fresh_when(scope, **opts)
17
- scope.to_a
18
- end
19
-
20
- get '/articles/never_updated' do
21
- article = Article.first
22
- article.updated_at = nil
23
-
24
- fresh_when(article, last_modified_field: :created_at)
25
- end
26
-
27
- get '/articles/:id' do
28
- article = Article.first
29
- article if stale?(article, stale_if_error: 5, extras: { a: 1, b: 2 })
30
- end
31
- end
32
- end
33
- let(:created_at) { Time.at(1515151500).utc }
34
-
35
- before do
36
- Article.create! title: 'Welcome', created_at: created_at, updated_at: created_at + 10
37
- Article.create! title: 'Bye', created_at: created_at, updated_at: created_at + 20
38
- end
39
-
40
- it 'handles fresh-when' do
41
- get '/articles'
42
- expect(last_response.status).to eq(200)
43
- expect(last_response.headers).to include(
44
- 'Content-Type' => 'application/json',
45
- 'ETag' => 'a5f6c4b024510c9835d8d70cbd3ed00c',
46
- 'Last-Modified' => 'Fri, 05 Jan 2018 11:25:20 GMT',
47
- )
48
- expect(JSON.parse(last_response.body).size).to eq(2)
49
-
50
- get '/articles', {}, 'HTTP_IF_NONE_MATCH' => last_response.headers['ETag']
51
- expect(last_response.status).to eq(304)
52
- get '/articles', {}, 'HTTP_IF_MODIFIED_SINCE' => 'Fri, 05 Jan 2018 11:25:20 GMT'
53
- expect(last_response.status).to eq(304)
54
- get '/articles', {}, 'HTTP_IF_NONE_MATCH' => last_response.headers['ETag'], 'HTTP_IF_MODIFIED_SINCE' => 'Fri, 05 Jan 2018 11:25:21 GMT'
55
- expect(last_response.status).to eq(304)
56
-
57
- get '/articles', {}, 'HTTP_IF_MODIFIED_SINCE' => 'Fri, 05 Jan 2018 11:25:19 GMT'
58
- expect(last_response.status).to eq(200)
59
- get '/articles', {}, 'HTTP_IF_MODIFIED_SINCE' => 'Fri, 05 Jan 2018 11:25:19 GMT', 'HTTP_IF_NONE_MATCH' => last_response.headers['ETag']
60
- expect(last_response.status).to eq(200)
61
- get '/articles', {}, 'HTTP_IF_MODIFIED_SINCE' => 'Fri, 05 Jan 2018 11:25:20 GMT', 'HTTP_IF_NONE_MATCH' => 'other'
62
- expect(last_response.status).to eq(200)
63
- end
64
-
65
- it 'handles fresh_when for records that were never updated' do
66
- get '/articles/never_updated'
67
- expect(last_response.status).to eq(200)
68
- expect(last_response.headers).to include(
69
- 'Last-Modified' => 'Fri, 05 Jan 2018 11:25:00 GMT',
70
- )
71
- end
72
-
73
- it 'supports cache-control' do
74
- get '/articles?public=true'
75
- expect(last_response.status).to eq(200)
76
- expect(last_response.headers).to include(
77
- 'Cache-Control' => 'public',
78
- )
79
- end
80
-
81
- it 'handles stale? (with cache-control)' do
82
- get '/articles/1'
83
- expect(last_response.status).to eq(200)
84
- expect(last_response.headers).to include(
85
- 'Cache-Control' => 'private, stale-if-error=5, a=1, b=2',
86
- 'Content-Type' => 'application/json',
87
- 'ETag' => '0154407bafc97186a494a05e0652ff61',
88
- 'Last-Modified' => 'Fri, 05 Jan 2018 11:25:10 GMT',
89
- )
90
- expect(JSON.parse(last_response.body)).to eq(
91
- 'id' => 1,
92
- 'title' => 'Welcome',
93
- 'updated_at' => '2018-01-05T11:25:10.000Z',
94
- 'created_at' => '2018-01-05T11:25:00.000Z',
95
- )
96
-
97
- get '/articles/1', {}, 'HTTP_IF_NONE_MATCH' => last_response.headers['ETag']
98
- expect(last_response.status).to eq(304)
99
- expect(last_response.headers).to include(
100
- 'Cache-Control' => 'private, stale-if-error=5, a=1, b=2',
101
- 'ETag' => '0154407bafc97186a494a05e0652ff61',
102
- 'Last-Modified' => 'Fri, 05 Jan 2018 11:25:10 GMT',
103
- )
104
- end
105
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Grape::App::Helpers::Params do
4
- include Rack::Test::Methods
5
-
6
- let :app do
7
- helper = described_class
8
- Class.new(Grape::API) do
9
- format :json
10
-
11
- helpers helper
12
-
13
- params do
14
- optional :title
15
- end
16
- post '/articles' do
17
- attrs = { id: 9, updated_at: Time.at(1515151515).utc }
18
- attrs.update(declared_params)
19
- Article.new(attrs)
20
- end
21
- end
22
- end
23
-
24
- it 'limits params' do
25
- post '/articles', title: 'Today', id: 1234, updated_at: Time.now
26
- expect(last_response.status).to eq(201)
27
- expect(JSON.parse(last_response.body)).to eq(
28
- 'created_at' => nil,
29
- 'id' => 9,
30
- 'title' => 'Today',
31
- 'updated_at' => '2018-01-05T11:25:15.000Z',
32
- )
33
- end
34
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Grape::App::Middleware::ConnectionManagement do
4
- include Rack::Test::Methods
5
-
6
- let :app do
7
- failing = ->(_) { raise(ActiveRecord::StatementInvalid) }
8
- middleware = described_class
9
- Rack::Builder.new do
10
- use middleware
11
- run failing
12
- end
13
- end
14
-
15
- it 'clears active connections' do
16
- ActiveRecord::Base.connection
17
- expect(ActiveRecord::Base.connection_handler).to be_active_connections
18
-
19
- expect { get '/' }.to raise_error(ActiveRecord::StatementInvalid)
20
- expect(ActiveRecord::Base.connection_handler).not_to be_active_connections
21
- end
22
- end
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Grape::App do
4
- include Rack::Test::Methods
5
-
6
- subject { described_class }
7
-
8
- before { subject.init! File.expand_path('../scenario', __dir__) }
9
-
10
- def app
11
- subject.middleware
12
- end
13
-
14
- it 'has an env' do
15
- expect(subject.env).to be_instance_of(ActiveSupport::StringInquirer)
16
- expect(subject.env).to eq('test')
17
- end
18
-
19
- it 'has an root' do
20
- expect(subject.root).to be_instance_of(Pathname)
21
- end
22
-
23
- it 'is an API instance' do
24
- expect(subject).to be < Grape::API
25
- end
26
-
27
- it 'inits with default time zone' do
28
- expect(Time.zone.name).to eq('UTC')
29
- expect(Thread.new { Time.zone }.value.name).to eq('UTC')
30
- end
31
-
32
- it 'configures i18n' do
33
- expect(I18n.load_path).to include(subject.root.join('config', 'locales', 'en.yml').to_s)
34
- expect(I18n.default_locale).to eq(:en)
35
- expect(I18n.exception_handler).to be_instance_of(Proc)
36
- end
37
-
38
- it 'reads env specific initializers' do
39
- expect(subject.config).to include(
40
- :test_specific,
41
- :raise_on_missing_translations,
42
- :cors,
43
- :middleware,
44
- )
45
- end
46
-
47
- it 'prepares middleware' do
48
- expect(subject.middleware).to be_instance_of(Rack::Builder)
49
- expect(subject.middleware.send(:instance_variable_get, :@use).size).to eq(3)
50
- expect(subject.middleware.send(:instance_variable_get, :@run)).to be(subject)
51
- end
52
-
53
- it 'applies middleware' do
54
- header 'Origin', 'test.host'
55
- get '/v1/ok'
56
- expect(last_response).to be_ok
57
- expect(last_response.body).to eq(%({"status":"OK"}))
58
- expect(last_response.headers).to include(
59
- 'Access-Control-Allow-Origin' => '*',
60
- 'X-MyApp' => 'true',
61
- )
62
-
63
- header 'Origin', 'test.host'
64
- get '/v1/failing'
65
- expect(last_response).to be_bad_request
66
- expect(last_response.body).to eq(%({"error":"bad request"}))
67
- expect(last_response.headers).to include(
68
- 'Access-Control-Allow-Origin' => '*',
69
- 'X-MyApp' => 'true',
70
- )
71
- end
72
- end
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', require: 'active_record'
4
- gem 'grape-app', path: '../../'
@@ -1,5 +0,0 @@
1
- class API::Posts < Grape::API
2
- get '/posts' do
3
- []
4
- end
5
- end
@@ -1,18 +0,0 @@
1
- class API::V1 < Grape::API
2
- version 'v1'
3
- format :json
4
-
5
- rescue_from MyLib::BadRequest do |e|
6
- error!({ error: e }, 400)
7
- end
8
-
9
- get '/ok' do
10
- { status: 'OK' }
11
- end
12
-
13
- get '/failing' do
14
- raise MyLib::BadRequest, 'bad request'
15
- end
16
-
17
- mount API::Posts
18
- end
@@ -1,7 +0,0 @@
1
- module API
2
- end
3
-
4
- # Mount root API to app
5
- Grape::App.instance_eval do
6
- mount API::V1
7
- end
@@ -1,3 +0,0 @@
1
- test:
2
- adapter: "sqlite3"
3
- database: ":memory:"
@@ -1,15 +0,0 @@
1
- require 'my_lib'
2
-
3
- Grape::App.configure do |c|
4
- c.test_specific = true
5
- c.raise_on_missing_translations = true
6
- c.cors do
7
- allow do
8
- origins '*'
9
- resource '*', headers: :any, methods: %i[get post options]
10
- end
11
- end
12
- c.middleware do
13
- use MyLib::Middleware
14
- end
15
- end
@@ -1,2 +0,0 @@
1
- en:
2
- hi: hello
@@ -1,16 +0,0 @@
1
- class MyLib
2
- class BadRequest < StandardError
3
- end
4
-
5
- class Middleware
6
- def initialize(app)
7
- @app = app
8
- end
9
-
10
- def call(env)
11
- status, headers, body = @app.call(env)
12
- headers['X-MyApp'] = 'true'
13
- [status, headers, body]
14
- end
15
- end
16
- end
data/spec/spec_helper.rb DELETED
@@ -1,16 +0,0 @@
1
- ENV['RACK_ENV'] ||= 'test'
2
- require 'grape-app'
3
- require 'rack/test'
4
- require 'active_record'
5
-
6
- ActiveRecord::Base.configurations = { 'test' => { 'adapter' => 'sqlite3', 'database' => ':memory:' } }
7
- ActiveRecord::Base.establish_connection :test
8
- ActiveRecord::Base.connection.instance_eval do
9
- create_table :articles do |t|
10
- t.string :title
11
- t.timestamps
12
- end
13
- end
14
-
15
- class Article < ActiveRecord::Base
16
- end