Class: Arduino::Library::Database

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utilities
Defined in:
lib/arduino/library/database.rb

Overview

This class represents a single entry into the library-index.json file, in other words — a ‘library.properties` file.

Direct Known Subclasses

DefaultDatabase

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#backup_previous_library, #debug, #download, #open_plain_or_gzipped, #read_file_or_url, #short_time

Constructor Details

#initialize(file_or_url) ⇒ Database

Returns a new instance of Database.



27
28
29
30
# File 'lib/arduino/library/database.rb', line 27

def initialize(file_or_url)
  self.local_file = read_file_or_url(file_or_url)
  load_json
end

Instance Attribute Details

#db_listObject

Returns the value of attribute db_list.



24
25
26
# File 'lib/arduino/library/database.rb', line 24

def db_list
  @db_list
end

#local_fileObject

Returns the value of attribute local_file.



24
25
26
# File 'lib/arduino/library/database.rb', line 24

def local_file
  @local_file
end

Instance Method Details

#search(**opts) ⇒ Object

Usage: search(attr1: value, attr2: /regexp/, … )



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/arduino/library/database.rb', line 33

def search(**opts)
  limit = opts[:limit]
  opts.delete(:limit)
  match_list = []

  db_list.select do |entry|
    matches = entry_matches?(entry, opts)
    match_list << entry if matches
    break if limit && match_list.size >= limit
  end

  match_list.each { |entry| yield(entry) } if block_given?
  match_list
end