Class: Scribbler::Context
- Inherits:
-
Object
- Object
- Scribbler::Context
- Defined in:
- lib/scribble-client/scribbler.rb
Instance Method Summary collapse
-
#add(hash) ⇒ Object
Merges the supplied key-value pairs into the context.
- #apply_context ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(&block) ⇒ Context
constructor
Can optionally be initialized/reset with starting context data supplied via a block.
- #reset! ⇒ Object
Constructor Details
#initialize(&block) ⇒ Context
Can optionally be initialized/reset with starting context data supplied via a block
93 94 95 96 97 98 |
# File 'lib/scribble-client/scribbler.rb', line 93 def initialize(&block) @contexts = Hash.new() @init_proc = block reset! end |
Instance Method Details
#add(hash) ⇒ Object
Merges the supplied key-value pairs into the context
102 103 104 105 106 |
# File 'lib/scribble-client/scribbler.rb', line 102 def add(hash) hash.each_pair { |k,v| @contexts[k] = v } end |
#apply_context ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/scribble-client/scribbler.rb', line 113 def apply_context() ret = {} @contexts.each_pair { |k,v| ret[k] = (v.is_a? Proc) ? (v.call self) : v } ret.empty? ? nil : ret end |
#empty? ⇒ Boolean
121 122 123 |
# File 'lib/scribble-client/scribbler.rb', line 121 def empty? @contexts.empty? end |
#reset! ⇒ Object
108 109 110 111 |
# File 'lib/scribble-client/scribbler.rb', line 108 def reset! @contexts.clear add(@init_proc.call) if(@init_proc) end |