class RShade::Formatter::Json
Attributes
event_store[R]
Public Class Methods
new(event_store)
click to toggle source
# File lib/rshade/formatter/json.rb, line 6 def initialize(event_store) @event_store = event_store end
Public Instance Methods
call()
click to toggle source
# File lib/rshade/formatter/json.rb, line 10 def call flat end
flat()
click to toggle source
# File lib/rshade/formatter/json.rb, line 14 def flat arr = [] event_store.iterate do |node, depth| arr << item(node) end arr.sort_by { |item| item[:depth]} end
hash_iterate(hash, depth)
click to toggle source
# File lib/rshade/formatter/json.rb, line 39 def hash_iterate(hash, depth) (0..depth).each do |lvl| unless hash[:inner] hash[:inner] = {} end hash = hash[:inner] end hash end
hierarchical()
click to toggle source
# File lib/rshade/formatter/json.rb, line 22 def hierarchical hash = {} event_store.iterate do |node, depth| ref = hash_iterate(hash, depth) ref[:data] = item(node) end sort_hash(hash) end
item(value)
click to toggle source
# File lib/rshade/formatter/json.rb, line 49 def item(value) { class: value.klass.to_s, method_name: value.method_name, full_path: "#{value.path}:#{value.lineno}", depth: value.depth, vars: value.vars } end
sort_hash(h)
click to toggle source
# File lib/rshade/formatter/json.rb, line 31 def sort_hash(h) {}.tap do |h2| h.sort.each do |k,v| h2[k] = v.is_a?(Hash) ? sort_hash(v) : v end end end