Class: ROM::ClassBuilder

Inherits:
Object
  • Object
show all
Includes:
Options
Defined in:
lib/rom/support/class_builder.rb

Overview

Internal support class for generating classes

Constant Summary

Constants included from Options

Options::InvalidOptionKeyError, Options::InvalidOptionValueError

Instance Attribute Summary

Attributes included from Options

#options

Instance Method Summary collapse

Methods included from Options

included, #initialize

Instance Method Details

#call {|klass| ... } ⇒ Class

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generate a class based on options

Examples:

builder = ROM::ClassBuilder.new(name: 'MyClass')

klass = builder.call
klass.name # => "MyClass"

Yields:

  • (klass)

Returns:

  • (Class)


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
# File 'lib/rom/support/class_builder.rb', line 24

def call
  klass = Class.new(parent)

  klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def self.name
      #{name.inspect}
    end

    def self.inspect
      name
    end

    def self.to_str
      name
    end

    def self.to_s
      name
    end
  RUBY

  yield(klass) if block_given?

  klass
end