Sha256: 7d1a0883aa49754b78e823631d08a561f0c63b47a5c1ef3d9ffed3a930c44e38

Contents?: true

Size: 1.79 KB

Versions: 5

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Service
    module Plugins
      module HasResultSteps
        module Entities
          class Method
            module Commands
              ##
              # TODO: Replace `CastMethodKey`, `CastMethodName`, `CastMethodCaller` by declarative caster?
              #
              class CastMethodCaller < Support::Command
                attr_reader :other, :options

                def initialize(other:, options:)
                  @other = other
                  @options = options
                end

                def call
                  case other
                  when ::Symbol then cast_symbol
                  when ::String then cast_string
                  when ::Hash then cast_hash
                  when Method then cast_method
                  end
                end

                private

                def cast_symbol
                  Entities::Callers::Usual.new(other)
                end

                def cast_string
                  Entities::Callers::Usual.new(other)
                end

                def cast_hash
                  return unless other.keys.one?

                  value = other.values.first

                  case value
                  when ::Symbol
                    Entities::Callers::Alias.new(value)
                  when ::String
                    Entities::Callers::Alias.new(value)
                  when ::Proc
                    Entities::Callers::Proc.new(value)
                  when Entities::Values::Raw
                    Entities::Callers::Raw.new(value)
                  end
                end

                def cast_method
                  other.caller.copy
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
convenient_service-0.3.1 lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb
convenient_service-0.3.0 lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb
convenient_service-0.2.1 lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb
convenient_service-0.2.0 lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb
convenient_service-0.1.0 lib/convenient_service/service/plugins/has_result_steps/entities/method/commands/cast_method_caller.rb