Class: Amazon::Util::Binder
- Inherits:
-
Object
- Object
- Amazon::Util::Binder
- Defined in:
- lib/amazon/util/binder.rb
Overview
Simple class for holding eval information useful for feeding to ERB templates and the like
Instance Method Summary collapse
- #bind ⇒ Object
- #erb_eval(template) ⇒ Object
-
#initialize(initial = {}) {|_self| ... } ⇒ Binder
constructor
:yields: self.
- #merge(hash) ⇒ Object
-
#old_erb_eval(template) ⇒ Object
Helper method to simplify ERB evaluation.
- #set(k, v) ⇒ Object
Constructor Details
#initialize(initial = {}) {|_self| ... } ⇒ Binder
:yields: self
13 14 15 16 |
# File 'lib/amazon/util/binder.rb', line 13 def initialize(initial={},&block) # :yields: self initial.each {|k,v| set(k,v) } yield self unless block.nil? end |
Instance Method Details
#bind ⇒ Object
26 27 28 |
# File 'lib/amazon/util/binder.rb', line 26 def bind binding end |
#erb_eval(template) ⇒ Object
40 41 42 43 |
# File 'lib/amazon/util/binder.rb', line 40 def erb_eval( template ) t = ERB.new template return t.result(binding) end |
#merge(hash) ⇒ Object
18 19 20 |
# File 'lib/amazon/util/binder.rb', line 18 def merge(hash) hash.each {|k,v| set(k,v) } end |
#old_erb_eval(template) ⇒ Object
Helper method to simplify ERB evaluation
31 32 33 34 35 36 37 38 39 |
# File 'lib/amazon/util/binder.rb', line 31 def old_erb_eval( template ) buffer = "" c = ERB::Compiler.new("") c.put_cmd = "buffer <<" if c.respond_to? :put_cmd= c.insert_cmd = "buffer <<" if c.respond_to? :insert_cmd= compiled = c.compile template eval compiled return buffer end |
#set(k, v) ⇒ Object
22 23 24 |
# File 'lib/amazon/util/binder.rb', line 22 def set(k,v) self.instance_variable_set "@#{k.to_s}", "#{v.to_s}" end |