Class: Rubyfocus::LocalFetcher

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/rubyfocus/fetchers/local_fetcher.rb

Instance Method Summary collapse

Methods inherited from Fetcher

#can_patch?, #can_reach_head_from?, #head, #next_patch, #reset, #update_full, #update_once

Instance Method Details

#appstore_locationObject

Default app-store file location



66
67
68
69
70
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 66

def appstore_location
  @appstore_location ||= File.join(ENV["HOME"],
                                    "/Library/Containers/com.omnigroup.OmniFocus2.MacAppStore",
                                    "Data/Library/Application Support/OmniFocus/OmniFocus.ofocus")
end

#baseObject

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")].first
    if zip_file
      Zip::File.open(zip_file){ |z| z.get_entry("contents.xml").get_input_stream.read }
    else
      raise RuntimeError, "Rubyfocs::LocalFetcher looking for zip files at #{self.location}: none found."
    end
  end
end

#base_idObject

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(Dir[File.join(self.location,"*.zip")].first)
  if base_file =~ /^\d+\=.*\+(.*)\.zip$/
    $1
  else
    raise RuntimeError, "Malformed patch file #{base_file}."
  end
end

#default_locationObject

Default (non app-store) file location



59
60
61
62
63
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 59

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



51
52
53
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 51

def encode_with(coder)
  coder.map = {"location" => @location}
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

#locationObject

Determine location based on assigned and default values. Returns nil if no assigned location and default locations don’t exist.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 74

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



86
87
88
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 86

def location= l
  @location = l
end

#patch(file) ⇒ Object

Fetches the contents of a given patch file



41
42
43
44
45
46
47
48
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 41

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

#patchesObject

Fetches a list of every patch file



36
37
38
# File 'lib/rubyfocus/fetchers/local_fetcher.rb', line 36

def patches
  @patches ||= Dir[File.join(self.location, "*.zip")][1..-1].map{ |f| Rubyfocus::Patch.new(self, File.basename(f)) }
end