Module: MyPrecious

Extended by:
Rake::DSL
Defined in:
lib/myprecious.rb,
lib/myprecious.rb,
lib/myprecious/cves.rb,
lib/myprecious/ruby_gems.rb,
lib/myprecious/data_caches.rb,
lib/myprecious/python_packages.rb

Overview

Declare the module here so it doesn’t cause problems for files in the “myprecious” directory (or does cause problems if they try to declare it a class)

Defined Under Namespace

Modules: CVEs, DataCaching, Reporting, URIModuleMethods Classes: ColumnOrder, GitInfoExtractor, LicenseDescription, MarkdownAdapter, PyPackageInfo, RubyGemInfo

Constant Summary collapse

DATA_DIR =
Pathname('~/.local/lib/myprecious').expand_path
ONE_DAY =
60 * 60 * 24
Program =
Rake::ToolkitProgram

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.caching_disabledObject

Returns the value of attribute caching_disabled.



5
6
7
# File 'lib/myprecious/data_caches.rb', line 5

def caching_disabled
  @caching_disabled
end

Class Method Details

.common_program_args(parser, args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/myprecious.rb', line 28

def self.common_program_args(parser, args)
  parser.on(
    '-o', '--out FILE',
    "Output file to generate",
  ) {|fpath| args.output_file = Pathname(fpath)}
  
  args.target = Pathname.pwd
  parser.on(
    '-C', '--dir PATH',
    "Path to inspect",
  ) do |fpath|
    fpath = Pathname(fpath)
    parser.invalid_args!("#{fpath} does not exist.") unless fpath.exist?
    args.target = fpath
    CVEs.config_dir = fpath
  end
  
  parser.on(
    '--[no-]cache',
    "Control caching of dependency information"
  ) {|v| MyPrecious.caching_disabled = v}
end

.data_cache(fpath) ⇒ Object

Declare a path as a data cache

This method returns the path it was given in fpath.



12
13
14
15
# File 'lib/myprecious/data_caches.rb', line 12

def data_cache(fpath)
  (@data_caches ||= []) << fpath
  return fpath
end

.data_cachesObject

Retrieve an Array of all known data caches



20
21
22
# File 'lib/myprecious/data_caches.rb', line 20

def data_caches
  (@data_caches || [])
end

.tracing_errors?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/myprecious.rb', line 24

def self.tracing_errors?
  !ENV['TRACE_ERRORS'].to_s.empty?
end

.yes_no(prompt) ⇒ Object

Prompt user for a yes/no answer

It doesn’t matter if they’ve redirected STDIN/STDOUT – this grabs the TTY directly.



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/myprecious.rb', line 169

def self.yes_no(prompt)
  Pathname('/dev/tty').open('r+') do |term|
    loop do
      term.write("#{prompt} ")
      case term.gets[0..-2]
      when 'y', 'Y', 'yes', 'Yes', 'YES'
        return true
      when 'n', 'N', 'no', 'No', 'NO'
        return false
      end
    end
  end
end