Class: QB::Labs::Atom::APM
- Inherits:
-
Object
- Object
- QB::Labs::Atom::APM
- Extended by:
- SingleForwardable
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/qb/labs/atom/apm.rb
Overview
TODO:
document QB::Atom::APM class.
Instance Attribute Summary collapse
-
#bin ⇒ String
readonly
What to use as the
apm
executable.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(bin: self.class.find_bin) ⇒ APM
constructor
Instantiate a new
QB::Atom::APM
. - #install(name:, force: false) ⇒ Object
- #installed?(package_name) ⇒ return_type
- #list ⇒ return_type
- #version(name:) ⇒ Object
Constructor Details
#initialize(bin: self.class.find_bin) ⇒ APM
Instantiate a new QB::Atom::APM
.
105 106 107 |
# File 'lib/qb/labs/atom/apm.rb', line 105 def initialize bin: self.class.find_bin @bin = bin end |
Instance Attribute Details
#bin ⇒ String (readonly)
What to use as the apm
executable.
97 98 99 |
# File 'lib/qb/labs/atom/apm.rb', line 97 def bin @bin end |
Class Method Details
.default ⇒ return_type
TODO:
Document default method.
Returns @todo Document return value.
61 62 63 |
# File 'lib/qb/labs/atom/apm.rb', line 61 def self.default @default ||= new end |
.find_bin ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/qb/labs/atom/apm.rb', line 66 def self.find_bin bin = ['apm-beta', 'apm'].find_map { |bin_name| which = Cmds.chomp 'which %s', bin_name if !which.empty? && File.executable?( which ) which end } if bin.nil? raise "Could not find apm bin!" end bin end |
Instance Method Details
#install(name:, force: false) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/qb/labs/atom/apm.rb', line 159 def install name:, force: false if current_version = self.version( name ) logger.info "Atom package #{ name } already installed", version: current_version return false unless force logger.info "Forcing installation..." end end |
#installed?(package_name) ⇒ return_type
TODO:
Document installed? method.
Returns @todo Document return value.
154 155 156 |
# File 'lib/qb/labs/atom/apm.rb', line 154 def installed? package_name list.key? t.non_empty_str.check( package_name ) end |
#list ⇒ return_type
TODO:
Document list method.
Returns @todo Document return value.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/qb/labs/atom/apm.rb', line 121 def list Cmds.out!( '%{bin} list --bare', bin: bin ). lines. each_with_object( {} ) do |line, packages| next if line =~ /\A\s+\z/ name, version = line.chomp.split( '@', 2 ) if [name, version].all? { |s| t.non_empty_str === s } packages[name] = version else logger.warn "Unable to parse `apm list --bare line`", line: line, name: name, version: version end end # each_with_object end |
#version(name:) ⇒ Object
141 142 143 |
# File 'lib/qb/labs/atom/apm.rb', line 141 def version name: list[t.non_empty_str.check( name )] end |