Sha256: e07004937f37b0ad62c7a74d502057438704e828a86157ea1256fb6e00db26cb

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Examples
    module Rails
      class Gemfile
        module Services
          class RunShellCommand
            include RailsService::Config

            attribute :command, :string
            attribute :debug, :boolean, default: false

            validates :command, presence: true if ConvenientService::Dependencies.support_has_j_send_result_params_validations_using_active_model_validations?

            step Services::PrintShellCommand,
              in: [:command, {skip: -> { !debug }}],
              fallback: true

            step :result,
              in: :command

            def result
              ##
              # NOTE: When the command exit code is 0, `system` return `true`, and `false` otherwise.
              # - https://ruby-doc.org/core-3.1.2/Kernel.html#method-i-system
              # - https://stackoverflow.com/a/37329716/12201472
              #
              if system(command)
                success
              else
                error("#{command} returned non-zero exit code")
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
convenient_service-0.17.0 lib/convenient_service/examples/rails/gemfile/services/run_shell_command.rb
convenient_service-0.16.0 lib/convenient_service/examples/rails/gemfile/services/run_shell_command.rb
convenient_service-0.15.0 lib/convenient_service/examples/rails/gemfile/services/run_shell_command.rb
convenient_service-0.14.0 lib/convenient_service/examples/rails/gemfile/services/run_shell_command.rb