Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add global option to disable letters side effects

  • Loading branch information...
commit eeae2a3a36690abdc88bbdb3c85b35ef1d7c9718 1 parent c4befce
@davejacobs authored
View
9 README.md
@@ -60,6 +60,7 @@ Here are the methods, listed with any options that can be passed in to modify th
- `:message (string)`: Print out the specified message as the method is being called.
- `:line_no (boolean)`: Print out the line number where a method is called as it is being called
+- `:disable (boolean)`: Disable this method's side effects
You can easily set these for an entire project using global configuration if you wish (see below).
@@ -203,3 +204,11 @@ Letters.config do
all :line_no => true
end
```
+
+To disable all Letters, for example if you're worried about them getting into a production environment:
+
+```ruby
+Letters.config do
+ all :disable => true
+end
+```
View
11 lib/letters/core_ext.rb
@@ -15,11 +15,14 @@ module CoreExt
def ubertap(letter, opts={}, orig_caller=[], &block)
full_opts = Letters.defaults_with(letter, opts)
- Helpers.message full_opts
- Helpers.print_line(orig_caller[0]) if full_opts[:line_no]
- tap do |o|
- block.call(o, full_opts)
+ unless full_opts[:disable]
+ Helpers.message full_opts
+ Helpers.print_line(orig_caller[0]) if full_opts[:line_no]
+
+ tap do |o|
+ block.call(o, full_opts)
+ end
end
end
View
10 spec/letters/config_spec.rb
@@ -40,6 +40,16 @@ module Letters
$stdout.should_receive(:puts).never
hash.b
end
+
+ it "allows disabling of all letters" do
+ Letters.config do
+ all :disable => true
+ b :line_no => true
+ end
+
+ $stdout.should_receive(:puts).never
+ hash.b
+ end
end
describe ".reset_config!" do
Please sign in to comment.
Something went wrong with that request. Please try again.