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 "    def self.name\n      \#{name.inspect}\n    end\n\n    def self.inspect\n      name\n    end\n\n    def self.to_str\n      name\n    end\n\n    def self.to_s\n      name\n    end\n  RUBY\n\n  yield(klass) if block_given?\n\n  klass\nend\n", __FILE__, __LINE__ + 1