Class: PackageJson::Managers::Base
- Inherits:
-
Object
- Object
- PackageJson::Managers::Base
- Defined in:
- lib/package_json/managers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#binary ⇒ String
readonly
The binary to invoke for running the package manager.
Instance Method Summary collapse
-
#add(packages, type: :production) ⇒ Object
Adds the given packages.
-
#add!(packages, type: :production) ⇒ Object
Adds the given packages.
-
#initialize(package_json, binary_name:) ⇒ Base
constructor
A new instance of Base.
-
#install(frozen: false) ⇒ Object
Installs the dependencies specified in the ‘package.json` file.
-
#install!(frozen: false) ⇒ Object
Installs the dependencies specified in the ‘package.json` file.
-
#native_exec_command(script_name, args = []) ⇒ Object
Provides the “native” command for executing a package with args for embedding into shell scripts.
-
#native_install_command(frozen: false) ⇒ Object
Provides the “native” command for installing dependencies with this package manager for embedding into scripts.
-
#native_run_command(script_name, args = [], silent: false) ⇒ Object
Provides the “native” command for running the script with args for embedding into shell scripts.
-
#remove(packages) ⇒ Object
Removes the given packages.
-
#remove!(packages) ⇒ Object
Removes the given packages.
-
#run(script_name, args = [], silent: false) ⇒ Object
Runs the script assuming it is defined in the ‘package.json` file.
-
#run!(script_name, args = [], silent: false) ⇒ Object
Runs the script assuming it is defined in the ‘package.json` file.
- #version ⇒ Object
Constructor Details
#initialize(package_json, binary_name:) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 |
# File 'lib/package_json/managers/base.rb', line 7 def initialize(package_json, binary_name:) # @type [PackageJson] @package_json = package_json # @type [String] @binary = binary_name end |
Instance Attribute Details
#binary ⇒ String (readonly)
Returns the binary to invoke for running the package manager.
5 6 7 |
# File 'lib/package_json/managers/base.rb', line 5 def binary @binary end |
Instance Method Details
#add(packages, type: :production) ⇒ Object
Adds the given packages
43 44 45 |
# File 'lib/package_json/managers/base.rb', line 43 def add(packages, type: :production) raise NotImplementedError end |
#add!(packages, type: :production) ⇒ Object
Adds the given packages
48 49 50 |
# File 'lib/package_json/managers/base.rb', line 48 def add!(packages, type: :production) raise_exited_with_non_zero_code_error unless add(packages, type: type) end |
#install(frozen: false) ⇒ Object
Installs the dependencies specified in the ‘package.json` file
28 29 30 |
# File 'lib/package_json/managers/base.rb', line 28 def install(frozen: false) raise NotImplementedError end |
#install!(frozen: false) ⇒ Object
Installs the dependencies specified in the ‘package.json` file
38 39 40 |
# File 'lib/package_json/managers/base.rb', line 38 def install!(frozen: false) raise_exited_with_non_zero_code_error unless install(frozen: frozen) end |
#native_exec_command(script_name, args = []) ⇒ Object
Provides the “native” command for executing a package with args for embedding into shell scripts
96 97 98 99 100 101 |
# File 'lib/package_json/managers/base.rb', line 96 def native_exec_command( script_name, args = [] ) raise NotImplementedError end |
#native_install_command(frozen: false) ⇒ Object
Provides the “native” command for installing dependencies with this package manager for embedding into scripts
33 34 35 |
# File 'lib/package_json/managers/base.rb', line 33 def native_install_command(frozen: false) raise NotImplementedError end |
#native_run_command(script_name, args = [], silent: false) ⇒ Object
Provides the “native” command for running the script with args for embedding into shell scripts
87 88 89 90 91 92 93 |
# File 'lib/package_json/managers/base.rb', line 87 def native_run_command( script_name, args = [], silent: false ) raise NotImplementedError end |
#remove(packages) ⇒ Object
Removes the given packages
53 54 55 |
# File 'lib/package_json/managers/base.rb', line 53 def remove(packages) raise NotImplementedError end |
#remove!(packages) ⇒ Object
Removes the given packages
58 59 60 61 62 |
# File 'lib/package_json/managers/base.rb', line 58 def remove!( packages ) raise_exited_with_non_zero_code_error unless remove(packages) end |
#run(script_name, args = [], silent: false) ⇒ Object
Runs the script assuming it is defined in the ‘package.json` file
65 66 67 68 69 70 71 |
# File 'lib/package_json/managers/base.rb', line 65 def run( script_name, args = [], silent: false ) raise NotImplementedError end |
#run!(script_name, args = [], silent: false) ⇒ Object
Runs the script assuming it is defined in the ‘package.json` file
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/package_json/managers/base.rb', line 74 def run!( script_name, args = [], silent: false ) raise_exited_with_non_zero_code_error unless run( script_name, args, silent: silent ) end |
#version ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/package_json/managers/base.rb', line 14 def version require "open3" command = "#{binary} --version" stdout, stderr, status = Open3.capture3(command, chdir: @package_json.directory) unless status.success? raise PackageJson::Error, "#{command} failed with exit code #{status.exitstatus}: #{stderr}" end stdout.chomp end |