Class: Hashformer::Generate::Chain
- Inherits:
-
Object
- Object
- Hashformer::Generate::Chain
- Defined in:
- lib/hashformer/generate.rb
Overview
Internal representation of a method call and array lookup chainer. Do not use this directly; instead use HF::G.chain().
Defined Under Namespace
Modules: ReceiverMethods Classes: BasicReceiver, DebuggableReceiver
Instance Attribute Summary collapse
-
#receiver ⇒ Object
readonly
Returns the call chaining receiver for this chain.
Class Method Summary collapse
-
.disable_debugging ⇒ Object
Switches Receiver back to a BasicObject (BasicReceiver).
-
.enable_debugging ⇒ Object
Switches Receiver to an Object (DebuggableReceiver) for debugging.
-
.receiver_class ⇒ Object
The chaining receiver class that will be used by newly created chains (must include ReceiverMethods).
Instance Method Summary collapse
-
#<<(info) ⇒ Object
Adds the given call info (used by ReceiverMethods).
-
#call(input_hash) ⇒ Object
Applies the methods stored by #method_missing.
-
#initialize ⇒ Chain
constructor
Initializes an empty chain.
-
#to_s ⇒ Object
(also: #inspect)
Returns a String with the class name and a list of chained methods.
Constructor Details
#initialize ⇒ Chain
Initializes an empty chain.
188 189 190 191 192 |
# File 'lib/hashformer/generate.rb', line 188 def initialize @calls = [] @receiver = self.class.receiver_class.new @receiver.__chain = self end |
Instance Attribute Details
#receiver ⇒ Object (readonly)
Returns the call chaining receiver for this chain.
185 186 187 |
# File 'lib/hashformer/generate.rb', line 185 def receiver @receiver end |
Class Method Details
.disable_debugging ⇒ Object
Switches Receiver back to a BasicObject (BasicReceiver).
178 179 180 |
# File 'lib/hashformer/generate.rb', line 178 def disable_debugging @receiver_class = BasicReceiver end |
.enable_debugging ⇒ Object
Switches Receiver to an Object (DebuggableReceiver) for debugging. debugging tools to introspect Receiver without crashing.
173 174 175 |
# File 'lib/hashformer/generate.rb', line 173 def enable_debugging @receiver_class = DebuggableReceiver end |
.receiver_class ⇒ Object
The chaining receiver class that will be used by newly created chains (must include ReceiverMethods).
167 168 169 |
# File 'lib/hashformer/generate.rb', line 167 def receiver_class @receiver_class ||= BasicReceiver end |
Instance Method Details
#<<(info) ⇒ Object
Adds the given call info (used by ReceiverMethods).
209 210 211 212 |
# File 'lib/hashformer/generate.rb', line 209 def <<(info) @calls << info self end |
#call(input_hash) ⇒ Object
Applies the methods stored by #method_missing
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/hashformer/generate.rb', line 195 def call(input_hash) value = input_hash @calls.each do |c| if c[:name] value = value.send(c[:name], *c[:args], &c[:block]) else # Support #__as value = c[:block].call(value, *c[:args]) end end value end |
#to_s ⇒ Object Also known as: inspect
Returns a String with the class name and a list of chained methods.
215 216 217 |
# File 'lib/hashformer/generate.rb', line 215 def to_s "#{self.class.name}: #{@calls.map{|c| c[:name]}}" end |