Class: Dry::Core::ClassBuilder
- Inherits:
-
Object
- Object
- Dry::Core::ClassBuilder
- Defined in:
- lib/dry/core/class_builder.rb
Overview
Class for generating more classes
Constant Summary collapse
- ParentClassMismatch =
Class.new(TypeError)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#call {|klass| ... } ⇒ Class
Generate a class based on options.
-
#initialize(name:, parent: nil, namespace: nil) ⇒ ClassBuilder
constructor
A new instance of ClassBuilder.
Constructor Details
#initialize(name:, parent: nil, namespace: nil) ⇒ ClassBuilder
Returns a new instance of ClassBuilder.
11 12 13 14 15 |
# File 'lib/dry/core/class_builder.rb', line 11 def initialize(name:, parent: nil, namespace: nil) @name = name @namespace = namespace @parent = parent || Object end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/dry/core/class_builder.rb', line 9 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
9 10 11 |
# File 'lib/dry/core/class_builder.rb', line 9 def namespace @namespace end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/dry/core/class_builder.rb', line 9 def parent @parent end |
Instance Method Details
#call {|klass| ... } ⇒ Class
Generate a class based on options
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dry/core/class_builder.rb', line 35 def call klass = if namespace create_named else create_anonymous end yield(klass) if block_given? klass end |