Class: Dry::Initializer::Plugins::Base

Inherits:
Object
  • Object
show all
Includes:
Errors
Defined in:
lib/dry/initializer/plugins/base.rb

Overview

Base class for plugins

A plugin should has class method [.call] that takes argument name and settings and return a chunk of code for the #initialize method body.

Direct Known Subclasses

DefaultProc, Signature, TypeConstraint, VariableSetter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, settings) ⇒ Base

Initializes a builder with argument name and settings

Parameters:

  • name (#to_s)
  • settings (Hash<Symbol, Object>)


26
27
28
29
# File 'lib/dry/initializer/plugins/base.rb', line 26

def initialize(name, settings)
  @name     = name
  @settings = settings
end

Instance Attribute Details

#nameObject (readonly)



22
23
24
# File 'lib/dry/initializer/plugins/base.rb', line 22

def name
  @name
end

#settingsObject (readonly)



22
23
24
# File 'lib/dry/initializer/plugins/base.rb', line 22

def settings
  @settings
end

Class Method Details

.call(name, settings) ⇒ String, ...

Builds the proc for the ‘after_initializer` callback

Parameters:

  • name (#to_s)
  • settings (Hash<Symbol, Object>)

Returns:

  • (String, Proc, nil)


17
18
19
# File 'lib/dry/initializer/plugins/base.rb', line 17

def self.call(name, settings)
  new(name, settings).call
end

Instance Method Details

#==(other) ⇒ Boolean

Checks equality to another instance by name

Returns:

  • (Boolean)


33
34
35
# File 'lib/dry/initializer/plugins/base.rb', line 33

def ==(other)
  other.instance_of?(self.class) && (other.name == name)
end

#callString, ...

Builds a chunk of code

Returns:

  • (String, Proc, nil)


39
40
# File 'lib/dry/initializer/plugins/base.rb', line 39

def call
end

#renameObject

Returns the name for the attribute



44
45
46
# File 'lib/dry/initializer/plugins/base.rb', line 44

def rename
  @rename ||= settings[:option] ? (settings[:as] || name) : name
end