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

Inherits:
Support::Command
  • Object
show all
Defined in:
lib/convenient_service/common/plugins/has_instance_proxy/commands/create_instance_proxy_class.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(target_class:) ⇒ void

Parameters:

  • target_class (Class)


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

def initialize(target_class:)
  @target_class = target_class
end

Instance Attribute Details

#target_classObject (readonly)

Returns the value of attribute target_class.



13
14
15
# File 'lib/convenient_service/common/plugins/has_instance_proxy/commands/create_instance_proxy_class.rb', line 13

def target_class
  @target_class
end

Instance Method Details

#callvoid

This method returns an undefined value.



26
27
28
29
30
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
# File 'lib/convenient_service/common/plugins/has_instance_proxy/commands/create_instance_proxy_class.rb', line 26

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