Sha256: 57310c2d9854b9f7dee1aeb456d1a2c57dd2545c7111f523557bfc9aa08f7a7c

Contents?: true

Size: 1.83 KB

Versions: 11

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Common
    module Plugins
      module HasInternals
        module Commands
          class CreateInternalsClass < Support::Command
            attr_reader :service_class

            def initialize(service_class:)
              @service_class = service_class
            end

            def call
              internals_class.include Entities::Internals::Concern

              ##
              # class Internals < ConvenientService::Common::Plugins::HasInternals::Entities::Internals # or just `class Internals` if service class defines its own.
              #   include ConvenientService::Common::Plugins::HasInternals::Entities::Internals::Concern
              #
              #   class << self
              #     def service_class
              #       ##
              #       # NOTE: Returns `service_class` passed to `CreateInternalsClass`.
              #       #
              #       service_class
              #     end
              #
              #     def ==(other)
              #       return unless other.instance_of?(self.class)
              #
              #       self.service_class == other.service_class
              #     end
              #   end
              # end
              #
              internals_class.class_exec(service_class) do |service_class|
                define_singleton_method(:service_class) { service_class }
                define_singleton_method(:==) { |other| self.service_class == other.service_class if other.instance_of?(self.class) }
              end

              internals_class
            end

            private

            def internals_class
              @internals_class ||= Utils::Module.get_own_const(service_class, :Internals) || ::Class.new(Entities::Internals)
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
convenient_service-0.9.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.8.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.7.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.6.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.5.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.4.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.3.1 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.3.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.2.1 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.2.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb
convenient_service-0.1.0 lib/convenient_service/common/plugins/has_internals/commands/create_internals_class.rb