Module: QB::Util
- Defined in:
- lib/qb/util.rb,
lib/qb/util/bundler.rb,
lib/qb/util/interop.rb,
lib/qb/util/resource.rb,
lib/qb/util/decorators.rb,
lib/qb/util/docker_mixin.rb
Defined Under Namespace
Modules: Bundler, Decorators, DockerMixin, Interop Classes: Resource
Class Method Summary collapse
-
.contract_path(path) ⇒ Pathname
do kind of the opposite of File.expand_path -- turn the home dir into ~ and the current dir into .
-
.find_up(filename, from = Pathname.pwd, raise_on_not_found: true) ⇒ Pathname?
find
filename
infrom
or closest parent directory. -
.resolve(*segments) ⇒ Pathname
Absolute resolved path.
-
.words(string) ⇒ Array<String>
Split a string into 'words' for word-based matching.
- .words_slice?(full_string, input, &is_match) ⇒ Boolean
-
.words_start_with?(full_string, input) ⇒ Boolean
see if words from an input match words.
Class Method Details
.contract_path(path) ⇒ Pathname
do kind of the opposite of File.expand_path -- turn the home dir into ~ and the current dir into .
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/qb/util.rb', line 55 def self.contract_path path contracted = if path.start_with? Dir.pwd path.sub Dir.pwd, '.' elsif path.start_with? ENV['HOME'] path.sub ENV['HOME'], '~' else path end Pathname.new contracted end |
.find_up(filename, from = Pathname.pwd, raise_on_not_found: true) ⇒ Pathname?
find filename
in from
or closest parent directory.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/qb/util.rb', line 94 def self.find_up filename, from = Pathname.pwd, raise_on_not_found: true path = from + filename return from if path.exist? parent = from.parent if from == parent if raise_on_not_found raise "not found in current or any parent directories: #{ filename }" else return nil end end return find_up filename, parent, raise_on_not_found: raise_on_not_found end |
.resolve(*segments) ⇒ Pathname
Returns absolute resolved path.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/qb/util.rb', line 34 def self.resolve *segments joined = Pathname.new '' ([Dir.pwd] + segments).reverse.each_with_index {|segment, index| joined = Pathname.new(segment).join joined return joined if joined.absolute? } # shouldn't ever happen raise "resolution failed: #{ segments.inspect }" end |
.words(string) ⇒ Array<String>
Split a string into 'words' for word-based matching
15 16 17 |
# File 'lib/qb/util.rb', line 15 def self.words string string.words end |
.words_slice?(full_string, input, &is_match) ⇒ Boolean
20 21 22 |
# File 'lib/qb/util.rb', line 20 def self.words_slice? full_string, input, &is_match full_string.words.slice? input.words, &is_match end |
.words_start_with?(full_string, input) ⇒ Boolean
see if words from an input match words
26 27 28 29 30 |
# File 'lib/qb/util.rb', line 26 def self.words_start_with? full_string, input words_slice? full_string, input do |full_string_word, input_word| full_string_word.start_with? input_word end end |