class Marquetapage::Runner
Execute sql command to sqlite
Public Class Methods
run(args)
click to toggle source
Execute query and output as json the result @example run() @param [ARGV] args must include a tag @return [Integer] Exit status
# File lib/marquetapage/runner.rb, line 11 def self.run(args) new.run(args) end
Public Instance Methods
run(args)
click to toggle source
Execute query and output as json the result @example run() @param [ARGV] args must include a tag @return [Integer] Exit status
# File lib/marquetapage/runner.rb, line 19 def run(args) raise ArgumentError unless args usage if args.empty? trap_interrupt @tag_name = args.first output_bookmarks end
Private Instance Methods
bookmark_place_ids()
click to toggle source
# File lib/marquetapage/runner.rb, line 73 def bookmark_place_ids Bookmark.distinct.select(:fk).where(parent: tag_id) end
bookmarks()
click to toggle source
# File lib/marquetapage/runner.rb, line 51 def bookmarks Place .select(:moz_places__url, :moz_bookmarks__title, :moz_items_annos__content) .from(:moz_places, :moz_bookmarks, :moz_items_annos, :moz_anno_attributes) .where(where_bookmarks_hash) end
output_bookmarks()
click to toggle source
# File lib/marquetapage/runner.rb, line 43 def output_bookmarks puts bookmarks.all.to_json @exit_status = 0 rescue Sequel::Error => e puts e @exit_status = 1 end
tag_id()
click to toggle source
# File lib/marquetapage/runner.rb, line 77 def tag_id Bookmark.where(moz_bookmarks__title: @tag_name).select(:id) end
trap_interrupt()
click to toggle source
Trac Ctrl-c and exit cleanly
# File lib/marquetapage/runner.rb, line 36 def trap_interrupt trap('INT') do STDERR.puts "\nExiting..." exit!(1) end end
usage()
click to toggle source
Print usage
# File lib/marquetapage/runner.rb, line 30 def usage puts 'Usage: marquetapage TAG' exit!(1) end
where_bookmarks_hash()
click to toggle source
# File lib/marquetapage/runner.rb, line 63 def where_bookmarks_hash { moz_anno_attributes__name: 'bookmarkProperties/description', moz_items_annos__anno_attribute_id: :moz_anno_attributes__id, moz_items_annos__item_id: :moz_bookmarks__id, moz_bookmarks__fk: :moz_places__id, moz_places__id: bookmark_place_ids } end