hosts_file 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,7 +10,7 @@ Basic library for reading hosts file entries.
10
10
 
11
11
  require 'hosts_file'
12
12
 
13
- hosts = HostsFile.read("/etc/hosts")
13
+ hosts = HostsFile.load("/etc/hosts")
14
14
  hosts.collect {|host| host.ip}
15
15
  hosts.collect {|host| host.name}
16
16
  hosts.collect {|host| host.aliases}
@@ -8,6 +8,10 @@ module HostsFile
8
8
  @aliases = aliases
9
9
  end
10
10
 
11
+ def name
12
+ hostname
13
+ end
14
+
11
15
  def hostname
12
16
  canonical_hostname
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module HostsFile
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,7 +1,14 @@
1
1
  require 'hosts_file/parser'
2
2
 
3
3
  describe HostsFile::Parser do
4
- it "should parse" do
4
+ def test_example(line, ip, name=nil, *alias_name)
5
+ host = HostsFile::Parser.new(line).first
6
+ host.ip.should eql(ip)
7
+ host.name.should eql(name)
8
+ host.aliases.should eql(alias_name)
9
+ end
10
+
11
+ it "should parse multiline" do
5
12
  @parser = HostsFile::Parser.new("1.1.1.1 hostname\n2.2.2.2 hostname2")
6
13
  @parser.collect {|h| h}.length.should eql(2)
7
14
  end
@@ -15,4 +22,28 @@ describe HostsFile::Parser do
15
22
  @parser = HostsFile::Parser.new("1.1.1.1")
16
23
  @parser.collect {|h| h}.length.should eql(0)
17
24
  end
25
+
26
+ it "should handle basic syntax" do
27
+ test_example("1.1.1.1 HOSTNAME", "1.1.1.1", "HOSTNAME")
28
+ end
29
+
30
+ it "should handle advanced syntax" do
31
+ test_example("1.1.1.1 HOSTNAME HOST", "1.1.1.1", "HOSTNAME", "HOST")
32
+ end
33
+
34
+ it "should support tab separation" do
35
+ test_example("1.1.1.1\tHOSTNAME", "1.1.1.1", "HOSTNAME")
36
+ end
37
+
38
+ it "should tolerate lots of tab separation" do
39
+ test_example("1.1.1.1\t\t\t\t\t\t\tHOSTNAME", "1.1.1.1", "HOSTNAME")
40
+ end
41
+
42
+ it "should tolerate lots of spaces" do
43
+ test_example("1.1.1.1 HOSTNAME", "1.1.1.1", "HOSTNAME")
44
+ end
45
+
46
+ it "should tolerate lots of aliases" do
47
+ test_example("1.1.1.1 HOSTNAME HOSTA HOSTB HOSTC HOSTD", "1.1.1.1", "HOSTNAME", "HOSTA", "HOSTB", "HOSTC", "HOSTD")
48
+ end
18
49
  end
metadata CHANGED
@@ -1,75 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hosts_file
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Joshua Bussdieker
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-07-24 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-07-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: bundler
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &13603580 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 9
29
- segments:
30
- - 1
31
- - 3
32
- version: "1.3"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: rake
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *13603580
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &13601400 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: rspec
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *13601400
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &13600040 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :development
62
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *13600040
63
47
  description:
64
- email:
48
+ email:
65
49
  - jbussdieker@gmail.com
66
50
  executables: []
67
-
68
51
  extensions: []
69
-
70
52
  extra_rdoc_files: []
71
-
72
- files:
53
+ files:
73
54
  - .gitignore
74
55
  - .travis.yml
75
56
  - Gemfile
@@ -88,39 +69,31 @@ files:
88
69
  - spec/hosts_file_spec.rb
89
70
  - spec/spec_helper.rb
90
71
  homepage: http://github.com/jbussdieker/ruby-hosts_file
91
- licenses:
72
+ licenses:
92
73
  - MIT
93
74
  post_install_message:
94
75
  rdoc_options: []
95
-
96
- require_paths:
76
+ require_paths:
97
77
  - lib
98
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
99
79
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
85
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- hash: 3
113
- segments:
114
- - 0
115
- version: "0"
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
116
90
  requirements: []
117
-
118
91
  rubyforge_project:
119
- rubygems_version: 1.8.15
92
+ rubygems_version: 1.8.17
120
93
  signing_key:
121
94
  specification_version: 3
122
95
  summary: Basic library for reading hosts file entries.
123
- test_files:
96
+ test_files:
124
97
  - spec/hosts_file/file_spec.rb
125
98
  - spec/hosts_file/host_spec.rb
126
99
  - spec/hosts_file/parser_spec.rb