File: testing.rb

package info (click to toggle)
ruby-declarative 0.0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 256 kB
  • sloc: ruby: 595; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 952 bytes parent folder | download
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
module Declarative
  def self.Inspect(obj)
    obj.inspect
  end

  module Inspect
    def inspect
      string = super
      if is_a?(Proc)
        elements = string.split(/[:@ ]/)
        elements[2] = '@' + File.basename(elements[2])
        elements.delete_at(1)
        string = elements.join(':')
      end
      string.gsub(/0x\w+/, "")
    end

    module Schema
      def inspect
        definitions.extend(Definitions::Inspect)
        "Schema: #{definitions.inspect}"
      end
    end
  end

  module Definitions::Inspect
    def inspect
      each { |dfn|
        dfn.extend(Declarative::Inspect)

        if dfn[:nested] && dfn[:nested].is_a?(Declarative::Schema::DSL)
          dfn[:nested].extend(Declarative::Inspect::Schema)
        else
          dfn[:nested].extend(Declarative::Definitions::Inspect) if dfn[:nested]
        end
      }
      super
    end

    def get(*)
      super.extend(Declarative::Inspect)
    end
  end
end