Class: RShade::Formatter::Json
Instance Attribute Summary collapse
-
#event_processor ⇒ Object
readonly
Returns the value of attribute event_processor.
Instance Method Summary collapse
- #call(event_store) ⇒ Object
- #flat ⇒ Object
- #hash_iterate(hash, depth) ⇒ Object
- #hierarchical ⇒ Object
- #item(value) ⇒ Object
- #sort_hash(h) ⇒ Object
Instance Attribute Details
#event_processor ⇒ Object (readonly)
Returns the value of attribute event_processor.
4 5 6 |
# File 'lib/rshade/formatter/json.rb', line 4 def event_processor @event_processor end |
Instance Method Details
#call(event_store) ⇒ Object
7 8 9 10 |
# File 'lib/rshade/formatter/json.rb', line 7 def call(event_store) @event_store = event_store flat end |
#flat ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/rshade/formatter/json.rb', line 12 def flat arr = [] event_store.each do |node| arr << item(node.event) end arr.sort_by { |item| item[:level]} end |
#hash_iterate(hash, depth) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/rshade/formatter/json.rb', line 38 def hash_iterate(hash, depth) (0..depth).each do |lvl| unless hash[:inner] hash[:inner] = {} end hash = hash[:inner] end hash end |
#hierarchical ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rshade/formatter/json.rb', line 20 def hierarchical hash = {} event_store.each do |node| depth = node.level ref = hash_iterate(hash, depth) ref[:data] = item(node) end sort_hash(hash) end |
#item(value) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/rshade/formatter/json.rb', line 48 def item(value) { class: value.klass.to_s, method_name: value.method_name, full_path: "#{value.path}:#{value.lineno}", level: value.depth, vars: value.vars } end |
#sort_hash(h) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rshade/formatter/json.rb', line 30 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 |