Class: PStorePP::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pstore_pp.rb

Instance Method Summary collapse

Constructor Details

#initialize(libraries = []) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
# File 'lib/pstore_pp.rb', line 7

def initialize(libraries = [])
  Array(libraries).each do |l|
    require l
  end
end

Instance Method Details

#dump(file) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pstore_pp.rb', line 26

def dump(file)
  fail "Could not find file: #{file}" unless File.exist?(file)

  store = PStore.new(file)

  store.transaction(true) do
    store.roots.map do |key|
      [key, store[key]]
    end.to_h
  end
end

#start(args = ARGV) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pstore_pp.rb', line 13

def start(args = ARGV)
  args = Array(args)

  case args.size
  when 0
    fail 'Error - Missing file name.'
  when 1
    puts JSON.generate(dump(args.first))
  else
    puts JSON.generate(args.map { |file| { file => dump(file) } })
  end
end