chef-extensions 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -1,9 +1,5 @@
1
1
  require 'rdiscount'
2
2
 
3
- guard 'rocco', :run_on => [:start, :change], :dir => 'docs' do
4
- watch(%r{^lib/.*\.rb$})
5
- end
6
-
7
3
  guard 'minitest', :notify => false do
8
4
  watch(%r|^test/(.*)_test\.rb|)
9
5
  watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
data/Rakefile CHANGED
@@ -13,10 +13,9 @@ end
13
13
 
14
14
  task :default => [:test]
15
15
 
16
- task :version do
17
- require 'chef'
18
- puts Chef::Extensions::VERSION
19
- end
16
+
17
+
18
+ ### DOCUMENTATION
20
19
 
21
20
  desc 'Build rocco gh-pages'
22
21
  task :docs => :rocco do
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_development_dependency "chef"
22
22
  s.add_development_dependency 'guard-minitest'
23
- s.add_development_dependency "guard-rocco"
24
23
  s.add_development_dependency 'minitest'
25
24
  s.add_development_dependency 'pry'
26
25
  s.add_development_dependency "rdiscount"
@@ -2,30 +2,39 @@ require File.expand_path('../platform', __FILE__)
2
2
 
3
3
  class Chef
4
4
  module Extensions
5
+ # In Ruby 1.9, there is `Socket.ip_address_list`, which would simplify all
6
+ # this greatly, but a lot of people still run chef under 1.8. This solution
7
+ # will work with both 1.8 & 1.9.
5
8
  module IP
6
9
  extend self
7
10
 
8
- # **Get all local IPv4 addresses** <br />
9
- # It excludes localhost. Easily adaptable to IPv6. <br />
10
- # In Ruby 1.9, this is a simple call to `Socket.ip_address_list`.
11
- def all
12
- local_ips - localhost
11
+ # **Get all public IPv4 addresses** <br />
12
+ # Some of them might be local to the host, but it's not easy to say which
13
+ # is which without expensive queries and a complicated logic. <br />
14
+ # It excludes localhost.
15
+ def public_ipv4
16
+ local_ipv4 - localhost_ipv4
13
17
  end
14
18
 
15
- protected
19
+ # **Get all local IPv4 addresses** <br />
20
+ # It includes localhost.
21
+ def local_ipv4
22
+ `echo "#{ifconfig}" | #{filter}`.split("\n")
23
+ end
16
24
 
17
- def local_ips
18
- `echo "#{ifconfig}" | #{filter}`.split("\n")
19
- end
25
+ def localhost_ipv4
26
+ ["127.0.0.1"]
27
+ end
20
28
 
21
- def localhost
22
- ["127.0.0.1"]
23
- end
29
+ # **Runs ifconfig shell utility** <br />
30
+ # Caching was not necessary, but it helps with tests.
31
+ def ifconfig
32
+ @ifconfig ||= `ifconfig`
33
+ end
24
34
 
25
- def ifconfig
26
- @ifconfig ||= `ifconfig`
27
- end
35
+ protected
28
36
 
37
+ # Selects the appropriate awk filering based on OS platform
29
38
  def filter
30
39
  @filter ||= if Platform.linux?
31
40
  linux_filter
@@ -36,6 +45,7 @@ class Chef
36
45
  end
37
46
  end
38
47
 
48
+ # Linux's ifconfig returns a slightly different version that OS X
39
49
  def linux_filter
40
50
  "#{awk} { print $4 }'"
41
51
  end
@@ -44,6 +54,7 @@ class Chef
44
54
  "#{awk} { print $2 }'"
45
55
  end
46
56
 
57
+ # Common to both OS X & Linux
47
58
  def awk
48
59
  %{awk -F"[: ]+" '/inet /}
49
60
  end
@@ -1,5 +1,5 @@
1
1
  class Chef
2
2
  module Extensions
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -10,8 +10,19 @@ class Chef
10
10
  IP.instance_variable_set(:@ifconfig, ifconfig)
11
11
  end
12
12
 
13
- it "all IPv4 addresses, excluding localhost" do
14
- IP.all.must_equal([
13
+ it "all public IPv4 addresses (excludes localhost)" do
14
+ IP.public_ipv4.must_equal([
15
+ "10.100.1.11",
16
+ "10.100.1.10",
17
+ "192.168.86.1",
18
+ "192.168.203.1",
19
+ "11.11.11.1"
20
+ ])
21
+ end
22
+
23
+ it "all local IPv4 addresses (includes localhost)" do
24
+ IP.local_ipv4.must_equal([
25
+ "127.0.0.1",
15
26
  "10.100.1.11",
16
27
  "10.100.1.10",
17
28
  "192.168.86.1",
@@ -28,12 +39,20 @@ class Chef
28
39
  IP.instance_variable_set(:@filter, IP.send(:linux_filter))
29
40
  end
30
41
 
31
- it "all IPv4 addresses, excluding localhost" do
32
- IP.all.must_equal([
42
+ it "all public IPv4 addresses (excludes localhost)" do
43
+ IP.public_ipv4.must_equal([
33
44
  "10.0.1.10",
34
45
  "11.11.11.10"
35
46
  ])
36
47
  end
48
+
49
+ it "all local IPv4 addresses (includes localhost)" do
50
+ IP.local_ipv4.must_equal([
51
+ "10.0.1.10",
52
+ "11.11.11.10",
53
+ "127.0.0.1"
54
+ ])
55
+ end
37
56
  end
38
57
  end
39
58
  end
data/test/test_helper.rb CHANGED
@@ -2,19 +2,8 @@ require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.setup
4
4
 
5
- require 'minitest/unit'
6
- require 'minitest/spec'
7
-
8
- require 'turn/colorize'
9
- require 'turn/controller'
10
- require 'turn/runners/minirunner'
11
-
12
- Turn.config do |config|
13
- config.format = :pretty
14
- end
15
-
16
- MiniTest::Unit.runner = Turn::MiniRunner.new
17
- MiniTest::Unit.autorun
5
+ require 'turn/autorun'
6
+ Turn.config.format = :pretty
18
7
 
19
8
  require 'pry'
20
9
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerhard Lazu
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-15 00:00:00 Z
18
+ date: 2012-02-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: chef
@@ -46,7 +46,7 @@ dependencies:
46
46
  type: :development
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: guard-rocco
49
+ name: minitest
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  none: false
@@ -60,7 +60,7 @@ dependencies:
60
60
  type: :development
61
61
  version_requirements: *id003
62
62
  - !ruby/object:Gem::Dependency
63
- name: minitest
63
+ name: pry
64
64
  prerelease: false
65
65
  requirement: &id004 !ruby/object:Gem::Requirement
66
66
  none: false
@@ -74,7 +74,7 @@ dependencies:
74
74
  type: :development
75
75
  version_requirements: *id004
76
76
  - !ruby/object:Gem::Dependency
77
- name: pry
77
+ name: rdiscount
78
78
  prerelease: false
79
79
  requirement: &id005 !ruby/object:Gem::Requirement
80
80
  none: false
@@ -88,7 +88,7 @@ dependencies:
88
88
  type: :development
89
89
  version_requirements: *id005
90
90
  - !ruby/object:Gem::Dependency
91
- name: rdiscount
91
+ name: rocco
92
92
  prerelease: false
93
93
  requirement: &id006 !ruby/object:Gem::Requirement
94
94
  none: false
@@ -102,7 +102,7 @@ dependencies:
102
102
  type: :development
103
103
  version_requirements: *id006
104
104
  - !ruby/object:Gem::Dependency
105
- name: rocco
105
+ name: turn
106
106
  prerelease: false
107
107
  requirement: &id007 !ruby/object:Gem::Requirement
108
108
  none: false
@@ -115,20 +115,6 @@ dependencies:
115
115
  version: "0"
116
116
  type: :development
117
117
  version_requirements: *id007
118
- - !ruby/object:Gem::Dependency
119
- name: turn
120
- prerelease: false
121
- requirement: &id008 !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 3
127
- segments:
128
- - 0
129
- version: "0"
130
- type: :development
131
- version_requirements: *id008
132
118
  description: Commands useful for checking internet connectivity, VM presence etc.
133
119
  email:
134
120
  - gerhard@lazu.co.uk