Class: RailsPwnerer::DevExecutor

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/rails_pwnerer/dev_executor.rb

Instance Method Summary collapse

Methods included from Base

_setup_unix, _setup_windows, all_packages, all_packages_without_caching, #atomic_erase, #atomic_read, #atomic_write, #best_package_matching, #check_rails_root, #control_boot_script, #cpu_cores, #current_user, #gem_exists?, #gid_for_username, #group_for_username, #hook_boot_script, #install_gem, #install_gems, #install_package, #install_package_impl, #install_package_matching, #install_packages, #kill_tree, #os_distro, package_info_hash, #path_to_boot_script, #path_to_boot_script_defaults, #path_to_gemdir, #process_info, #prompt_user_for_password, #remove_package, #remove_packages, #search_packages, #uid_for_username, #unroll_collection, #update_all_packages, #update_all_packages_impl, #update_gems, #update_package_metadata, #upgrade_gem, #upgrade_gems, #upgrade_package, #upgrade_package_impl, #upgrade_packages, #with_package_source, #with_temp_dir

Instance Method Details

#checkin_rails_app(checkin_command, path_base) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails_pwnerer/dev_executor.rb', line 30

def checkin_rails_app(checkin_command, path_base)
  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
    if File.file? path
      Kernel.system "#{checkin_command} add #{path}"
      has_files = true
    else
      checkin_rails_app checkin_command, path
    end
  end

  if is_empty
    # workaround to check in blank directory
    path = File.join path_base, '.keep'
    File.open(path, 'w') { |f| f.write '' }
    Kernel.system "#{checkin_command} add #{path}"
  end
end

#read_config(instance) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rails_pwnerer/dev_executor.rb', line 6

def read_config(instance)
  if instance == '*'
    file = File.join(@config_root, 'rails_pwnerer.yml')
  else
    file = File.join(@instance_root, instance + '.yml')
  end

  begin
    File.open(file, 'r' ) { |f| YAML.load f }
  rescue
    return Hash.new
  end
end

#run(args) ⇒ Object

standalone runner



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rails_pwnerer/dev_executor.rb', line 58

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'
  @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
end

#write_config(config, instance) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rails_pwnerer/dev_executor.rb', line 20

def write_config(config, instance)
  if instance == '*'
    file = File.join(@config_root, 'rails_pwnerer.yml')
  else
    file = File.join(@instance_root, instance + '.yml')
  end

  File.open(file, 'w') { |f| YAML.dump config, f }
end