work 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/play +7 -6
- data/bin/work +7 -6
- data/lib/work.rb +1 -0
- data/lib/work/dotfile.rb +21 -5
- data/lib/work/teacher.rb +2 -2
- data/lib/work/version.rb +1 -1
- metadata +3 -3
data/bin/play
CHANGED
@@ -16,22 +16,20 @@ end
|
|
16
16
|
# Find the location of the user's work preferences.
|
17
17
|
dotfile = Work::DotFile.locate
|
18
18
|
|
19
|
-
case ARGV.first
|
20
19
|
# We need a list of domains to work with, which is stored in a
|
21
20
|
# ~/.work hidden file.
|
22
|
-
|
23
|
-
dotfile = Work::DotFile.locate
|
21
|
+
if ARGV.first == 'setup'
|
24
22
|
if dotfile.exists?
|
25
23
|
puts "Work file already exists at #{dotfile.path}"
|
26
24
|
else
|
27
|
-
dotfile.write
|
25
|
+
dotfile.write!
|
28
26
|
puts "Default work domains added to #{dotfile.path}"
|
29
27
|
end
|
30
28
|
|
31
29
|
# Not a setup command, so we'll need the `Teacher`
|
32
30
|
else
|
33
31
|
# Warn the user if they've not set up a domains list
|
34
|
-
if dotfile.
|
32
|
+
if dotfile.domains.length == 0
|
35
33
|
puts "Domain list is empty. Add work domains to #{dotfile.path}"
|
36
34
|
puts "or run `#{$0} setup` to populate with the default list."
|
37
35
|
exit
|
@@ -39,7 +37,7 @@ else
|
|
39
37
|
|
40
38
|
# If we can't write to the hosts file, re-run but with `sudo`.
|
41
39
|
begin
|
42
|
-
p = Work::Teacher.new(dotfile.
|
40
|
+
p = Work::Teacher.new(dotfile.domains, dotfile.ip)
|
43
41
|
rescue Work::HostsFileNotWritable
|
44
42
|
sudome
|
45
43
|
end
|
@@ -54,6 +52,9 @@ else
|
|
54
52
|
p.play
|
55
53
|
else
|
56
54
|
puts "Bums on seats, please."
|
55
|
+
# Clear out any old data in case the domain list or IP address has
|
56
|
+
# been updated and we're just running `work` again without a `play`.
|
57
|
+
p.play
|
57
58
|
p.work
|
58
59
|
end
|
59
60
|
|
data/bin/work
CHANGED
@@ -16,22 +16,20 @@ end
|
|
16
16
|
# Find the location of the user's work preferences.
|
17
17
|
dotfile = Work::DotFile.locate
|
18
18
|
|
19
|
-
case ARGV.first
|
20
19
|
# We need a list of domains to work with, which is stored in a
|
21
20
|
# ~/.work hidden file.
|
22
|
-
|
23
|
-
dotfile = Work::DotFile.locate
|
21
|
+
if ARGV.first == 'setup'
|
24
22
|
if dotfile.exists?
|
25
23
|
puts "Work file already exists at #{dotfile.path}"
|
26
24
|
else
|
27
|
-
dotfile.write
|
25
|
+
dotfile.write!
|
28
26
|
puts "Default work domains added to #{dotfile.path}"
|
29
27
|
end
|
30
28
|
|
31
29
|
# Not a setup command, so we'll need the `Teacher`
|
32
30
|
else
|
33
31
|
# Warn the user if they've not set up a domains list
|
34
|
-
if dotfile.
|
32
|
+
if dotfile.domains.length == 0
|
35
33
|
puts "Domain list is empty. Add work domains to #{dotfile.path}"
|
36
34
|
puts "or run `#{$0} setup` to populate with the default list."
|
37
35
|
exit
|
@@ -39,7 +37,7 @@ else
|
|
39
37
|
|
40
38
|
# If we can't write to the hosts file, re-run but with `sudo`.
|
41
39
|
begin
|
42
|
-
p = Work::Teacher.new(dotfile.
|
40
|
+
p = Work::Teacher.new(dotfile.domains, dotfile.ip)
|
43
41
|
rescue Work::HostsFileNotWritable
|
44
42
|
sudome
|
45
43
|
end
|
@@ -54,6 +52,9 @@ else
|
|
54
52
|
p.play
|
55
53
|
else
|
56
54
|
puts "Bums on seats, please."
|
55
|
+
# Clear out any old data in case the domain list or IP address has
|
56
|
+
# been updated and we're just running `work` again without a `play`.
|
57
|
+
p.play
|
57
58
|
p.work
|
58
59
|
end
|
59
60
|
|
data/lib/work.rb
CHANGED
data/lib/work/dotfile.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Work
|
2
4
|
class DotFile
|
3
5
|
|
4
|
-
attr_accessor :path
|
6
|
+
attr_accessor :path, :ip, :domains
|
7
|
+
attr_writer :ip, :domains
|
5
8
|
|
6
9
|
def self.locate
|
7
10
|
@dotfile ||= self.new File.expand_path(File.join('~', '.work'))
|
@@ -9,19 +12,32 @@ module Work
|
|
9
12
|
|
10
13
|
def initialize(path)
|
11
14
|
@path = path
|
15
|
+
read!
|
16
|
+
end
|
17
|
+
|
18
|
+
def ip
|
19
|
+
@ip ||= Work::DEFAULT_IP
|
20
|
+
end
|
21
|
+
|
22
|
+
def domains
|
23
|
+
@domains ||= Work::DEFAULT_DOMAINS
|
12
24
|
end
|
13
25
|
|
14
26
|
def exists?
|
15
27
|
File.exists? @path
|
16
28
|
end
|
17
29
|
|
18
|
-
def read
|
19
|
-
|
30
|
+
def read!
|
31
|
+
if exists?
|
32
|
+
data = YAML.load_file(path)
|
33
|
+
self.ip = data["ip"] if data.has_key?("ip")
|
34
|
+
self.domains = data["domains"].sort if data.has_key?("domains")
|
35
|
+
end
|
20
36
|
end
|
21
37
|
|
22
|
-
def write
|
38
|
+
def write!
|
23
39
|
File.open(path, 'w+') do |f|
|
24
|
-
f.write(
|
40
|
+
f.write YAML::dump({ "ip" => ip, "domains" => domains })
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
data/lib/work/teacher.rb
CHANGED
@@ -7,10 +7,10 @@ module Work
|
|
7
7
|
|
8
8
|
attr_accessor :path, :domains, :ip
|
9
9
|
|
10
|
-
def initialize(domains,
|
10
|
+
def initialize(domains, ip=nil, path=nil)
|
11
11
|
@domains = domains
|
12
|
+
@ip = ip || Work::DEFAULT_IP
|
12
13
|
@path = path || "/etc/hosts"
|
13
|
-
@ip = ip || "127.0.0.1"
|
14
14
|
raise HostsFileNotWritable if !File.writable?(@path)
|
15
15
|
end
|
16
16
|
|
data/lib/work/version.rb
CHANGED
metadata
CHANGED