Permalink
Browse files

New config layout facilitates having per-host configs in separate rep…

…ository.
  • Loading branch information...
1 parent 3af0b4b commit 7a01cc9c4ae03294bd7c1e8bd7328e54100b6158 @pwnall committed Dec 17, 2012
Showing with 28 additions and 25 deletions.
  1. +2 −0 CHANGELOG
  2. +1 −1 lib/rails_pwnerer/app/config.rb
  3. +25 −24 lib/rails_pwnerer/dev_executor.rb
View
@@ -1,3 +1,5 @@
+v0.7.0. New config layout facilitates having per-host configs in separate repository.
+
v0.6.109. Allow .crt for SSL certificate chains.
v0.6.108. Re-release with X-Forwarded-For for real.
@@ -89,7 +89,7 @@ def update(app_name, instance_name)
app_config[:port] = 443
end
- ["config/rails_pwnerer/.yml", "config/rails_pwnerer/#{instance_name}.yml"].each do |fname|
+ ["config/rails_pwnerer.yml", "config/rails_pwnerer/#{instance_name}.yml"].each do |fname|
next unless File.exists? fname
config_update = File.open(fname, 'r') { |f| YAML.load f } rescue nil
unless config_update
@@ -2,38 +2,38 @@
class RailsPwnerer::DevExecutor
include RailsPwnerer::Base
-
+
def read_config(instance)
if instance == '*'
- file = File.join(@config_root, '.yml')
+ file = File.join(@config_root, 'rails_pwnerer.yml')
else
- file = File.join(@config_root, instance + '.yml')
+ file = File.join(@instance_root, instance + '.yml')
end
-
+
begin
File.open(file, 'r' ) { |f| YAML.load f }
rescue
return Hash.new
end
end
-
+
def write_config(config, instance)
if instance == '*'
- file = File.join(@config_root, '.yml')
+ file = File.join(@config_root, 'rails_pwnerer.yml')
else
- file = File.join(@config_root, instance + '.yml')
+ file = File.join(@instance_root, instance + '.yml')
end
File.open(file, 'w') { |f| YAML.dump config, f }
end
-
+
def checkin_rails_app(checkin_command, path_base)
- is_empty = true
-
+ is_empty = true
+
Dir.foreach(path_base) do |entry|
# skip uninteresting entries
next if ['.', '..'].include? entry
-
+
# check in files and subdirectories
is_empty = false
path = File.join path_base, entry
@@ -44,61 +44,62 @@ def checkin_rails_app(checkin_command, path_base)
checkin_rails_app checkin_command, path
end
end
-
+
if is_empty
# workaround to check in blank directory
- path = File.join path_base, '.not_blank'
+ path = File.join path_base, '.keep'
File.open(path, 'w') { |f| f.write '' }
Kernel.system "#{checkin_command} add #{path}"
end
end
-
-
+
+
# standalone runner
def run(args)
unless check_rails_root '.'
print "You need to run this at the root of your Rails application\n"
return
end
-
+
# create the config root unless it exists
- @config_root = 'config/rails_pwnerer'
- Dir.mkdir @config_root unless File.exists? @config_root
-
+ @config_root = 'config'
+ @instance_root = File.join @config_root, 'rails_pwnerer'
+ Dir.mkdir @instance_root unless File.exists?(@instance_root)
+
case args[0]
when 'get', 'getprop'
property = args[1]
instance = args[2] || '*'
config = read_config instance
pp config[property]
-
+
when 'set', 'setprop', 'setnum', 'setpropnum'
property = args[1]
if args[0].index 'num'
value = eval(args[2] || '1')
else
value = args[2] || 'true'
end
-
+
instance = args[3] || '*'
config = read_config instance
config[property] = value
write_config config, instance
-
+
when 'del', 'delprop', 'delete', 'rm', 'remove'
property = args[1]
instance = args[2] || '*'
config = read_config instance
config.delete property
write_config config, instance
-
+
when 'checkin'
unless args[1]
print "Please provide the checkin command (e.g. git).\n"
exit
end
checkin_rails_app args[1], '.'
-
+
else
print "Unrecognized command #{args[0]}\n"
end

0 comments on commit 7a01cc9

Please sign in to comment.