localdev 0.3.2 → 0.4.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/localdev.rb +38 -17
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80ee8a71006d5f83bb9d7337d69694981c8f58bc
4
- data.tar.gz: 3d845faf2a9dbd5ddbc51a33f13ab26493856805
3
+ metadata.gz: ebc540a4cd5ea1afa2d2105340916d0c87f532a1
4
+ data.tar.gz: 8dd912ccd5ee08e8a24b05a84d115b6981e2647e
5
5
  SHA512:
6
- metadata.gz: cd1eac2f6ccbd745aa334ab385e1e461e7218821fa5fe08708d25d6bd3b875bc185ab50fd2179e5324e400759b4566394467be09febc3aa0b51ec3b2c02a9814
7
- data.tar.gz: 9b2a9cd25c95330a5154c04b286f3bd38a26fa9119000c67c64350abd21d572ad2110413c5ae4b5367c3aa5211f503dc85542ceae0a0f2bbdae609f09e3325ff
6
+ metadata.gz: 36236ab97c1728cf2216c95817e7a11e02f1032a65e29651498b29e1680018db18c4d5221a78aa5fdceec55c1e63647d5fabb942c2dbdd289bd104a00152db8c
7
+ data.tar.gz: 15d62ffa4ce494922763c2266b0ecfcb3a74d68bdad0aadc3c2c20c4519244dab2d31fd5c27ccdcb45631b42b5999f061c98f9ebe7be112d272e4aa41ee2a1c2
@@ -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.3.2'
24
+ VERSION = '0.4.0'
24
25
 
25
26
  def initialize
26
- @debug = false
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
- send command, object
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 @debug
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.split("\n").uniq
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
- file.puts "127.0.0.1 #{Digest::MD5.hexdigest(domain)}.#{domain} #{domain}"
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.split("\n")
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
- update_localdev {|domains| domains << domain unless domains.include? domain }
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
- update_localdev {|domains| domains = domains.delete domain }
169
+ _remove domain
156
170
  enable if :on == get_status
157
- puts "Removed '#{domain}'"
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
- puts file.read
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.3.2
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-01 00:00:00.000000000 Z
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.