File: debug.rb

package info (click to toggle)
ruby-representable 3.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 896 kB
  • sloc: ruby: 6,432; makefile: 3
file content (77 lines) | stat: -rw-r--r-- 2,111 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module Representable
  module Debug
    def update_properties_from(doc, options, format)
      puts
      puts "[Deserialize]........."
      puts "[Deserialize] document #{doc.inspect}"
      super
    end

    def create_representation_with(doc, options, format)
      puts
      puts "[Serialize]........."
      puts "[Serialize]"
      super
    end

    def representable_map(*)
      super.tap do |arr|
        arr.collect { |bin| bin.extend(Binding) }
      end
    end

    module Binding
      def evaluate_option(name, *args, &block)
        puts "=====#{self[name]}" if name ==:prepare
        puts (evaled = self[name]) ?
          "                #evaluate_option [#{name}]: eval!!!" :
          "                #evaluate_option [#{name}]: skipping"
        value = super
        puts "                #evaluate_option [#{name}]: --> #{value}" if evaled
        puts "                #evaluate_option [#{name}]: -->= #{args.first}" if name == :setter
        value
      end

      def parse_pipeline(*)
        super.extend(Pipeline::Debug)
      end

      def render_pipeline(*)
        super.extend(Pipeline::Debug)
      end
    end
  end


  module Pipeline::Debug
    def call(input, options)
      puts "Pipeline#call: #{inspect}"
      puts "               input: #{input.inspect}"
      super
    end

    def evaluate(block, memo, options)
      block.extend(Pipeline::Debug) if block.is_a?(Collect)

      puts "  Pipeline   :   -> #{_inspect_function(block)} "
      super.tap do |res|
        puts "  Pipeline   :     result: #{res.inspect}"
      end
    end

    def inspect
      functions = collect do |func|
        _inspect_function(func)
      end.join(", ")
      "#{self.class.to_s.split("::").last}[#{functions}]"
    end

    # prints SkipParse instead of <Proc>. i know, i can make this better, but not now.
    def _inspect_function(func)
      return func.extend(Pipeline::Debug).inspect if func.is_a?(Collect)
      return func unless func.is_a?(Proc)
      File.readlines(func.source_location[0])[func.source_location[1]-1].match(/^\s+(\w+)/)[1]
    end
  end
end