Class: DatabaseConsistency::ReportBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/database_consistency/report_builder.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.define(klass, *attrs) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/database_consistency/report_builder.rb', line 5

def self.define(klass, *attrs)
  Class.new(klass) do
    attr_reader(*attrs)

    class_eval(<<~DEF, __FILE__, __LINE__ + 1)
      def initialize(#{attrs.map { |attr| "#{attr}:" }.join(', ')}#{"," if attrs.any?} **opts)
        super(**opts) if opts.any?
        #{attrs.map { |attr| "@#{attr} = #{attr}" }.join("\n")}
      end

      def to_h
        h = defined?(super) ? super : {}
        #{attrs.map { |attr| "h[#{attr}] = #{attr}" }.join("\n")}
        h
      end
    DEF
  end
end