config_curator 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e025bf5875775d284843dd093df45960f282e908
4
- data.tar.gz: 942b7ecffe91f214959dcccbbfaf88fd56c46249
3
+ metadata.gz: 32b4ddb600f1f140e66c33d83bdde687f92e94a3
4
+ data.tar.gz: 85b1b44674ba0ac5df73cd64e33e509a44b9a77c
5
5
  SHA512:
6
- metadata.gz: 6456369212a86c78383e814acf404770dcb96719b935bd8f1b88f87a9d65f00c517343846e03c552e36944ca226bcf7444e3f29280866ef66e64d76d88745780
7
- data.tar.gz: 1c49c2541f670186678b071d3c307bcfa7a73344d3224a655ff5be6302317ed0c3dd4d4d132309bc8d329ee13fb5bc75e465c4d9103a744ed3e701a875ce828b
6
+ metadata.gz: 71e19020b4da56639b484babdd8e153e45ebdffdcf8423546bfd7de17d296738c9cd8f447bdd97d45aaf1230d81910e15a36a3a24078ae231f63a3d1efbe9582
7
+ data.tar.gz: 1efebe21980e568e141376b77c92c60da909ba77c042b8a91ed490c817e2fc41451828e0985dd7d5422e1ca96b91fb758ac8ecf28aafa445115f2b92894dc7c4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Config Curator ChangeLog
2
2
 
3
+ ## 0.1.0
4
+
5
+ - PackageLookup#tools separates tool identifier and tool command.
6
+ - PackageLookup#installed? checks for tool command before lookup.
7
+ - Support for FreeBSD's pkgng added to PackageLookup.
8
+
3
9
  ## 0.0.1
4
10
 
5
11
  - Initial development release.
@@ -16,7 +16,12 @@ module ConfigCurator
16
16
  class LookupFailed < RuntimeError; end
17
17
 
18
18
  # Default list of supported package tools.
19
- TOOLS = %i(dpkg pacman)
19
+ # @see #tools
20
+ TOOLS = {
21
+ dpkg: 'dpkg',
22
+ pacman: 'pacman',
23
+ pkgng: 'pkg',
24
+ }
20
25
 
21
26
  attr_accessor :tool, :tools
22
27
 
@@ -25,7 +30,8 @@ module ConfigCurator
25
30
  end
26
31
 
27
32
  # Package tools that support package lookup ordered by preference.
28
- # @return [Array] list of supported package tools
33
+ # Each key is an identifier and each value is the command to check for.
34
+ # @return [Hash] hash of supported package tools
29
35
  def tools
30
36
  @tools ||= TOOLS
31
37
  end
@@ -35,9 +41,9 @@ module ConfigCurator
35
41
  def tool
36
42
  return @tool if @tool
37
43
 
38
- tools.each do |cmd|
39
- if command? cmd
40
- return @tool = cmd
44
+ tools.each do |k, v|
45
+ if command? v
46
+ return @tool = k
41
47
  end
42
48
  end
43
49
  @tool
@@ -48,6 +54,10 @@ module ConfigCurator
48
54
  # @return [Boolean] if package is installed
49
55
  def installed? package
50
56
  fail LookupFailed, 'No supported package tool found.' if tool.nil?
57
+
58
+ cmd = tools[tool]
59
+ fail LookupFailed, "Package tool '#{cmd}' not found." if command?(cmd).nil?
60
+
51
61
  send tool, package
52
62
  end
53
63
 
@@ -79,6 +89,13 @@ module ConfigCurator
79
89
  wait_thr.value.to_i == 0
80
90
  end
81
91
  end
92
+
93
+ def pkgng package
94
+ cmd = command? 'pkg'
95
+ Open3.popen3 cmd, 'info', package do |_, _ , _, wait_thr|
96
+ wait_thr.value.to_i == 0
97
+ end
98
+ end
82
99
  end
83
100
 
84
101
  end
@@ -1,4 +1,4 @@
1
1
  module ConfigCurator
2
2
  # Config Curator version.
3
- VERSION = '0.0.2'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -32,8 +32,8 @@ describe ConfigCurator::PackageLookup do
32
32
  context "when tool not set" do
33
33
 
34
34
  it "returns the first avaible tool" do
35
- allow(lookup).to receive(:command?).with(:dpkg).and_return(true)
36
- lookup.tools = %i(dpkg pacman)
35
+ lookup.tools = {dpkg: 'dpkg', pacman: 'pacman'}
36
+ allow(lookup).to receive(:command?).with('dpkg').and_return(true)
37
37
  expect(lookup.tool).to eq :dpkg
38
38
  end
39
39
  end
@@ -41,17 +41,43 @@ describe ConfigCurator::PackageLookup do
41
41
 
42
42
  describe "#installed?" do
43
43
 
44
- it "calls the corresponding private lookup method" do
45
- lookup.tool = :dpkg
46
- expect(lookup).to receive(:dpkg).with('rsync')
47
- lookup.installed? 'rsync'
44
+ context "when package is found" do
45
+
46
+ it "calls the corresponding private lookup method and returns true" do
47
+ lookup.tool = :dpkg
48
+ cmd = lookup.tools[:dpkg]
49
+ allow(lookup).to receive(:command?).with(cmd).and_return(cmd)
50
+ expect(lookup).to receive(:dpkg).with('rsync').and_return(true)
51
+ expect(lookup.installed? 'rsync').to be true
52
+ end
53
+ end
54
+
55
+ context "when package not found" do
56
+
57
+ it "calls the corresponding private lookup method and returns false" do
58
+ lookup.tool = :dpkg
59
+ cmd = lookup.tools[:dpkg]
60
+ allow(lookup).to receive(:command?).with(cmd).and_return(cmd)
61
+ expect(lookup).to receive(:dpkg).with('rsync').and_return(false)
62
+ expect(lookup.installed? 'rsync').to be false
63
+ end
48
64
  end
49
65
 
50
66
  context "when no package tool found" do
51
67
 
52
68
  it "fails" do
53
- lookup.tools = %i(dpkg)
54
- allow(lookup).to receive(:command?).with(:dpkg).and_return(false)
69
+ lookup.tools = {dpkg: 'dpkg'}
70
+ allow(lookup).to receive(:command?).with('dpkg').and_return(nil)
71
+ expect { lookup.installed? 'rsync' }.to raise_error ConfigCurator::PackageLookup::LookupFailed
72
+ end
73
+ end
74
+
75
+ context "when package tool not found" do
76
+
77
+ it "fails" do
78
+ lookup.tool = :dpkg
79
+ cmd = lookup.tools[:dpkg]
80
+ allow(lookup).to receive(:command?).with(cmd).and_return(nil)
55
81
  expect { lookup.installed? 'rsync' }.to raise_error ConfigCurator::PackageLookup::LookupFailed
56
82
  end
57
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_curator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Boyd Sosenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-10 00:00:00.000000000 Z
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport