Class: Rubyfocus::LocalFetcher
- Defined in:
- lib/rubyfocus/fetchers/local_fetcher.rb
Instance Method Summary collapse
-
#appstore_location ⇒ Object
Default 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 Method Details
#appstore_location ⇒ Object
Default app-store file location
76 77 78 79 80 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 76 def appstore_location @appstore_location ||= File.join(ENV["HOME"], "/Library/Containers/com.omnigroup.OmniFocus2.MacAppStore", "Data/Library/Application Support/OmniFocus/OmniFocus.ofocus") 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
69 70 71 72 73 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 69 def default_location @default_location ||= File.join(ENV["HOME"], "/Library/Containers/com.omnigroup.OmniFocus2", "Data/Library/Application Support/OmniFocus/OmniFocus.ofocus") 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.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 84 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
96 97 98 |
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 96 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 |