Class: ConvenientService::Common::Plugins::CanHaveUserProvidedEntity::Commands::FindOrCreateEntity Private

Inherits:
Support::Command
  • Object
show all
Defined in:
lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.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

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(namespace:, proto_entity:) ⇒ 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:

Since:

  • 1.0.0

API:

  • private



31
32
33
34
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 31

def initialize(namespace:, proto_entity:)
  @namespace = namespace
  @proto_entity = proto_entity
end

Instance Attribute Details

#namespaceObject (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

API:

  • private



18
19
20
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 18

def namespace
  @namespace
end

#proto_entityObject (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

API:

  • private



24
25
26
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 24

def proto_entity
  @proto_entity
end

Instance Method Details

#callvoid

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.

This method returns an undefined value.

Since:

  • 1.0.0

API:

  • private



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
97
98
99
# File 'lib/convenient_service/common/plugins/can_have_user_provided_entity/commands/find_or_create_entity.rb', line 39

def call
  ::ConvenientService.raise Exceptions::ProtoEntityHasNoName.new(proto_entity: proto_entity) unless proto_entity_name
  ::ConvenientService.raise Exceptions::ProtoEntityHasNoConcern.new(proto_entity: proto_entity) unless proto_entity_concern

  entity.include Core

  entity.include proto_entity_concern

  ##
  # @example Result for service.
  #
  #   klass = ConvenientService::Common::Plugins::CanHaveUserProvidedEntity::Commands::FindOrCreateEntity.call(
  #     namespace: SomeService,
  #     proto_entity: ConvenientService::Service::Plugins::HasJSendResult::Entities::Result
  #   )
  #
  #   ##
  #   # `klass` is something like:
  #   #
  #   # class Result < ConvenientService::Service::Plugins::HasJSendResult::Entities::Result # or just `class Result` if service (namespace) class defines its own.
  #   #   include ConvenientService::Service::Plugins::HasJSendResult::Entities::Result::Concern # (concern)
  #   #
  #   #   class << self
  #   #     def proto_entity
  #   #       ##
  #   #       # NOTE: Returns `proto_entity` passed to `FindOrCreateEntity`.
  #   #       #
  #   #       proto_entity
  #   #     end
  #   #
  #   #     def ==(other)
  #   #       return unless other.respond_to?(:proto_entity)
  #   #
  #   #       self.proto_entity == other.proto_entity
  #   #     end
  #   #   end
  #   # end
  #
  entity.class_exec(proto_entity) do |proto_entity|
    ##
    # @return [Class]
    #
    define_singleton_method(:proto_entity) { proto_entity }

    ##
    # @param other [Object] Can by any type.
    # @return [Boolean, nil]
    #
    # @internal
    #   TODO: Try `self.proto_entity == other.proto_entity if self < proto_entity_concern`.
    #
    define_singleton_method(:==) { |other| self.proto_entity == other.proto_entity if other.respond_to?(:proto_entity) }

    ##
    # TODO: `inspect`.
    #
    # define_singleton_method(:inspect) { "#{entity}(Prototyped by #{proto_entity})" }
  end

  entity
end