Class: ConvenientService::Common::Plugins::HasInstanceProxy::Commands::CreateInstanceProxyClass Private

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

[], call

Constructor Details

#initialize(target_class:) ⇒ 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:

  • target_class (Class)

Since:

  • 1.0.0



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

def initialize(target_class:)
  @target_class = target_class
end

Instance Attribute Details

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



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

def target_class
  @target_class
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



31
32
33
34
35
36
37
38
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
# File 'lib/convenient_service/common/plugins/has_instance_proxy/commands/create_instance_proxy_class.rb', line 31

def call
  klass = ::Class.new(Entities::InstanceProxy)

  ##
  # @example Result for feature.
  #
  #   klass = ConvenientService::Common::Plugins::HasInstanceProxy::Commands::CreateInstanceProxyClass.call(
  #     target_class: SomeFeature
  #   )
  #
  #   ##
  #   # `klass` is something like:
  #   #
  #   # class InstanceProxy < ConvenientService::Service::Plugins::HasInstanceProxy::Entities::InstanceProxy
  #   #   class << self
  #   #     def target_class
  #   #       ##
  #   #       # NOTE: Returns `target_class` passed to `CreateInstanceProxyClass`.
  #   #       #
  #   #       target_class
  #   #     end
  #   #
  #   #     def ==(other)
  #   #       return unless other.respond_to?(:target_class)
  #   #
  #   #       self.target_class == other.target_class
  #   #     end
  #   #   end
  #   # end
  #
  klass.class_exec(target_class) do |target_class|
    ##
    # @return [Class]
    #
    define_singleton_method(:target_class) { target_class }

    ##
    # @return [Boolean, nil]
    #
    # @internal
    #   TODO: Try `self.target_class == other.target_class if self < ::ConvenientService::Common::Plugins::HasInstanceProxy::Entities::InstanceProxy`.
    #
    define_singleton_method(:==) { |other| self.target_class == other.target_class if other.respond_to?(:target_class) }

    ##
    # @return [String]
    #
    define_singleton_method(:inspect) { "#{target_class}::InstanceProxy" }
  end

  klass
end