Class: Booker::Parsers::Firefox

Inherits:
Base
  • Object
show all
Defined in:
lib/booker/parsers.rb

Overview

Firefox bookmark parser (SQLite format)

Class Attribute Summary collapse

Attributes inherited from Base

#allurls

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #results

Constructor Details

This class inherits a constructor from Booker::Parsers::Base

Class Attribute Details

.running=(value) ⇒ Object (writeonly)

"is firefox running" is a question about the machine, not about a profile, so a config naming three profiles asked pgrep three times - a fork each, and the slowest single thing booker did on that config



97
98
99
# File 'lib/booker/parsers.rb', line 97

def running=(value)
  @running = value
end

Class Method Details

.reset!Object

the memo outlives a single example, so the suite drops it between them



109
# File 'lib/booker/parsers.rb', line 109

def reset! = @running = nil

.running?Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
# File 'lib/booker/parsers.rb', line 99

def running?
  return @running unless @running.nil?

  out, _err, _status = Open3.capture3("pgrep", "-x", "firefox")
  @running = !out.strip.empty?
rescue
  @running = false
end

Instance Method Details

#parseObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/booker/parsers.rb', line 112

def parse
  begin
    require "sqlite3"
  rescue LoadError
    warn "Error: ".red + "sqlite3 gem not installed"
    warn "Run: ".grn + "gem install sqlite3"
    return
  end

  # Copy database to temp file if Firefox is running (to avoid lock).
  # Tempfile.create removes the copy when the block ends, so there is no
  # unlink left to remember in an ensure further down
  if firefox_running?
    require "tempfile"
    Tempfile.create(["places", ".sqlite"]) do |temp|
      temp.close
      FileUtils.cp(@file_path, temp.path)
      query_places(temp.path)
    end
  else
    query_places(@file_path)
  end
end