Class: Hanami::Components::Component Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/components/component.rb

Overview

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

Base component

See Also:

Since:

  • 0.9.0

Instance Method Summary collapse

Constructor Details

#initialize(name, &blk) ⇒ Hanami::Components::Component

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.

Instantiate a new component

Parameters:

  • name (String)

    the component name

  • blk (Proc)

    the logic of the component

Since:

  • 0.9.0


19
20
21
22
23
24
25
# File 'lib/hanami/components/component.rb', line 19

def initialize(name, &blk)
  @name         = name
  @requirements = []
  @_prepare     = ->(*) {}
  @_resolve     = -> {}
  instance_eval(&blk)
end

Instance Method Details

#call(configuration) ⇒ Object

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.

Run or resolve the component

Parameters:

Since:

  • 0.9.0


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hanami/components/component.rb', line 33

def call(configuration)
  resolve_requirements
  _prepare.call(configuration)

  unless _run.nil?
    _run.call(configuration)
    return
  end

  resolved(name, _resolve.call(configuration))
end