Sha256: 7c76f9a461f3f9e2687602320905f01c9244abe602041fb895f5a73476356fd6

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

##
# Usage example:
#
#   ConvenientService::Examples::Standard::V1::Gemfile::Services::AssertNpmPackageAvailable.result(name: "lodash")
#
module ConvenientService
  module Examples
    module Standard
      module V1
        class Gemfile
          module Services
            class AssertNpmPackageAvailable
              include ConvenientService::Standard::V1::Config

              attr_reader :name

              step :validate_name

              step Services::AssertNodeAvailable

              ##
              # NOTE: `> /dev/null 2>&1` is used to hide output.
              # https://unix.stackexchange.com/a/119650/394253
              #
              # NOTE: For `npm list` and its options docs, see
              # https://docs.npmjs.com/cli/v7/commands/npm-ls
              #
              step Services::RunShellCommand, in: {command: -> { "npm list #{name} --depth=0 > /dev/null 2>&1" }}

              def initialize(name:)
                @name = name
              end

              private

              def validate_name
                return failure(name: "Name is `nil`") if name.nil?
                return failure(name: "Name is empty") if name.empty?

                success
              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/standard/v1/gemfile/services/assert_npm_package_available.rb
convenient_service-0.16.0 lib/convenient_service/examples/standard/v1/gemfile/services/assert_npm_package_available.rb
convenient_service-0.15.0 lib/convenient_service/examples/standard/v1/gemfile/services/assert_npm_package_available.rb
convenient_service-0.14.0 lib/convenient_service/examples/standard/v1/gemfile/services/assert_npm_package_available.rb