Module: Carefully
- Defined in:
- lib/carefully.rb,
lib/carefully/version.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
'0.1.2'
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
- .allow_all ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .confirm_destructive_action(method_name) ⇒ Object
- .included(base) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
19 20 21 |
# File 'lib/carefully.rb', line 19 def configuration @configuration end |
Class Method Details
.allow_all ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/carefully.rb', line 30 def self.allow_all begin Carefully.configuration.instance_variable_set :@enabled, false yield ensure Carefully.configuration.set_enabled end end |
.configure {|configuration| ... } ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/carefully.rb', line 22 def self.configure self.configuration ||= Configuration.new yield configuration if block_given? configuration.set_enabled end |
.confirm_destructive_action(method_name) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/carefully.rb', line 39 def self.confirm_destructive_action(method_name) puts Carefully.configuration. print '> ' return true if gets.chomp == Carefully.configuration.confirmation_text puts "\"#{method_name}\" aborted!" false end |
.included(base) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/carefully.rb', line 2 def self.included(base) base.instance_eval do def delete_all return super if Carefully.configuration.disabled? Carefully.confirm_destructive_action(:delete_all) && super end def delete(ids) return super if Carefully.configuration.disabled? Carefully.confirm_destructive_action(:delete) && super end end end |
Instance Method Details
#delete ⇒ Object
49 50 51 52 53 |
# File 'lib/carefully.rb', line 49 def delete return super if Carefully.configuration.disabled? Carefully.confirm_destructive_action(:delete) && super end |
#destroy ⇒ Object
55 56 57 58 59 |
# File 'lib/carefully.rb', line 55 def destroy return super if Carefully.configuration.disabled? Carefully.confirm_destructive_action(:destroy) && super end |