Sha256: 9e318006af88b8ca845377b559c4103ee73d9ea8cb4dbc7d4f4f0b6f3d006b14

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module EML
  class EndpointClass
    extend T::Sig

    def self.call(class_type:, resource_class:, endpoint:)
      new(
        class_type: class_type,
        resource_class: resource_class,
        endpoint: endpoint
      ).call
    end

    def initialize(class_type:, resource_class:, endpoint:)
      @class_type = class_type
      @resource_class = resource_class
      @endpoint = endpoint
    end

    def call
      Object.const_get(class_name) if Object.const_defined?(class_name)
    end

    private

    def class_name
      @class_name ||= begin
        name_parts = @resource_class.name.split("::")
        name = name_parts[0..-2] << @class_type
        name << name_parts.last
        name << action_class_name
        name.join("::")
      end
    end

    def action_class_name
      @endpoint.capitalize.sub(/s$/, "")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eml-2.0.0 lib/eml/lib/endpoint_class.rb
eml-1.0.0 lib/eml/lib/endpoint_class.rb