Class: Scrub
- Inherits:
-
Object
- Object
- Scrub
- Defined in:
- lib/dnode/scrub.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
Instance Method Summary collapse
-
#initialize ⇒ Scrub
constructor
A new instance of Scrub.
- #scrub(args) ⇒ Object
- #unscrub(req, &block) ⇒ Object
Constructor Details
#initialize ⇒ Scrub
Returns a new instance of Scrub.
4 5 6 7 |
# File 'lib/dnode/scrub.rb', line 4 def initialize @callbacks = {} @last_id = 0 end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
9 10 11 |
# File 'lib/dnode/scrub.rb', line 9 def callbacks @callbacks end |
Instance Method Details
#scrub(args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dnode/scrub.rb', line 11 def scrub args callbacks = {} walked = Walk.new(args).walk do |node| if node.value.is_a? Proc then id = @last_id @last_id += 1 @callbacks[id] = node.value callbacks[id] = node.path.clone node.value = '[Function]' end end { :arguments => walked, :callbacks => callbacks } end |
#unscrub(req, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dnode/scrub.rb', line 25 def unscrub req, &block args = Walk.new(req['arguments']).walk do |node| path = node.path.map(&:to_s) pair = req['callbacks'].detect{ |_,p| p.map(&:to_s) == path } unless pair.nil? then id = pair.first node.value = block.call(id) end end end |