Module: Pakyow::Support::Makeable

Defined in:
lib/pakyow/support/makeable.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__object_nameObject (readonly)

Returns the value of attribute __object_name.



19
20
21
# File 'lib/pakyow/support/makeable.rb', line 19

def __object_name
  @__object_name
end

#__source_locationObject

Returns the value of attribute __source_location.



20
21
22
# File 'lib/pakyow/support/makeable.rb', line 20

def __source_location
  @__source_location
end

Class Method Details

.extended(base) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/pakyow/support/makeable.rb', line 11

def self.extended(base)
  # Mixin the `make` event for objects that are hookable.
  #
  if base.ancestors.include?(Hookable)
    base.events :make
  end
end

Instance Method Details

#make(object_name, within: nil, set_const: true, **kwargs, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pakyow/support/makeable.rb', line 22

def make(object_name, within: nil, set_const: true, **kwargs, &block)
  @__source_location = block&.source_location
  object_name = build_object_name(object_name, within: within)
  object = find_or_define_object(object_name, kwargs, set_const)

  local_eval_method = eval_method
  object.send(eval_method) do
    @__object_name = object_name
    send(local_eval_method, &block) if block_given?
  end

  if object.ancestors.include?(Hookable)
    object.call_hooks(:after, :make)
  end

  object
end