Class: ConvenientService::Support::DependencyContainer::Entities::Method
- Inherits:
-
Object
- Object
- ConvenientService::Support::DependencyContainer::Entities::Method
- Includes:
- Copyable
- Defined in:
- lib/convenient_service/support/dependency_container/entities/method.rb
Instance Attribute Summary collapse
-
#alias_slug ⇒ Object
readonly
Returns the value of attribute alias_slug.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #define_in_module!(mod) ⇒ ConvenientService::Support::DependencyContainer::Entities::Method
- #initialize(slug:, scope:, body:, alias_slug: "") ⇒ void constructor
- #name ⇒ Symbol
- #namespaces ⇒ Array<ConvenientService::Support::DependencyContainer::Entities::Namespace>
- #to_arguments ⇒ ConvenientService::Support::Arguments
- #to_kwargs ⇒ Hash{Symbol => Object}
Methods included from Copyable
Constructor Details
#initialize(slug:, scope:, body:, alias_slug: "") ⇒ void
41 42 43 44 45 46 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 41 def initialize(slug:, scope:, body:, alias_slug: "") @slug = slug @scope = scope @body = body @alias_slug = alias_slug end |
Instance Attribute Details
#alias_slug ⇒ Object (readonly)
Returns the value of attribute alias_slug.
32 33 34 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 32 def alias_slug @alias_slug end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
26 27 28 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 26 def body @body end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
20 21 22 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 20 def scope @scope end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
14 15 16 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 14 def slug @slug end |
Instance Method Details
#==(other) ⇒ Boolean
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 102 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
66 67 68 69 70 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 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 66 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 |
#name ⇒ Symbol
51 52 53 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 51 def name @name ||= alias_slug_parts.last || slug_parts.last end |
#namespaces ⇒ Array<ConvenientService::Support::DependencyContainer::Entities::Namespace>
58 59 60 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 58 def namespaces @namespaces ||= (alias_slug_parts.any? ? alias_slug_parts : slug_parts).slice(0..-2).map { |part| Entities::Namespace.new(name: part) } end |
#to_arguments ⇒ ConvenientService::Support::Arguments
123 124 125 126 127 128 129 130 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 123 def to_arguments Support::Arguments.new( slug: slug, scope: scope, body: body, alias_slug: alias_slug ) end |
#to_kwargs ⇒ Hash{Symbol => Object}
116 117 118 |
# File 'lib/convenient_service/support/dependency_container/entities/method.rb', line 116 def to_kwargs to_arguments.kwargs end |