class RailsPwnerer::DevExecutor

Public Instance Methods

checkin_rails_app(checkin_command, path_base) click to toggle source
   # File lib/rails_pwnerer/dev_executor.rb
30 def checkin_rails_app(checkin_command, path_base)
31   is_empty = true
32 
33   Dir.foreach(path_base) do |entry|
34     # skip uninteresting entries
35     next if ['.', '..'].include? entry
36 
37     # check in files and subdirectories
38     is_empty = false
39     path = File.join path_base, entry
40     if File.file? path
41       Kernel.system "#{checkin_command} add #{path}"
42       has_files = true
43     else
44       checkin_rails_app checkin_command, path
45     end
46   end
47 
48   if is_empty
49     # workaround to check in blank directory
50     path = File.join path_base, '.keep'
51     File.open(path, 'w') { |f| f.write '' }
52     Kernel.system "#{checkin_command} add #{path}"
53   end
54 end
read_config(instance) click to toggle source
   # File lib/rails_pwnerer/dev_executor.rb
 6 def read_config(instance)
 7   if instance == '*'
 8     file = File.join(@config_root, 'rails_pwnerer.yml')
 9   else
10     file = File.join(@instance_root, instance + '.yml')
11   end
12 
13   begin
14     File.open(file, 'r' ) { |f| YAML.load f }
15   rescue
16     return Hash.new
17   end
18 end
run(args) click to toggle source

standalone runner

    # File lib/rails_pwnerer/dev_executor.rb
 58 def run(args)
 59   unless check_rails_root '.'
 60     print "You need to run this at the root of your Rails application\n"
 61     return
 62   end
 63 
 64   # create the config root unless it exists
 65   @config_root = 'config'
 66   @instance_root = File.join @config_root, 'rails_pwnerer'
 67   Dir.mkdir @instance_root unless File.exists?(@instance_root)
 68 
 69   case args[0]
 70   when 'get', 'getprop'
 71     property = args[1]
 72     instance = args[2] || '*'
 73     config = read_config instance
 74     pp config[property]
 75 
 76   when 'set', 'setprop', 'setnum', 'setpropnum'
 77     property = args[1]
 78     if args[0].index 'num'
 79       value = eval(args[2] || '1')
 80     else
 81       value = args[2] || 'true'
 82     end
 83 
 84     instance = args[3] || '*'
 85     config = read_config instance
 86     config[property] = value
 87     write_config config, instance
 88 
 89   when 'del', 'delprop', 'delete', 'rm', 'remove'
 90     property = args[1]
 91     instance = args[2] || '*'
 92     config = read_config instance
 93     config.delete property
 94     write_config config, instance
 95 
 96   when 'checkin'
 97     unless args[1]
 98       print "Please provide the checkin command (e.g. git).\n"
 99       exit
100     end
101     checkin_rails_app args[1], '.'
102 
103   else
104     print "Unrecognized command #{args[0]}\n"
105   end
106 end
write_config(config, instance) click to toggle source
   # File lib/rails_pwnerer/dev_executor.rb
20 def write_config(config, instance)
21   if instance == '*'
22     file = File.join(@config_root, 'rails_pwnerer.yml')
23   else
24     file = File.join(@instance_root, instance + '.yml')
25   end
26 
27   File.open(file, 'w') { |f| YAML.dump config, f }
28 end