rake-protect 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +61 -0
- data/lib/rake-protect.rb +33 -0
- metadata +249 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45b92ba09a39bf90ff416eae9dd63ab44e149e91
|
4
|
+
data.tar.gz: 4f873e1292850b503b7ebfe8e5f463632ae49972
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7df4c00f6d40611d834ee603952810ac091826bfad6101c33de2ab95b091b52f1a725f3b4024114d7068e1938c66f7b9de83d90d4d99e4b8bee748c28bfc4ecd
|
7
|
+
data.tar.gz: 6bd4cd8183034d97627de9dc7f6630dd9d177ae18d9f33247c8b3c171733812c0bf43a6b07f36d1ddfc35eff3d84fa2d70274ea46b49ba1193fffbef37bc712a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Marek Tuchowski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# rake-protect
|
2
|
+
|
3
|
+
[![build status](https://gitlab.com/mtuchowski/rake-protect/badges/master/build.svg)](https://gitlab.com/mtuchowski/rake-protect/commits/master)
|
4
|
+
[![coverage report](https://gitlab.com/mtuchowski/rake-protect/badges/master/coverage.svg)](https://gitlab.com/mtuchowski/rake-protect/commits/master)
|
5
|
+
|
6
|
+
When some gems are unavailable in an environment, for example on a production server, requiring them in a `Rakefile` will cause `LoadError` to be thrown. Wrap the require and task declaration in `Rake.protect` block to prevent that.
|
7
|
+
|
8
|
+
For example, let's create a sample `Gemfile` with one gem limited only to `test` group:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
source 'https://rubygems.org'
|
12
|
+
|
13
|
+
gem 'rake'
|
14
|
+
gem 'rake-protect'
|
15
|
+
|
16
|
+
# Test environment gems only.
|
17
|
+
group :test do
|
18
|
+
gem 'rubocop'
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
Then, install the gems, without the `test` group:
|
23
|
+
|
24
|
+
```console
|
25
|
+
$ bundle install --without=test
|
26
|
+
```
|
27
|
+
|
28
|
+
Now, requiring the `rubocop` gem inside `Rakefile` will naturally raise a `LoadError`:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'rubocop/rake_task'
|
32
|
+
|
33
|
+
RuboCop::RakeTask.new # This raises a LoadError.
|
34
|
+
```
|
35
|
+
|
36
|
+
Wrap the require and task declaration in `Rake.protect` to suppress the error and allow yourself to use other, available tasks:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'rake-protect'
|
40
|
+
|
41
|
+
Rake.protect do
|
42
|
+
require 'rubocop/rake_task'
|
43
|
+
|
44
|
+
RuboCop::RakeTask.new
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
After checking out the repo, run `bin/install-dependencies` to install dependencies.
|
51
|
+
|
52
|
+
The project uses [Rake](http://rake.rubyforge.org/) to automate development tasks. Run `bin/run` without any arguments to see the full list.
|
53
|
+
|
54
|
+
### Using development console
|
55
|
+
|
56
|
+
`bin/run guard` command starts a live console that automates various common tasks (running tests, linting source code, etc.) in response to file system modifications. This feature is provided by [Guard](https://github.com/guard/guard) gem.
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
61
|
+
Copyright (c) 2017 Marek Tuchowski. See [LICENSE](./LICENSE) for details.
|
data/lib/rake-protect.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rainbow'
|
5
|
+
|
6
|
+
# rubocop:disable Style/Documentation
|
7
|
+
module Rake
|
8
|
+
# Wraps block in rescue clause to prevent raising an exception when some gems are unavailable
|
9
|
+
# in an environment, for example on a production server.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# Rake.protect do
|
13
|
+
# require 'unavailable_gem'
|
14
|
+
# ..
|
15
|
+
# end
|
16
|
+
def self.protect(&block)
|
17
|
+
raise ArgumentError unless block
|
18
|
+
|
19
|
+
block.call
|
20
|
+
rescue LoadError => error
|
21
|
+
return unless Rake.verbose == true
|
22
|
+
|
23
|
+
if RUBY_VERSION >= '2.1'
|
24
|
+
# :nocov:
|
25
|
+
task = error.backtrace_locations.find do |location|
|
26
|
+
location.path.match(/^.*\.rake$/)
|
27
|
+
end
|
28
|
+
# :nocov:
|
29
|
+
end
|
30
|
+
|
31
|
+
$stderr.puts Rainbow("Tasks#{(' in ' + task.path) if task} not available: #{error.message}").red
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rake-protect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marek Tuchowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rainbow
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.47'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.47'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: reek
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.11'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.11'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.14'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.14'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: guard-rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '4.7'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '4.7'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: listen
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: simplecov
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.13'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.13'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: simplecov-console
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ~>
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0.4'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ~>
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0.4'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: simplecov-json
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ~>
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0.2'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ~>
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0.2'
|
209
|
+
description: |2
|
210
|
+
When some gems are unavailable in an environment, for example on a production server, requiring
|
211
|
+
them in a `Rakefile` will cause `LoadError` to be thrown. Wrap the require and task declaration
|
212
|
+
in `Rake.protect` block to prevent that.
|
213
|
+
email: marek@tuchowski.com.pl
|
214
|
+
executables: []
|
215
|
+
extensions: []
|
216
|
+
extra_rdoc_files:
|
217
|
+
- README.md
|
218
|
+
- LICENSE
|
219
|
+
files:
|
220
|
+
- LICENSE
|
221
|
+
- README.md
|
222
|
+
- lib/rake-protect.rb
|
223
|
+
homepage: https://gitlab.com/mtuchowski/rake-protect
|
224
|
+
licenses:
|
225
|
+
- MIT
|
226
|
+
metadata: {}
|
227
|
+
post_install_message:
|
228
|
+
rdoc_options:
|
229
|
+
- --charset
|
230
|
+
- UTF-8
|
231
|
+
require_paths:
|
232
|
+
- lib
|
233
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - '>='
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: 2.0.0
|
238
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
|
+
requirements:
|
240
|
+
- - '>='
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: '2.6'
|
243
|
+
requirements: []
|
244
|
+
rubyforge_project:
|
245
|
+
rubygems_version: 2.6.10
|
246
|
+
signing_key:
|
247
|
+
specification_version: 4
|
248
|
+
summary: Protect from raising an exception when requiring unavailable gems in Rakefile
|
249
|
+
test_files: []
|