class ARPM::Package
Attributes
name[RW]
repository[RW]
versions[RW]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/arpm/package.rb, line 9 def initialize(opts = {}) opts.each { |k,v| instance_variable_set("@#{k}", v) } end
search(name, exact_match = true)
click to toggle source
Search for a new package
# File lib/arpm/package.rb, line 14 def self.search(name, exact_match = true) # Grab the package list data = URI.parse("https://raw.githubusercontent.com/alfo/arpm/master/packages.json").read packages = JSON.parse(data) if exact_match # Search the packages for one with the same name remote_packages = packages.select { |p| p['name'] == name } else # Search for packages with similar names and return them remote_packages = packages.select { |p| p['name'].include? name } end # Did the search return any results? if remote_packages.any? packages = [] remote_packages.each do |remote_package| # Get a list of tags from the remote repo tags = Git::Lib.new.ls_remote(remote_package["repository"])["tags"] # Delete any tags that aren't version numbers tags.each { |t| tags.delete(t) unless t[0].is_number? } # Sort the tags newest to oldest versions = Hash[tags.sort.reverse] # Create a new package object and return it packages << Package.new(:name => remote_package["name"], :authors => remote_package["authors"], :repository => remote_package["repository"], :versions => versions) end if exact_match return packages.first else return packages end else # The package doesn't exist, so return false false end end
Public Instance Methods
install(version)
click to toggle source
# File lib/arpm/package.rb, line 88 def install(version) # Clone the repository! repo = Git.clone(repository, install_path(version)) # It does, so checkout the right version repo.checkout("tags/#{version}") # Register the package to the list register(version) end
install_path(version = nil)
click to toggle source
# File lib/arpm/package.rb, line 75 def install_path(version = nil) # Take the latest_version unless it's been specified version = latest_version unless version # Creat the install path path = ARPM::Config.base_directory + name # Arduino doesn't like dots or dashes in library names path = path + "_#{version.gsub('.', '_')}" end
installed_versions()
click to toggle source
# File lib/arpm/package.rb, line 115 def installed_versions ARPM::List.versions(self.name) end
latest_version()
click to toggle source
# File lib/arpm/package.rb, line 67 def latest_version if versions.kind_of?(Array) versions.first else versions.keys.first.to_s end end
register(version)
click to toggle source
# File lib/arpm/package.rb, line 107 def register(version) ARPM::List.register(self, version) end
uninstall(version)
click to toggle source
# File lib/arpm/package.rb, line 99 def uninstall(version) # Remove the files FileUtils.rm_r(install_path(version)) rescue "" # Unregister it unregister(version) end
unregister(version)
click to toggle source
# File lib/arpm/package.rb, line 111 def unregister(version) ARPM::List.unregister(self, version) end