class Rubyfocus::LocalFetcher
Attributes
Public Instance Methods
App store file location. Will look for “com.omnigroup.Omnifocus###.MacAppStore” (where ### is a number) and pick the most recent.
If it cannot find any directories matching this pattern, will return “” (empty string). Note that File.exists?(“”) returns `false`.
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 110 def appstore_location if @appstore_location.nil? omnifocus_directories = Dir[File.join(container_location, "com.omnigroup.OmniFocus*")] appstore_omnifocus_directories = omnifocus_directories.select{ |path| File.basename(path) =~ /com\.omnigroup\.OmniFocus\d+\.MacAppStore$/ } if (appstore_omnifocus_directories.size == 0) # If none match the regexp, we return "" @appstore_location = "" else # Otherwise, match highest last_omnifocus_directory = appstore_omnifocus_directories.sort().last() @appstore_location = File.join( last_omnifocus_directory, "Data/Library/Application Support/OmniFocus/OmniFocus.ofocus" ) end end return @appstore_location end
Fetches the contents of the base file
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 14 def base @base ||= begin zip_file = Dir[File.join(self.location,"*.zip")].sort.first if zip_file Zip::File.open(zip_file){ |z| z.get_entry("contents.xml").get_input_stream.read } else raise RuntimeError, "Rubyfocus::LocalFetcher looking for zip files at #{self.location}: none found." end end end
Fetches the ID Of the base file
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 26 def base_id base_file = File.basename(sorted_files.first) if base_file =~ /^\d+\=.*\+(.*)\.zip$/ $1 else raise RuntimeError, "Malformed patch file #{base_file}." end end
Where do we expect OS X to store containers?
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 69 def container_location @container_location ||= File.join(ENV["HOME"], "Library/Containers/") end
Default (non app-store) file location. Will look for “com.omnigroup.Omnifocus###” (where ### is a number) and pick the most recent.
If it cannot find any directories matching this pattern, will return “” (empty string). Note that File.exists?(“”) returns `false`.
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 80 def default_location if @default_location.nil? omnifocus_directories = Dir[File.join(container_location, "com.omnigroup.OmniFocus*")] default_omnifocus_directories = omnifocus_directories.select{ |path| File.basename(path) =~ /com\.omnigroup\.OmniFocus\d+$/ } if (default_omnifocus_directories.size == 0) # If none match the regexp, we return "" @default_location = "" else # Otherwise, match highest last_omnifocus_directory = default_omnifocus_directories.sort().last() @default_location = File.join( last_omnifocus_directory, "Data/Library/Application Support/OmniFocus/OmniFocus.ofocus" ) end end return @default_location end
Save to disk
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 56 def encode_with(coder) coder.map = {"location" => @location} end
Is this fetcher fetching encrypted data?
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 61 def encrypted? File.exists?(File.join(self.location, "encrypted")) end
Init from yaml
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 7 def init_with(coder) if coder["location"] @location = coder["location"] end end
Determine location based on assigned and default values. Returns nil
if no assigned location and default locations don't exist.
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 137 def location if @location @location elsif File.exists?(default_location) default_location elsif File.exists?(appstore_location) appstore_location else nil end end
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 149 def location= l @location = l end
Fetches the contents of a given patch file
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 46 def patch(file) filename = File.join(self.location, file) if File.exists?(filename) Zip::File.open(filename){ |z| z.get_entry("contents.xml").get_input_stream.read } else raise ArgumentError, "Trying to fetch patch #{file}, but file does not exist." end end
Fetches a list of every patch file
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 36 def patches @patches ||= sorted_files[1..-1].map{ |f| Rubyfocus::Patch.new(self, File.basename(f)) } end
Private Instance Methods
Fetch a sorted list of files from this directory
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 41 def sorted_files @sorted_files ||= Dir[File.join(self.location, "*.zip")].sort end