Class: ARPM::Package
- Inherits:
-
Object
- Object
- ARPM::Package
- Defined in:
- lib/arpm/package.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#name ⇒ Object
Returns the value of attribute name.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#versions ⇒ Object
Returns the value of attribute versions.
Class Method Summary collapse
-
.search(name, exact_match = true) ⇒ Object
Search for a new package.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Package
constructor
A new instance of Package.
- #install(version) ⇒ Object
- #install_path(version = nil) ⇒ Object
- #installed_versions ⇒ Object
- #latest_version ⇒ Object
- #register(version) ⇒ Object
- #uninstall(version) ⇒ Object
- #unregister(version) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Package
Returns a new instance of Package.
9 10 11 |
# File 'lib/arpm/package.rb', line 9 def initialize(opts = {}) opts.each { |k,v| instance_variable_set("@#{k}", v) } end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
5 6 7 |
# File 'lib/arpm/package.rb', line 5 def @authors end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/arpm/package.rb', line 4 def name @name end |
#repository ⇒ Object
Returns the value of attribute repository.
7 8 9 |
# File 'lib/arpm/package.rb', line 7 def repository @repository end |
#versions ⇒ Object
Returns the value of attribute versions.
6 7 8 |
# File 'lib/arpm/package.rb', line 6 def versions @versions end |
Class Method Details
.search(name, exact_match = true) ⇒ Object
Search for a new package
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 = Git::Lib.new.ls_remote(remote_package["repository"])["tags"] # Delete any tags that aren't version numbers .each { |t| .delete(t) unless t[0].is_number? } # Sort the tags newest to oldest versions = Hash[.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 |
Instance Method Details
#install(version) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# 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) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# 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 ⇒ Object
115 116 117 |
# File 'lib/arpm/package.rb', line 115 def installed_versions ARPM::List.versions(self.name) end |
#latest_version ⇒ Object
67 68 69 70 71 72 73 |
# 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) ⇒ Object
107 108 109 |
# File 'lib/arpm/package.rb', line 107 def register(version) ARPM::List.register(self, version) end |
#uninstall(version) ⇒ Object
99 100 101 102 103 104 105 |
# 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) ⇒ Object
111 112 113 |
# File 'lib/arpm/package.rb', line 111 def unregister(version) ARPM::List.unregister(self, version) end |