safeword 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +13 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Guardfile +14 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/lib/safeword/blocker.rb +32 -0
- data/lib/safeword/version.rb +3 -0
- data/lib/safeword.rb +10 -0
- data/safeword.gemspec +36 -0
- metadata +199 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 744d30f815ed87f46a56511eea26c89f36a71d83
|
4
|
+
data.tar.gz: d8aab455c16f68cd2f0b563c782d814b09a09db6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19d44c5fb2d7ba942ded9f277d9cd3879000f9a75f45c0e04e2d6b4de01bfc3d75e5e46432c0a349f190957756d1b5786dfd88fe983f701f2f8b939fbf8d4008
|
7
|
+
data.tar.gz: 972b5aa3e02ccb38b1b429b15e92234aa4c6e28e2838807092b4a14b4a78b76bb3ac1ea8ac4e1448a342a3e4a0e1382faff0867b9ac97903bad04b72f7adea2d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
guard :bundler do
|
2
|
+
watch('safeword.gemspec')
|
3
|
+
end
|
4
|
+
|
5
|
+
guard :rspec, all_on_start: true, cmd: 'bundle exec rspec --format progress' do
|
6
|
+
watch(%r{^spec/.+_spec\.rb$})
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
9
|
+
end
|
10
|
+
|
11
|
+
guard :rubocop do
|
12
|
+
watch(/.+\.rb$/)
|
13
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Wilson Silva
|
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,86 @@
|
|
1
|
+
# Safeword
|
2
|
+
|
3
|
+
Prevents blocks of code from being executed until you consider them safe. Useful if you need to run untested code
|
4
|
+
in the production console.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'safeword'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install safeword
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Every new instance of Safeword is `enabled` by default. Enabled safewords prevent code from being executed.
|
25
|
+
Disabled safewords allow it to be executed.
|
26
|
+
|
27
|
+
To enable, disable and verifying if a safeword is enabled, you can use `enable`, `disable`
|
28
|
+
and `enabled?` respectively:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'safeword'
|
32
|
+
|
33
|
+
safeword = Safeword.new
|
34
|
+
safeword.enabled? # => true
|
35
|
+
|
36
|
+
safeword.disable
|
37
|
+
safeword.enabled? # => false
|
38
|
+
|
39
|
+
safeword.enable
|
40
|
+
safeword.enabled? # => true
|
41
|
+
```
|
42
|
+
|
43
|
+
### Preventing code from running
|
44
|
+
|
45
|
+
Instantiate a `Safeword` and pass your wrapped code in a block to its `use` method.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'safeword'
|
49
|
+
|
50
|
+
safeword = Safeword.new
|
51
|
+
safeword.use { puts 'start war' } #=> nothing happens
|
52
|
+
safeword.disable
|
53
|
+
safeword.use { puts 'drop bomb' } #=> drop bomb
|
54
|
+
```
|
55
|
+
|
56
|
+
### Chaining methods
|
57
|
+
|
58
|
+
The methods `enable`, `disable` and `use` return the word itself, so you can chain multiple calls together:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'safeword'
|
62
|
+
|
63
|
+
Safeword.new
|
64
|
+
.disable
|
65
|
+
.use { puts 'start war' } #=> start war
|
66
|
+
.use { puts 'drop bomb' } #=> drop bomb
|
67
|
+
.enable
|
68
|
+
.use { puts 'cut fruit' } #=> nothing happens
|
69
|
+
```
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
74
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
77
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
78
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/safeword.
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Safeword
|
2
|
+
# Decides whether blocks of code are executed or not.
|
3
|
+
class Blocker
|
4
|
+
# Instantiates an enabled blocker.
|
5
|
+
def initialize
|
6
|
+
@enabled = true
|
7
|
+
end
|
8
|
+
|
9
|
+
# Whether the blocker is enabled or not. Enabled blockers prevent blocks of code from being executed.
|
10
|
+
def enabled?
|
11
|
+
@enabled
|
12
|
+
end
|
13
|
+
|
14
|
+
# Enables the blocker, preventing blocks of code from being executed.
|
15
|
+
def enable
|
16
|
+
@enabled = true
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
# Disables the blocker, allowing blocks of code to be executed.
|
21
|
+
def disable
|
22
|
+
@enabled = false
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
# Ignores the provided block of code if enabled. Executes it otherwise.
|
27
|
+
def use
|
28
|
+
yield unless enabled?
|
29
|
+
self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/safeword.rb
ADDED
data/safeword.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'safeword'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'safeword'
|
9
|
+
spec.version = Safeword::VERSION
|
10
|
+
spec.authors = ['Wilson Silva']
|
11
|
+
spec.email = ['me@wilsonsilva.net']
|
12
|
+
|
13
|
+
spec.summary = 'Prevents blocks of code from being executed until you consider them safe.'
|
14
|
+
spec.description = 'Prevents blocks of code from being executed until you consider them safe.'
|
15
|
+
spec.homepage = 'https://github.com/wilsonsilva/safeword'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(spec)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
27
|
+
spec.add_development_dependency 'guard', '~> 2.14'
|
28
|
+
spec.add_development_dependency 'guard-bundler', '~> 2.1'
|
29
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
30
|
+
spec.add_development_dependency 'guard-rubocop', '~> 1.2'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
32
|
+
spec.add_development_dependency 'rake', '~> 11.2'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 0.46'
|
35
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.8'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: safeword
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wilson Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '11.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '11.2'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.5'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.5'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.46'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.46'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '1.8'
|
153
|
+
description: Prevents blocks of code from being executed until you consider them safe.
|
154
|
+
email:
|
155
|
+
- me@wilsonsilva.net
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".rubocop.yml"
|
163
|
+
- ".travis.yml"
|
164
|
+
- Gemfile
|
165
|
+
- Guardfile
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- bin/console
|
170
|
+
- bin/setup
|
171
|
+
- lib/safeword.rb
|
172
|
+
- lib/safeword/blocker.rb
|
173
|
+
- lib/safeword/version.rb
|
174
|
+
- safeword.gemspec
|
175
|
+
homepage: https://github.com/wilsonsilva/safeword
|
176
|
+
licenses:
|
177
|
+
- MIT
|
178
|
+
metadata: {}
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubyforge_project:
|
195
|
+
rubygems_version: 2.5.1
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: Prevents blocks of code from being executed until you consider them safe.
|
199
|
+
test_files: []
|