class Rubyfocus::LocalFetcher

Attributes

container_location[W]

Public Instance Methods

appstore_location() click to toggle source

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
base() click to toggle source

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
base_id() click to toggle source

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
container_location() click to toggle source

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_location() click to toggle source

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
encode_with(coder) click to toggle source

Save to disk

# File lib/rubyfocus/fetchers/local_fetcher.rb, line 56
def encode_with(coder)
        coder.map = {"location" => @location}
end
encrypted?() click to toggle source

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_with(coder) click to toggle source

Init from yaml

# File lib/rubyfocus/fetchers/local_fetcher.rb, line 7
def init_with(coder)
        if coder["location"]
                @location = coder["location"]
        end
end
location() click to toggle source

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
location=(l) click to toggle source
# File lib/rubyfocus/fetchers/local_fetcher.rb, line 149
def location= l
        @location = l
end
patch(file) click to toggle source

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
patches() click to toggle source

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

sorted_files() click to toggle source

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