Class: Props::DebugWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/props_template/debug_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ DebugWriter

Returns a new instance of DebugWriter.



9
10
11
12
# File 'lib/props_template/debug_writer.rb', line 9

def initialize(opts)
  @stream = Oj::StringWriter.new(opts)
  @commands = []
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



7
8
9
# File 'lib/props_template/debug_writer.rb', line 7

def commands
  @commands
end

Instance Method Details

#popObject



34
35
36
# File 'lib/props_template/debug_writer.rb', line 34

def pop
  @commands.push([:pop])
end

#push_arrayObject



30
31
32
# File 'lib/props_template/debug_writer.rb', line 30

def push_array
  @commands.push([:push_array])
end

#push_key(key) ⇒ Object



18
19
20
# File 'lib/props_template/debug_writer.rb', line 18

def push_key(key)
  @commands.push([:push_key, key])
end

#push_objectObject



14
15
16
# File 'lib/props_template/debug_writer.rb', line 14

def push_object
  @commands.push([:push_object])
end

#push_value(value, key = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/props_template/debug_writer.rb', line 22

def push_value(value, key = nil)
  if key
    @commands.push([:push_value, value, key])
  else
    @commands.push([:push_value, value])
  end
end

#resetObject



38
39
40
41
# File 'lib/props_template/debug_writer.rb', line 38

def reset
  @commands = []
  @stream.reset
end

#to_sObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/props_template/debug_writer.rb', line 43

def to_s
  @commands.each do |command|
    begin
      @stream.send(*command)
    rescue => e
      byebug
    end
  end

  @stream.to_s
end