lib/aurb/aur.rb in aurb-1.2.4 vs lib/aurb/aur.rb in aurb-1.3.0

- old
+ new

@@ -51,10 +51,20 @@ end.select do |package| !!(open package rescue false) end.delete_if(&:blank?) end + # Returns all available info for a given package name. + # + # info('aurb') # => {:ID => ..., :Name => 'aurb', ...} + def info(package) + parse_json Aurb.aur_rpc_path(:info, package.to_s) do |json| + return if json.type =~ /error/ + json.results + end + end + # Returns a +list+ of names of packages that have an upgrade # available to them, which could then in turn be passed on to # the +download+ method. # # # With Aurb on the AUR as version 1.1.2-1 @@ -71,23 +81,25 @@ upgradables.delete_if(&:blank?) end protected + # Shortcut to the +Yajl+ JSON parser. + def parse_json(json) + json = Yajl::Parser.new.parse(open(json).read) + yield json rescue json + end + + private + # Compare version of local +package+ with the one on the AUR. def upgradable?(package, version) local_version = Version.new(version) remote_version = nil parse_json Aurb.aur_rpc_path(:info, package.to_s) do |json| return if json.type =~ /error/ remote_version = Version.new(json.results.Version) end remote_version && local_version < remote_version - end - - # Shortcut to the +Yajl+ JSON parser. - def parse_json(json) - json = Yajl::Parser.new.parse(open(json).read) - yield json rescue json end end end