aurb 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,15 +12,15 @@ Aurb can download from, search and look for updates on the AUR.
12
12
 
13
13
  Download one or more packages:
14
14
 
15
- $ aurb --download "firefox-nightly opera chromium-browser-svn"
15
+ $ aurb download "firefox-nightly opera chromium-browser-svn"
16
16
 
17
17
  Search for one or more packages:
18
18
 
19
- $ aurb --search "firefox opera"
19
+ $ aurb search "firefox opera"
20
20
 
21
21
  Look for upgrades to packages you have installed from the AUR:
22
22
 
23
- $ aurb --upgrade
23
+ $ aurb upgrade
24
24
 
25
25
  == Tests
26
26
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{aurb}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gigamo"]
12
- s.date = %q{2010-02-07}
12
+ s.date = %q{2010-02-08}
13
13
  s.default_executable = %q{aurb}
14
14
  s.email = %q{gigamo@gmail.com}
15
15
  s.executables = ["aurb"]
@@ -17,7 +17,7 @@ require 'archive/tar/minitar'
17
17
  require 'facets/version'
18
18
 
19
19
  module Aurb #:nodoc:
20
- VERSION = '1.1.0'
20
+ VERSION = '1.1.1'
21
21
 
22
22
  class AurbError < StandardError
23
23
  def self.status_code(code = nil)
@@ -44,6 +44,10 @@ module Aurb #:nodoc:
44
44
  "http://aur.archlinux.org/rpc.php?type=#{type}&arg=#{arg}"
45
45
  end
46
46
 
47
+ def aur_download_path(pkg)
48
+ "http://aur.archlinux.org/packages/#{pkg}/#{pkg}.tar.gz"
49
+ end
50
+
47
51
  def aur
48
52
  @aur ||= Aur.new
49
53
  end
@@ -23,10 +23,8 @@ module Aurb
23
23
  #
24
24
  # download(['aurb']) # => ['http://.../aurb.tar.gz']
25
25
  def download(packages)
26
- url = lambda {|p| "http://aur.archlinux.org/packages/#{p}/#{p}.tar.gz"}
27
-
28
26
  packages.map do |package|
29
- url.call(URI.escape(package.to_s))
27
+ Aurb.aur_download_path URI.escape(package.to_s)
30
28
  end.select do |package|
31
29
  downloadable?(package)
32
30
  end.delete_if(&:blank?)
@@ -39,15 +37,12 @@ module Aurb
39
37
  # # With Aurb on the AUR as version [0, 8, 2, 1]
40
38
  # upgrade(['aurb 0.0.0.0', 'aurb 0.9.9.9']) # => [:aurb]
41
39
  def upgrade(list)
42
- upgradables = []
43
-
44
- list.each do |line|
40
+ list.inject([]) do |ary, line|
45
41
  name, version = line.split
46
42
  next if in_community?(name)
47
- upgradables << name.to_sym if upgradable?(name, version)
43
+ ary << name.to_sym if upgradable?(name, version)
44
+ ary
48
45
  end
49
-
50
- upgradables
51
46
  end
52
47
 
53
48
  protected
@@ -64,39 +59,46 @@ module Aurb
64
59
 
65
60
  # Compare version of local +package+ with the one on the AUR.
66
61
  def upgradable?(package, version)
67
- json = parse_json(Aurb.aur_path(:info, package.to_s))
68
- return if json.type =~ /error/
69
- remote_package = json.results
62
+ parse_json(Aurb.aur_path(:info, package.to_s)) do |json|
63
+ return false if json.type =~ /error/
70
64
 
71
- local_version = VersionNumber.new(version)
72
- remote_version = VersionNumber.new(remote_package.Version)
65
+ remote_package = json.results
73
66
 
74
- local_version < remote_version
67
+ local_version = VersionNumber.new(version)
68
+ remote_version = VersionNumber.new(remote_package.Version)
69
+
70
+ local_version < remote_version
71
+ end
75
72
  end
76
73
 
77
74
  # Returns an array containing a hash of search results
78
75
  # for a given +package+.
79
76
  def list_search_results(package)
80
77
  json = parse_json(Aurb.aur_path(:search, URI.escape(package.to_s)))
81
- return if json.type =~ /error/
82
- ids = json.results.map(&:ID)
83
- results = []
84
-
85
- ids.each do |id|
86
- json = parse_json(Aurb.aur_path(:info, id))
87
- next if json.type =~ /error/
88
- result = json.results.symbolize_keys
89
- results << result unless in_community?(result[:Name])
78
+ return [] if json.type =~ /error/
79
+
80
+ ids = json.results.map(&:ID)
81
+ ids.inject([]) do |ary, id|
82
+ parse_json(Aurb.aur_path(:info, id)) do |json|
83
+ next if json.type =~ /error/
84
+ result = json.results.symbolize_keys
85
+ ary << result unless in_community?(result.Name)
86
+ end
87
+ ary
90
88
  end
91
-
92
- results
93
89
  end
94
90
 
95
91
  private
96
92
 
97
93
  # Shortcut to the +Yajl+ JSON parser.
98
94
  def parse_json(json)
99
- Yajl::Parser.new.parse(open(json).read)
95
+ json = Yajl::Parser.new.parse(open(json).read)
96
+
97
+ if block_given?
98
+ yield json
99
+ else
100
+ json
101
+ end
100
102
  end
101
103
  end
102
104
  end
@@ -30,20 +30,6 @@ class Hash
30
30
  end
31
31
  end
32
32
 
33
- class Array
34
- # Extracts options from a set of arguments.
35
- #
36
- # def options(*args)
37
- # args.extract_options!
38
- # end
39
- #
40
- # options(1, 2) # => {}
41
- # options(1, 2, :a => :b) # => {:a=>:b}
42
- def extract_options!
43
- last.is_a?(Hash) ? pop : {}
44
- end
45
- end
46
-
47
33
  class String
48
34
  # Colors a string with +color+.
49
35
  # Uses the ANSICode library provided by +facets+.
@@ -24,7 +24,6 @@ class AurTest < Test::Unit::TestCase
24
24
 
25
25
  context 'download' do
26
26
  setup do
27
- @url = lambda {|p| "http://aur.archlinux.org/packages/#{p}/#{p}.tar.gz"}
28
27
  @package_working = ['awesome-git']
29
28
  @package_faulty = ['awesome']
30
29
  end
@@ -35,7 +34,7 @@ class AurTest < Test::Unit::TestCase
35
34
  end
36
35
 
37
36
  should 'return download links' do
38
- assert_equal [@url.call(@package_working.join)], @aur.download(@package_working)
37
+ assert_equal [Aurb.aur_download_path(@package_working.join)], @aur.download(@package_working)
39
38
  end
40
39
 
41
40
  should 'filter out non-existant packages' do
@@ -45,16 +44,21 @@ class AurTest < Test::Unit::TestCase
45
44
 
46
45
  context 'search' do
47
46
  setup do
48
- @package = ['aurb']
47
+ @package_working = ['aurb']
48
+ @package_faulty = ['foobarbaz']
49
49
  end
50
50
 
51
51
  should 'return an array of results' do
52
- assert @aur.search(@package).is_a?(Array)
52
+ assert @aur.search(@package_working).is_a?(Array)
53
+ end
54
+
55
+ should 'filter out non-existant packages' do
56
+ assert_equal [], @aur.search(@package_faulty)
53
57
  end
54
58
 
55
59
  context 'result' do
56
60
  setup do
57
- @result = @aur.search(@package).first
61
+ @result = @aur.search(@package_working).first
58
62
  end
59
63
 
60
64
  should 'return an array containing hashes' do
@@ -1,40 +1,39 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
2
 
3
3
  class SupportTest < Test::Unit::TestCase
4
- context 'The core extensions' do
4
+ context 'Object' do
5
5
  should 'be able to check for blank' do
6
6
  assert ''.blank?
7
7
  assert nil.blank?
8
+ assert [].blank?
8
9
  end
10
+ end
9
11
 
10
- context 'for hash' do
11
- setup do
12
- @hash_s = {'hello' => 'world'}
13
- @hash_sym = {:hello => 'world'}
14
- end
12
+ context 'Hash' do
13
+ setup do
14
+ @hash_str = {'hello' => 'world'}
15
+ @hash_sym = {:hello => 'world'}
16
+ end
15
17
 
16
- should 'be able to symbolize keys' do
17
- assert_equal @hash_sym, @hash_s.symbolize_keys
18
- symbolized = @hash_s.symbolize_keys!
19
- assert_equal @hash_sym, symbolized
20
- end
18
+ should 'be able to symbolize keys' do
19
+ assert_equal @hash_sym, @hash_str.symbolize_keys
20
+ symbolized = @hash_str.symbolize_keys!
21
+ assert_equal @hash_sym, symbolized
22
+ end
21
23
 
22
- should 'provide methods for its keys and automatically symbolize them' do
23
- assert_equal 'world', @hash_s.hello
24
- assert_equal 'world', @hash_sym.hello
25
- end
24
+ should 'provide methods for its keys through method_missing' do
25
+ assert_equal 'world', @hash_str.hello
26
+ assert_equal 'world', @hash_sym.hello
26
27
  end
28
+ end
27
29
 
28
- context 'for array' do
29
- setup do
30
- @array_no_opts = [1, 2]
31
- @array_with_opts = [1, 2, :a => :b]
32
- end
30
+ context 'String' do
31
+ setup do
32
+ @str = 'foo'
33
+ end
33
34
 
34
- should 'be able to extract options' do
35
- assert_equal({}, @array_no_opts.extract_options!)
36
- assert_equal({:a => :b}, @array_with_opts.extract_options!)
37
- end
35
+ should 'be able to colorize itself through the ansi library' do
36
+ assert_equal "\e[34mfoo\e[0m", @str.colorize(:blue)
38
37
  end
39
38
  end
40
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aurb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gigamo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-07 00:00:00 +01:00
12
+ date: 2010-02-08 00:00:00 +01:00
13
13
  default_executable: aurb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency