localdev 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/localdev.rb +38 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebc540a4cd5ea1afa2d2105340916d0c87f532a1
|
4
|
+
data.tar.gz: 8dd912ccd5ee08e8a24b05a84d115b6981e2647e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36236ab97c1728cf2216c95817e7a11e02f1032a65e29651498b29e1680018db18c4d5221a78aa5fdceec55c1e63647d5fabb942c2dbdd289bd104a00152db8c
|
7
|
+
data.tar.gz: 15d62ffa4ce494922763c2266b0ecfcb3a74d68bdad0aadc3c2c20c4519244dab2d31fd5c27ccdcb45631b42b5999f061c98f9ebe7be112d272e4aa41ee2a1c2
|
data/lib/localdev.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Localdev - Hosts file tool for local development
|
3
3
|
#
|
4
|
-
# Copyright 2011 by Mark Jaquith
|
4
|
+
# Copyright 2011-2015 by Mark Jaquith
|
5
5
|
#
|
6
6
|
# This program is free software; you can redistribute it and/or modify
|
7
7
|
# it under the terms of the GNU General Public License as published by
|
@@ -18,12 +18,13 @@
|
|
18
18
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
19
|
|
20
20
|
require 'digest/md5'
|
21
|
+
require 'yaml'
|
21
22
|
|
22
23
|
class Localdev
|
23
|
-
VERSION = '0.
|
24
|
+
VERSION = '0.4.0'
|
24
25
|
|
25
26
|
def initialize
|
26
|
-
@
|
27
|
+
@debugMode = false
|
27
28
|
@localdev = '/etc/hosts-localdev'
|
28
29
|
@hosts = '/etc/hosts'
|
29
30
|
@start = '#==LOCALDEV==#'
|
@@ -44,9 +45,13 @@ class Localdev
|
|
44
45
|
require_sudo
|
45
46
|
object.nil? && exit_error_message("'localdev #{command}' requires you to provide a domain")
|
46
47
|
ensure_localdev_exists
|
47
|
-
|
48
|
+
if ARGV.first.nil?
|
49
|
+
send command, object
|
50
|
+
else
|
51
|
+
send command, object, ARGV.first
|
52
|
+
end
|
48
53
|
when nil, '--help', '-h'
|
49
|
-
exit_message "Usage: localdev [on|off|status|list|clear]\n localdev [add|remove] domain"
|
54
|
+
exit_message "Usage: localdev [on|off|status|list|clear]\n localdev [add|remove] domain [ip-address]"
|
50
55
|
else
|
51
56
|
exit_error_message "Invalid command"
|
52
57
|
end
|
@@ -63,7 +68,7 @@ class Localdev
|
|
63
68
|
end
|
64
69
|
|
65
70
|
def debug message
|
66
|
-
puts message if @
|
71
|
+
puts message if @debugMode
|
67
72
|
end
|
68
73
|
|
69
74
|
def exit_message message
|
@@ -87,7 +92,8 @@ class Localdev
|
|
87
92
|
disable
|
88
93
|
domains = []
|
89
94
|
File.open( @localdev, 'r' ) do |file|
|
90
|
-
domains = file.read
|
95
|
+
domains = YAML::load file.read
|
96
|
+
domains = [] unless domains.respond_to? 'each'
|
91
97
|
end
|
92
98
|
File.open( @hosts, 'a' ) do |file|
|
93
99
|
file.puts "\n"
|
@@ -95,7 +101,8 @@ class Localdev
|
|
95
101
|
file.puts "# The md5 dummy entries are here so that things like MAMP Pro don't"
|
96
102
|
file.puts "# discourtiously remove our entries"
|
97
103
|
domains.each do |domain|
|
98
|
-
|
104
|
+
# puts domain.inspect
|
105
|
+
file.puts "#{domain['ip']} #{Digest::MD5.hexdigest(domain['domain'])}.#{domain['domain']} #{domain['domain']}"
|
99
106
|
end
|
100
107
|
file.puts @end
|
101
108
|
end
|
@@ -134,32 +141,43 @@ class Localdev
|
|
134
141
|
def update_localdev
|
135
142
|
domains = []
|
136
143
|
File.open( @localdev, 'r' ) do |file|
|
137
|
-
domains = file.read
|
144
|
+
domains = YAML::load file.read
|
145
|
+
domains = [] unless domains.respond_to? 'each'
|
138
146
|
debug domains.inspect
|
139
147
|
yield domains
|
140
148
|
debug domains.inspect
|
141
149
|
end
|
142
150
|
File.open( @localdev, 'w' ) do |file|
|
143
|
-
file.puts domains
|
151
|
+
file.puts YAML::dump domains
|
144
152
|
end
|
145
153
|
end
|
146
154
|
|
147
|
-
def add domain
|
148
|
-
|
155
|
+
def add domain, ip='127.0.0.1'
|
156
|
+
domain = {
|
157
|
+
'domain' => domain,
|
158
|
+
'ip' => ip
|
159
|
+
}
|
160
|
+
|
161
|
+
_remove domain['domain']
|
162
|
+
update_localdev {|domains| domains << domain }
|
149
163
|
enable if :on == get_status
|
150
|
-
puts "Added '#{domain}
|
164
|
+
puts "Added #{domain['domain']} => #{domain['ip']}"
|
151
165
|
status
|
152
166
|
end
|
153
167
|
|
154
168
|
def remove domain
|
155
|
-
|
169
|
+
_remove domain
|
156
170
|
enable if :on == get_status
|
157
|
-
puts "Removed
|
171
|
+
puts "Removed #{domain}"
|
158
172
|
status
|
159
173
|
end
|
160
174
|
|
175
|
+
def _remove domain
|
176
|
+
update_localdev {|domains| domains = domains.delete_if{|item| item['domain'] == domain } }
|
177
|
+
end
|
178
|
+
|
161
179
|
def clear
|
162
|
-
update_localdev {|domains| domains.clear
|
180
|
+
update_localdev {|domains| domains.clear }
|
163
181
|
enable if :on == get_status
|
164
182
|
puts "Removed all domains"
|
165
183
|
status
|
@@ -181,7 +199,10 @@ class Localdev
|
|
181
199
|
|
182
200
|
def list
|
183
201
|
File.open( @localdev, 'r' ) do |file|
|
184
|
-
|
202
|
+
domains = YAML::load file.read
|
203
|
+
domains.each do |domain|
|
204
|
+
puts "#{domain['domain']} => #{domain['ip']}"
|
205
|
+
end
|
185
206
|
end
|
186
207
|
end
|
187
208
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localdev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Jaquith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Localdev manages part of your hosts file and lets you specify domains
|
14
14
|
to host locally. You can quickly enable or disable local hosting of those domains.
|