class Arduino::Library::DefaultDatabase
This class represents a single entry into the library-index.json file, in other words — a `library.properties` file.
Attributes
library_index_path[RW]
library_index_url[RW]
library_path[RW]
url_size_cache[RW]
path[RW]
url[RW]
Public Class Methods
assign_defaults()
click to toggle source
# File lib/arduino/library/default_database.rb, line 26 def assign_defaults self.url_size_cache ||= {} self.library_index_path ||= DEFAULT_ARDUINO_LIBRARY_INDEX_PATH self.library_index_url ||= DEFAULT_ARDUINO_LIBRARY_INDEX_URL self.library_path ||= DEFAULT_ARDUINO_LIBRARY_PATH end
instance()
click to toggle source
# File lib/arduino/library/default_database.rb, line 18 def instance @default ||= self.send(:new) end
new()
click to toggle source
# File lib/arduino/library/default_database.rb, line 38 def initialize reload! end
reload!()
click to toggle source
# File lib/arduino/library/default_database.rb, line 22 def reload! instance.reload! end
Public Instance Methods
download_if_needed!()
click to toggle source
# File lib/arduino/library/default_database.rb, line 55 def download_if_needed! if File.exist?(path) remote_size = get_remote_size(url) local_size = File.size(path) debug("remote size: #{remote_size}, local size: #{local_size}") return if remote_size == local_size backup_previous_library(path) end download(url, path) end
get_remote_size(url)
click to toggle source
# File lib/arduino/library/default_database.rb, line 66 def get_remote_size(url) with_caching(url) do resp = HTTParty.head(url) resp['content-length'].to_i end end
reload!()
click to toggle source
# File lib/arduino/library/default_database.rb, line 42 def reload! self.url = self.class.library_index_url self.path = self.class.library_index_path FileUtils.mkpath(File.dirname(path)) download_if_needed! self.local_file = open_plain_or_gzipped(path) load_json end
with_caching(url) { || ... }
click to toggle source
# File lib/arduino/library/default_database.rb, line 73 def with_caching(url, &_block) @cache ||= self.class.url_size_cache @cache[url] ||= yield end