Sha256: 5b299b21f647257565250f52900f13ba931a3000d393a48495a84cb6f2f58205

Contents?: true

Size: 1008 Bytes

Versions: 4

Compression:

Stored size: 1008 Bytes

Contents

# frozen_string_literal: true

##
# Usage example:
#
#   ConvenientService::Examples::Rails::Gemfile::Services::PrintShellCommand.result(command: "ls -a")
#
module ConvenientService
  module Examples
    module Rails
      class Gemfile
        module Services
          class PrintShellCommand
            include RailsService::Config

            attribute :command, :string
            attribute :skip, :boolean, default: false
            attribute :out, default: $stdout

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

            def result
              return failure("Printing of shell command `#{command}` is skipped") if skip

              out.puts

              out.puts ::Paint["$ #{command}", :blue, :bold]

              success
            end

            def fallback_failure_result
              success
            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/print_shell_command.rb
convenient_service-0.16.0 lib/convenient_service/examples/rails/gemfile/services/print_shell_command.rb
convenient_service-0.15.0 lib/convenient_service/examples/rails/gemfile/services/print_shell_command.rb
convenient_service-0.14.0 lib/convenient_service/examples/rails/gemfile/services/print_shell_command.rb