Class: Rubyfocus::LocalFetcher
- Defined in:
- lib/rubyfocus/fetchers/local_fetcher.rb
Instance Attribute Summary collapse
-
#container_location ⇒ Object
Where do we expect OS X to store containers?.
Instance Method Summary collapse
-
#appstore_location ⇒ Object
App store file location.
-
#base ⇒ Object
Fetches the contents of the base file.
-
#base_id ⇒ Object
Fetches the ID Of the base file.
-
#default_location ⇒ Object
Default (non app-store) file location.
-
#encode_with(coder) ⇒ Object
Save to disk.
-
#encrypted? ⇒ Boolean
Is this fetcher fetching encrypted data?.
-
#init_with(coder) ⇒ Object
Init from yaml.
-
#location ⇒ Object
Determine location based on assigned and default values.
- #location=(l) ⇒ Object
-
#patch(file) ⇒ Object
Fetches the contents of a given patch file.
-
#patches ⇒ Object
Fetches a list of every patch file.
Methods inherited from Fetcher
#can_patch?, #can_reach_head_from?, #head, #next_patch, #reset, #update_full, #update_once
Instance Attribute Details
#container_location ⇒ Object
Where do we expect OS X to store containers?
69 70 71 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 69 def container_location @container_location ||= File.join(ENV["HOME"], "Library/Containers/") end |
Instance Method Details
#appstore_location ⇒ Object
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`.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# 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 ⇒ Object
Fetches the contents of the base file
14 15 16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
Fetches the ID Of the base file
26 27 28 29 30 31 32 33 |
# 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 |
#default_location ⇒ Object
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`.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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) ⇒ Object
Save to disk
56 57 58 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 56 def encode_with(coder) coder.map = {"location" => @location} end |
#encrypted? ⇒ Boolean
Is this fetcher fetching encrypted data?
61 62 63 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 61 def encrypted? File.exists?(File.join(self.location, "encrypted")) end |
#init_with(coder) ⇒ Object
Init from yaml
7 8 9 10 11 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 7 def init_with(coder) if coder["location"] @location = coder["location"] end end |
#location ⇒ Object
Determine location based on assigned and default values. Returns nil if no assigned location and default locations don’t exist.
137 138 139 140 141 142 143 144 145 146 147 |
# 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) ⇒ Object
149 150 151 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 149 def location= l @location = l end |
#patch(file) ⇒ Object
Fetches the contents of a given patch file
46 47 48 49 50 51 52 53 |
# 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 |