Permalink
Browse files

add global option to disable letters side effects

  • Loading branch information...
1 parent c4befce commit eeae2a3a36690abdc88bbdb3c85b35ef1d7c9718 @davejacobs committed Jul 11, 2013
Showing with 26 additions and 4 deletions.
  1. +9 −0 README.md
  2. +7 −4 lib/letters/core_ext.rb
  3. +10 −0 spec/letters/config_spec.rb
View
@@ -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
+```
@@ -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
@@ -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

0 comments on commit eeae2a3

Please sign in to comment.