summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-12-27 10:14:36 -0700
committermo khan <mo@mokhan.ca>2013-12-27 10:14:36 -0700
commit31da2f75460270239f9f7d805191db005d388ce2 (patch)
tree645400cfdafbb592625a9889f654416028deed73
parent65d46c9bbed1f0ffbaa0130b26ade395f357f6ae (diff)
add module to expose an objects binding.
-rw-r--r--lib/nasty.rb1
-rw-r--r--lib/nasty/binding_behaviour.rb7
-rw-r--r--spec/unit/binding_spec.rb16
3 files changed, 24 insertions, 0 deletions
diff --git a/lib/nasty.rb b/lib/nasty.rb
index 35b89ea..f73cdee 100644
--- a/lib/nasty.rb
+++ b/lib/nasty.rb
@@ -1,4 +1,5 @@
require "nasty/background_job"
+require "nasty/binding_behaviour"
require "nasty/command"
require "nasty/composite_command"
require "nasty/kernel"
diff --git a/lib/nasty/binding_behaviour.rb b/lib/nasty/binding_behaviour.rb
new file mode 100644
index 0000000..d043be0
--- /dev/null
+++ b/lib/nasty/binding_behaviour.rb
@@ -0,0 +1,7 @@
+module Nasty
+ module BindingBehaviour
+ def get_binder
+ binding
+ end
+ end
+end
diff --git a/spec/unit/binding_spec.rb b/spec/unit/binding_spec.rb
new file mode 100644
index 0000000..5b51d08
--- /dev/null
+++ b/spec/unit/binding_spec.rb
@@ -0,0 +1,16 @@
+require "spec_helper"
+
+module Nasty
+ describe BindingBehaviour do
+ it "exposes an objects private binding" do
+ item = Object.new
+ item.instance_eval do
+ @message = "secret"
+ end
+ item.extend(Nasty::BindingBehaviour)
+ binding = item.get_binder
+ result = ERB.new("<%= @message %>").result(binding)
+ result.should == "secret"
+ end
+ end
+end