carefully 0.1.0 → 0.1.1
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/README.md +16 -3
- data/lib/carefully.rb +31 -27
- data/lib/carefully/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bdb0fe9d45c15d6fec870b034ed91cbfcc4aeadf
|
|
4
|
+
data.tar.gz: ecedb980544f300bda15e4b20c0f68cf334c5f43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0651495c0c88bdffb859a50ffaf9a111819fd2351423040841f8380f810e8f6e157b3656b0f3e8910ed618de004889978ed117be23b72dfa760485956b92c152'
|
|
7
|
+
data.tar.gz: 133354fe53e545f31f3b304e4664bafb485054d0e1e6ead674608be8c0217ac64cdb0b1c0b7bb4d80f1f6709b614c5765b3d32b5297a701545ec20972cc7d128
|
data/README.md
CHANGED
|
@@ -4,12 +4,12 @@ Additional layer of security when performing actions through rails console in se
|
|
|
4
4
|
|
|
5
5
|
### Installation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
```
|
|
7
|
+
Add to Gemfile
|
|
8
|
+
```ruby
|
|
9
9
|
gem 'carefully'
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Run from terminal
|
|
13
13
|
```
|
|
14
14
|
rails g carefully
|
|
15
15
|
```
|
|
@@ -25,3 +25,16 @@ include Carefully
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
You might as well include it in your ActiveRecord::Base wrapper class (like ApplicationRecord) to have it for all models.
|
|
28
|
+
|
|
29
|
+
#### Disabling the prompt
|
|
30
|
+
|
|
31
|
+
You can disable the prompting for blocks like this:
|
|
32
|
+
```ruby
|
|
33
|
+
Carefully.allow_all do
|
|
34
|
+
this.destroy
|
|
35
|
+
that.destroy
|
|
36
|
+
everything.destroy
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
None of these actions will require to be confirmed this way.
|
data/lib/carefully.rb
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
module Carefully
|
|
2
2
|
def self.included(base)
|
|
3
3
|
base.instance_eval do
|
|
4
|
-
def destroy_all
|
|
5
|
-
return super unless Carefully.configuration.enabled?
|
|
6
|
-
|
|
7
|
-
Carefully.confirm_destructive_action && super
|
|
8
|
-
end
|
|
9
|
-
|
|
10
4
|
def delete_all
|
|
11
|
-
return super
|
|
5
|
+
return super if Carefully.configuration.disabled?
|
|
12
6
|
|
|
13
|
-
Carefully.confirm_destructive_action && super
|
|
7
|
+
Carefully.confirm_destructive_action(:delete_all) && super
|
|
14
8
|
end
|
|
15
9
|
|
|
16
|
-
def delete(
|
|
17
|
-
|
|
18
|
-
return super unless Carefully.configuration.enabled?
|
|
10
|
+
def delete(ids)
|
|
11
|
+
return super if Carefully.configuration.disabled?
|
|
19
12
|
|
|
20
|
-
Carefully.confirm_destructive_action && super
|
|
13
|
+
Carefully.confirm_destructive_action(:delete) && super
|
|
21
14
|
end
|
|
22
15
|
end
|
|
23
16
|
end
|
|
@@ -34,29 +27,35 @@ module Carefully
|
|
|
34
27
|
configuration.set_enabled
|
|
35
28
|
end
|
|
36
29
|
|
|
37
|
-
def self.
|
|
30
|
+
def self.allow_all
|
|
31
|
+
begin
|
|
32
|
+
Carefully.configuration.instance_variable_set :@enabled, false
|
|
33
|
+
yield
|
|
34
|
+
ensure
|
|
35
|
+
Carefully.configuration.set_enabled
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.confirm_destructive_action(method_name)
|
|
38
40
|
puts Carefully.configuration.confirmation_message
|
|
39
41
|
print '> '
|
|
40
42
|
|
|
41
|
-
if gets.chomp == Carefully.configuration.confirmation_text
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
false
|
|
46
|
-
end
|
|
43
|
+
return true if gets.chomp == Carefully.configuration.confirmation_text
|
|
44
|
+
|
|
45
|
+
puts "\"#{method_name}\" aborted!"
|
|
46
|
+
false
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def
|
|
50
|
-
return super
|
|
51
|
-
return super if caller_locations(1, 10).map(&:label).include? 'destroy_all'
|
|
49
|
+
def delete
|
|
50
|
+
return super if Carefully.configuration.disabled?
|
|
52
51
|
|
|
53
|
-
Carefully.confirm_destructive_action && super
|
|
52
|
+
Carefully.confirm_destructive_action(:delete) && super
|
|
54
53
|
end
|
|
55
54
|
|
|
56
|
-
def
|
|
57
|
-
return super
|
|
55
|
+
def destroy
|
|
56
|
+
return super if Carefully.configuration.disabled?
|
|
58
57
|
|
|
59
|
-
Carefully.confirm_destructive_action && super
|
|
58
|
+
Carefully.confirm_destructive_action(:destroy) && super
|
|
60
59
|
end
|
|
61
60
|
|
|
62
61
|
private
|
|
@@ -66,7 +65,7 @@ module Carefully
|
|
|
66
65
|
|
|
67
66
|
def initialize
|
|
68
67
|
self.protected_environments = [:production, :demo, :staging]
|
|
69
|
-
self.confirmation_message =
|
|
68
|
+
self.confirmation_message = "You are performing destructive actions in #{Rails.env} environment. Do you want to continue?"
|
|
70
69
|
self.confirmation_text = 'yes'
|
|
71
70
|
end
|
|
72
71
|
|
|
@@ -78,6 +77,10 @@ module Carefully
|
|
|
78
77
|
!!@enabled
|
|
79
78
|
end
|
|
80
79
|
|
|
80
|
+
def disabled?
|
|
81
|
+
!@enabled
|
|
82
|
+
end
|
|
83
|
+
|
|
81
84
|
private
|
|
82
85
|
|
|
83
86
|
def protected_environment?
|
|
@@ -86,6 +89,7 @@ module Carefully
|
|
|
86
89
|
|
|
87
90
|
def rails_console?
|
|
88
91
|
defined?(Rails::Console)
|
|
92
|
+
true
|
|
89
93
|
end
|
|
90
94
|
end
|
|
91
95
|
end
|
data/lib/carefully/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: carefully
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pauls Liepa
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-09-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|