marina 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1f40758d246eb2e193b3b0e4426cada361aef6d
4
+ data.tar.gz: 74faff872a29ac678670ea2981970638d3714d95
5
+ SHA512:
6
+ metadata.gz: d088200ab7dbee51f979f1aded23f7acf232b5d1c254d7bff59ec83d10f7b6b2082389b2ab73bfda68b345e8018c08caaa89a0e8f337a67b63624ee48eef8b0b
7
+ data.tar.gz: b44acffb9634493f5893601fb6e84e59f3e4ae6ed3ffc67fdb22d6de5088d4e29893d49df8bb329102d3f42afc014e7a671844b0f7503244f89377d4f4492742
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marina.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Robert Mackenzie
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Marina
2
+
3
+ Encourages you to declare any hosts file entries you need alongside your project in a Hostspec file. You can then use this tool to update your hosts file against your Hostspec file. Similar style to gems with bundler.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'marina'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install marina
18
+
19
+ ## Usage
20
+
21
+ Add a Hostspec file to the root of your project. Fill it will host name in the
22
+ following format:
23
+
24
+ host 'win.com'
25
+ host 'epic.win.com'
26
+
27
+ Then run `sudo marina` and these will be added to /etc/hosts.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/marina ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'marina'
7
+
8
+ hosts_file_path = ARGV[0] || '/etc/hosts'
9
+ hostspec_file_path = ARGV[1] || './Hostspec'
10
+ marina = Marina.new(hosts_file_path, hostspec_file_path)
11
+
12
+ begin
13
+ hosts_spec = File.open(marina.hostspec_file_path, 'r')
14
+ marina.instance_eval(hosts_spec.read)
15
+ marina.add_to_hostfile
16
+ rescue IOError
17
+ puts e; raise e
18
+ rescue Errno::ENOENT
19
+ puts "marina: #{marina.hostspec_file_path}: No such file"
20
+ exit(66)
21
+ ensure
22
+ hosts_spec.close if hosts_spec.respond_to?(:close)
23
+ end
@@ -0,0 +1,3 @@
1
+ class Marina
2
+ VERSION = "0.0.1"
3
+ end
data/lib/marina.rb ADDED
@@ -0,0 +1,80 @@
1
+ require 'marina/version'
2
+
3
+ class Marina
4
+
5
+ attr_accessor :specified_hosts, :host_entries, :hostspec_file_path, :hosts_file_path
6
+
7
+ def initialize hosts_file_path = '/etc/hosts', hostspec_file_path = 'Hostspec'
8
+ @hosts_file_path = hosts_file_path
9
+ @hostspec_file_path = hostspec_file_path
10
+ @specified_hosts = []
11
+ end
12
+
13
+ def list
14
+ answer = clean_hosts || 'Host file does not exist'
15
+ puts answer
16
+ end
17
+
18
+ def host host
19
+ @specified_hosts << host
20
+ end
21
+
22
+ def add_to_hostfile
23
+ begin
24
+ puts "\nAdding hosts to hosts file:" if File.exists?(@hosts_file_path)
25
+ specified_hosts.each do |host_spec|
26
+ if host_entries.include? "127.0.0.1 #{host_spec}\n"
27
+ puts "\t-\s#{host_spec} is already in the hosts file"
28
+ next
29
+ end
30
+ hosts.write("127.0.0.1 #{host_spec}\n")
31
+ puts "\t-\s#{host_spec} written to the hosts file"
32
+ end
33
+ rescue IOError
34
+ rescue Errno::ENOENT
35
+ puts "marina: #{@hosts_file_path}: No such file"
36
+ exit(66)
37
+ rescue Errno::EACCES
38
+ puts "\tmarina: #{@hosts_file_path}: Permission denied"
39
+ exit(66)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def host_entries bust = nil
46
+ @host_entries = nil if bust
47
+ @host_entries ||= hosts.entries
48
+ end
49
+
50
+ def hosts
51
+ if File.exists?(@hosts_file_path)
52
+ File.open(@hosts_file_path, 'a+')
53
+ else
54
+ raise Errno::ENOENT
55
+ end
56
+ end
57
+
58
+ def clean_hosts
59
+ return nil unless File.exists?(@hosts_file_path)
60
+
61
+ File.open(@hosts_file_path) do |hosts_file|
62
+ return chaff_free hosts_file
63
+ end
64
+ end
65
+
66
+ def chaff_free(hosts_file)
67
+ hosts_file.each_line.reject do |line|
68
+ is_a_comment?(line) or not is_localhost?(line)
69
+ end
70
+ end
71
+
72
+ def is_a_comment?(line)
73
+ line =~ /\A\#/
74
+ end
75
+
76
+ def is_localhost?(line)
77
+ line =~ /\A127\.0\.0\.1/
78
+ end
79
+
80
+ end
data/marina.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'marina/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "marina"
8
+ spec.version = Marina::VERSION
9
+ spec.authors = ["Robert Mackenzie"]
10
+ spec.email = ["robertmackenzie@gmail.com"]
11
+ spec.description = %q{ Encourages you to declare any hosts file entries you need alongside your project in a Hostspec file. You can then use this tool to update your hosts file against your Hostspec file. Similar style to gems with bundler. }
12
+ spec.summary = %q{ Encourages you to declare any hosts file entries you need alongside your project in a Hostspec file. You can then use this tool to update your hosts file against your Hostspec file. Similar style to gems with bundler. }
13
+ spec.homepage = "http://robertmackenzie.githib.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "capybara"
25
+ spec.add_development_dependency "pry"
26
+ end
@@ -0,0 +1,85 @@
1
+ require "capybara/rspec"
2
+
3
+ RSpec.configure do |config|
4
+
5
+ config.before :all do
6
+ FileUtils.cp('spec/stubs/hostspecs/Hostspec', './Hostspec') if File.exist?('spec/stubs/hostspecs/Hostspec')
7
+ end
8
+
9
+ config.before :each do
10
+ File.delete('spec/stubs/hosts/hosts.tmp') if File.exist?('spec/stubs/hosts/hosts.tmp')
11
+ FileUtils.cp('spec/stubs/hosts/hosts.template', 'spec/stubs/hosts/hosts.tmp') if File.exist?('spec/stubs/hosts/hosts.template')
12
+ end
13
+
14
+ config.after :all do
15
+ File.delete('./Hostspec') if File.exist?('./Hostspec')
16
+ File.delete('spec/stubs/hosts/hosts.tmp') if File.exist?('spec/stubs/hosts/hosts.tmp')
17
+ end
18
+
19
+ end
20
+
21
+ feature "adding hosts" do
22
+
23
+ scenario "adding a host" do
24
+ stdout = %x{ ./bin/marina.rb spec/stubs/hosts/hosts.tmp spec/stubs/hostspecs/Hostspec }
25
+ stdout.should eq "\nAdding hosts to hosts file:\n\t- win.com written to the hosts file\n"
26
+
27
+ File.open('spec/stubs/hosts/hosts.tmp') do |temporary_hosts_file|
28
+ File.open('spec/stubs/hosts/hosts.reference.single') do |reference_hosts_file|
29
+ (temporary_hosts_file.read).should eq (reference_hosts_file.read)
30
+ end
31
+ end
32
+
33
+ $?.exitstatus.should eq 0
34
+ end
35
+
36
+ scenario "adding a host with no Hostspec argument" do
37
+ %x{ ./bin/marina.rb spec/stubs/hosts/hosts.tmp}
38
+
39
+ File.open('spec/stubs/hosts/hosts.tmp') do |temporary_hosts_file|
40
+ File.open('spec/stubs/hosts/hosts.reference.single') do |reference_hosts_file|
41
+ (temporary_hosts_file.read).should eq (reference_hosts_file.read)
42
+ end
43
+ end
44
+
45
+ $?.exitstatus.should eq 0
46
+ end
47
+
48
+
49
+ scenario "adding multiple hosts" do
50
+ %x{ ./bin/marina.rb spec/stubs/hosts/hosts.tmp spec/stubs/hostspecs/multiple_hostspec }
51
+
52
+ File.open('spec/stubs/hosts/hosts.tmp') do |temporary_hosts_file|
53
+ File.open('spec/stubs/hosts/hosts.reference.multiple') do |reference_hosts_file|
54
+ (temporary_hosts_file.read).should eq (reference_hosts_file.read)
55
+ end
56
+ end
57
+
58
+ $?.exitstatus.should eq 0
59
+ end
60
+
61
+ scenario "specified, but non-existent hosts file" do
62
+ stdout = %x{ ./bin/marina.rb spec/stubs/hosts/hosts_file_that_does_not_exist spec/stubs/hostspecs/Hostspec }
63
+ stdout.should eq "marina: spec/stubs/hosts/hosts_file_that_does_not_exist: No such file\n"
64
+ $?.exitstatus.should eq 66
65
+ end
66
+
67
+ scenario "specified, but non-existent Hostspec file" do
68
+ stdout = %x{ ./bin/marina.rb spec/stubs/hosts/hosts.tmp spec/stubs/hostspecs/hostspec_file_that_does_not_exist }
69
+ stdout.should eq "marina: spec/stubs/hostspecs/hostspec_file_that_does_not_exist: No such file\n"
70
+ $?.exitstatus.should eq 66
71
+ end
72
+
73
+ scenario "specified, but non-existent Hostspec file & host file" do
74
+ stdout = %x{ ./bin/marina.rb spec/stubs/hosts/hosts_file_that_does_not_exist spec/stubs/hostspecs/hostspec_file_that_does_not_exist }
75
+ stdout.should eq "marina: spec/stubs/hostspecs/hostspec_file_that_does_not_exist: No such file\n"
76
+ $?.exitstatus.should eq 66
77
+ end
78
+
79
+ scenario "accessing /etc/hosts" do
80
+ stdout = %x{ ./bin/marina.rb }
81
+ stdout.should eq "\nAdding hosts to hosts file:\n\tmarina: /etc/hosts: Permission denied\n"
82
+ $?.exitstatus.should eq 66
83
+ end
84
+
85
+ end
@@ -0,0 +1,12 @@
1
+ ##
2
+ # Host Database
3
+ #
4
+ # localhost is used to configure the loopback interface
5
+ # when the system is booting. Do not change this entry.
6
+ ##
7
+ 127.0.0.1 localhost
8
+ 255.255.255.255 broadcasthost
9
+ ::1 localhost
10
+ fe80::1%lo0 localhost
11
+ 127.0.0.1 win.com
12
+ 127.0.0.1 epic.win.com
@@ -0,0 +1,11 @@
1
+ ##
2
+ # Host Database
3
+ #
4
+ # localhost is used to configure the loopback interface
5
+ # when the system is booting. Do not change this entry.
6
+ ##
7
+ 127.0.0.1 localhost
8
+ 255.255.255.255 broadcasthost
9
+ ::1 localhost
10
+ fe80::1%lo0 localhost
11
+ 127.0.0.1 win.com
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Host Database
3
+ #
4
+ # localhost is used to configure the loopback interface
5
+ # when the system is booting. Do not change this entry.
6
+ ##
7
+ 127.0.0.1 localhost
8
+ 255.255.255.255 broadcasthost
9
+ ::1 localhost
10
+ fe80::1%lo0 localhost
@@ -0,0 +1 @@
1
+ host "win.com"
@@ -0,0 +1,2 @@
1
+ host "win.com"
2
+ host "epic.win.com"
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marina
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Mackenzie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ' Encourages you to declare any hosts file entries you need alongside
84
+ your project in a Hostspec file. You can then use this tool to update your hosts
85
+ file against your Hostspec file. Similar style to gems with bundler. '
86
+ email:
87
+ - robertmackenzie@gmail.com
88
+ executables:
89
+ - marina
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - .gitignore
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/marina
99
+ - lib/marina.rb
100
+ - lib/marina/version.rb
101
+ - marina.gemspec
102
+ - spec/adding_hosts_spec.rb
103
+ - spec/stubs/hosts/hosts.reference.multiple
104
+ - spec/stubs/hosts/hosts.reference.single
105
+ - spec/stubs/hosts/hosts.template
106
+ - spec/stubs/hostspecs/Hostspec
107
+ - spec/stubs/hostspecs/multiple_hostspec
108
+ homepage: http://robertmackenzie.githib.io
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.0.0
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Encourages you to declare any hosts file entries you need alongside your
132
+ project in a Hostspec file. You can then use this tool to update your hosts file
133
+ against your Hostspec file. Similar style to gems with bundler.
134
+ test_files:
135
+ - spec/adding_hosts_spec.rb
136
+ - spec/stubs/hosts/hosts.reference.multiple
137
+ - spec/stubs/hosts/hosts.reference.single
138
+ - spec/stubs/hosts/hosts.template
139
+ - spec/stubs/hostspecs/Hostspec
140
+ - spec/stubs/hostspecs/multiple_hostspec