Class: Arduino::Library::DefaultDatabase
- Defined in:
- lib/arduino/library/default_database.rb
Overview
This class represents a single entry into the library-index.json file, in other words — a ‘library.properties` file.
Class Attribute Summary collapse
-
.library_index_path ⇒ Object
Returns the value of attribute library_index_path.
-
.library_index_url ⇒ Object
Returns the value of attribute library_index_url.
-
.library_path ⇒ Object
Returns the value of attribute library_path.
-
.url_size_cache ⇒ Object
Returns the value of attribute url_size_cache.
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#url ⇒ Object
Returns the value of attribute url.
Attributes inherited from Database
Class Method Summary collapse
Instance Method Summary collapse
- #download_if_needed! ⇒ Object
- #get_remote_size(url) ⇒ Object
-
#initialize ⇒ DefaultDatabase
constructor
A new instance of DefaultDatabase.
- #reload! ⇒ Object
- #with_caching(url, &_block) ⇒ Object
Methods inherited from Database
Methods included from Utilities
#backup_previous_library, #debug, #download, #open_plain_or_gzipped, #read_file_or_url, #short_time
Constructor Details
#initialize ⇒ DefaultDatabase
Returns a new instance of DefaultDatabase.
38 39 40 |
# File 'lib/arduino/library/default_database.rb', line 38 def initialize reload! end |
Class Attribute Details
.library_index_path ⇒ Object
Returns the value of attribute library_index_path.
13 14 15 |
# File 'lib/arduino/library/default_database.rb', line 13 def library_index_path @library_index_path end |
.library_index_url ⇒ Object
Returns the value of attribute library_index_url.
13 14 15 |
# File 'lib/arduino/library/default_database.rb', line 13 def library_index_url @library_index_url end |
.library_path ⇒ Object
Returns the value of attribute library_path.
13 14 15 |
# File 'lib/arduino/library/default_database.rb', line 13 def library_path @library_path end |
.url_size_cache ⇒ Object
Returns the value of attribute url_size_cache.
13 14 15 |
# File 'lib/arduino/library/default_database.rb', line 13 def url_size_cache @url_size_cache end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
36 37 38 |
# File 'lib/arduino/library/default_database.rb', line 36 def path @path end |
#url ⇒ Object
Returns the value of attribute url.
36 37 38 |
# File 'lib/arduino/library/default_database.rb', line 36 def url @url end |
Class Method Details
.assign_defaults ⇒ Object
26 27 28 29 30 31 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/arduino/library/default_database.rb', line 18 def instance @default ||= self.send(:new) end |
.reload! ⇒ Object
22 23 24 |
# File 'lib/arduino/library/default_database.rb', line 22 def reload! instance.reload! end |
Instance Method Details
#download_if_needed! ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
66 67 68 69 70 71 |
# 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! ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# 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, &_block) ⇒ Object
73 74 75 76 |
# File 'lib/arduino/library/default_database.rb', line 73 def with_caching(url, &_block) @cache ||= self.class.url_size_cache @cache[url] ||= yield end |