Sha256: 9240654af1c1e14b5094d89d50113e14a401a14293f31f6012b0734deaecd86d

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

# rubocop:disable Naming/FileName
# rubocop:enable Naming/FileName
# frozen_string_literal: true

module EasyCommand
  class Result
    module ClassMethods
      ruby2_keywords def [](*args)
        new(*args)
      end
    end
    extend ClassMethods
  end

  module ClassMethods
    ruby2_keywords def call(*args)
      new(*args).call
    end
  end

  ruby2_keywords def abort(*args)
    errors.add(*args)
    raise ExitError
  end

  module LegacyErrorHandling
    # Convenience/retrocompatibility aliases
    def self.errors_legacy_alias(method, errors_method)
      ruby2_keywords define_method(method) { |*args|
        warn "/!\\ #{method} is deprecated, please use errors.#{errors_method} instead."
        errors.__send__ errors_method, *args
      }
    end
  end

  ruby2_keywords def assert_subcommand(klass, *args)
    command_instance = klass.new(*args).as_sub_command
    (@sub_commands ||= []) << command_instance
    command = command_instance.call
    return command.result if command.success?
    errors.merge_from(command)
    raise ExitError.new(result: command.result)
  end

  def assert_sub(...)
    warn "/!\\ 'assert_sub' is deprecated, please use 'assert_subcommand' instead."
    assert_subcommand(...)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
easy_command-1.0.1 lib/easy_command/ruby-2-7-specific.rb
easy_command-1.0.0 lib/easy_command/ruby-2-7-specific.rb
easy_command-1.0.0.pre.rc3 lib/easy_command/ruby-2-7-specific.rb
easy_command-1.0.0.pre.rc2 lib/easy_command/ruby-2-7-specific.rb
easy_command-1.0.0.pre.rc1 lib/easy_command/ruby-2-7-specific.rb