Module: EasyStart
- Defined in:
- lib/easy_start.rb,
lib/easy_start/version.rb
Constant Summary collapse
- VERSION =
"0.1.3"
Class Method Summary collapse
- .add(project) ⇒ Object
- .create_directory_if_not_found ⇒ Object
- .create_script(base_data) ⇒ Object
- .get_root_path(name) ⇒ Object
- .launch(launch_data, branch = '') ⇒ Object
- .launch_console(name) ⇒ Object
- .meta_data ⇒ Object
Class Method Details
.add(project) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/easy_start.rb', line 5 def self.add(project) base_data = {'project_name' => '', 'project_path' => ''} base_data.each do |key,value| loop do base_data[key] = project[key] unless base_data[key].present? puts "Enter #{key}" input = gets.chomp base_data[key] = input end break if base_data[key].present? end end create_script base_data end |
.create_directory_if_not_found ⇒ Object
28 29 30 31 32 33 |
# File 'lib/easy_start.rb', line 28 def self.create_directory_if_not_found directory_path = File.join(File.dirname(__FILE__), "../scripts") unless File.directory?(directory_path) Dir.mkdir directory_path end end |
.create_script(base_data) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/easy_start.rb', line 21 def self.create_script base_data create_directory_if_not_found file_path = File.join(File.dirname(__FILE__), "../scripts/#{base_data['project_name']}.sh") File.open(file_path, 'w') {|f| f.write("ROOT_PATH=\"#{base_data['project_path']}\"\n" + ) } system "chmod 755 #{file_path}" end |
.get_root_path(name) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/easy_start.rb', line 58 def self.get_root_path(name) root_path = "" file_path = File.join(File.dirname(__FILE__), "../scripts/#{name}.sh") File.open(file_path).each do |line| if line.include? 'ROOT_PATH=' line.slice!("ROOT_PATH=\"") line.slice!("\"\n") root_path = line break end end root_path end |
.launch(launch_data, branch = '') ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/easy_start.rb', line 35 def self.launch(launch_data,branch='') name = launch_data.respond_to?(:keys) ? launch_data['launch_project_name'] : launch_data port = launch_data['project_port'] || '3000' branch = launch_data['project_branch'] || branch begin file_path = File.join(File.dirname(__FILE__), "../scripts/#{name}.sh") a = system "#{file_path}", port ,(branch || '') rescue SystemExit, Interrupt exit 0 rescue Exception => e puts e end end |
.launch_console(name) ⇒ Object
49 50 51 52 |
# File 'lib/easy_start.rb', line 49 def self.launch_console(name) root_path = get_root_path(name) system "cd #{root_path} && rails c" end |
.meta_data ⇒ Object
54 55 56 |
# File 'lib/easy_start.rb', line 54 def self. ['cd "$ROOT_PATH"','if [ -n "$2" ]; then','git checkout $2','git pull','fi','rails s -p $1'].join("\n") end |