Sha256: 1d76c762c4d9acda733b8a7ff1de0b35d963714b01f655d3a77ad3c0875f2915

Contents?: true

Size: 1.2 KB

Versions: 14

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

##
# Usage example:
#
#   ConvenientService::Examples::Standard::Gemfile::Services::AssertNpmPackageAvailable.result(name: "lodash")
#
module ConvenientService
  module Examples
    module Standard
      module Gemfile
        module Services
          class AssertNpmPackageAvailable
            include ConvenientService::Standard::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::RunShell, 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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.10.1 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.10.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.9.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.8.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.7.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.6.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.5.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.4.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.3.1 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.3.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.2.1 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.2.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb
convenient_service-0.1.0 lib/convenient_service/examples/standard/gemfile/services/assert_npm_package_available.rb