Class: ConvenientService::Support::DependencyContainer::Entities::Method Private

Inherits:
Object
  • Object
show all
Includes:
Copyable
Defined in:
lib/convenient_service/support/dependency_container/entities/method.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.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Copyable

#copy

Constructor Details

#initialize(slug:, scope:, body:, alias_slug: "") ⇒ void

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.

Parameters:

  • slug (String, Symbol)
  • scope (:instance, :class)
  • body (Proc)
  • alias_slug (String, Symbol) (defaults to: "")

Since:

  • 1.0.0



46
47
48
49
50
51
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 46

def initialize(slug:, scope:, body:, alias_slug: "")
  @slug = slug
  @scope = scope
  @body = body
  @alias_slug = alias_slug
end

Instance Attribute Details

#alias_slugObject (readonly)

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.

Since:

  • 1.0.0



37
38
39
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 37

def alias_slug
  @alias_slug
end

#bodyObject (readonly)

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.

Since:

  • 1.0.0



31
32
33
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 31

def body
  @body
end

#scopeObject (readonly)

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.

Since:

  • 1.0.0



25
26
27
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 25

def scope
  @scope
end

#slugObject (readonly)

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.

Since:

  • 1.0.0



19
20
21
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 19

def slug
  @slug
end

Instance Method Details

#==(other) ⇒ Boolean?

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.

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)

Since:

  • 1.0.0



107
108
109
110
111
112
113
114
115
116
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 107

def ==(other)
  return unless other.instance_of?(self.class)

  return false if slug != other.slug
  return false if scope != other.scope
  return false if body != other.body
  return false if alias_slug != other.alias_slug

  true
end

#define_in_module!(mod) ⇒ ConvenientService::Support::DependencyContainer::Entities::Method

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.

Parameters:

  • mod (Module)

Returns:

Since:

  • 1.0.0



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 71

def define_in_module!(mod)
  ##
  # NOTE: `innermost_namespace` is just `mod`, when `namespaces` are empty.
  #
  innermost_namespace =
    namespaces.reduce(mod) do |namespace, sub_namespace|
      already_defined_sub_namespace = namespace.namespaces.find_by(name: sub_namespace.name)

      ##
      # NOTE:
      #   - Reuses already defined namespace from previous "imports".
      #   - In contrast, same methods are always redefined.
      #
      next already_defined_sub_namespace if already_defined_sub_namespace

      namespace.namespaces << sub_namespace

      namespace.define_method(sub_namespace.name) { sub_namespace.body.call }

      sub_namespace
    end

  ##
  # NOTE:
  #   - Same methods are redefined.
  #   - In contrast, same namespaces are always reused.
  #
  innermost_namespace.define_method(name, &body)

  self
end

#nameSymbol

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.

Returns:

  • (Symbol)

Since:

  • 1.0.0



56
57
58
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 56

def name
  @name ||= alias_slug_parts.last || slug_parts.last
end

#namespacesArray<ConvenientService::Support::DependencyContainer::Entities::Namespace>

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.



63
64
65
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 63

def namespaces
  @namespaces ||= (alias_slug_parts.any? ? alias_slug_parts : slug_parts).slice(0..-2).map { |part| Entities::Namespace.new(name: part) }
end

#to_argumentsConvenientService::Support::Arguments

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.

Returns:

Since:

  • 1.0.0



128
129
130
131
132
133
134
135
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 128

def to_arguments
  Support::Arguments.new(
    slug: slug,
    scope: scope,
    body: body,
    alias_slug: alias_slug
  )
end

#to_kwargsHash{Symbol => 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.

Returns:

  • (Hash{Symbol => Object})

Since:

  • 1.0.0



121
122
123
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 121

def to_kwargs
  to_arguments.kwargs
end