Module: Itunes::Util::Executor
Instance Method Summary collapse
- #execute_script(script_path, args = '') ⇒ Object
- #execute_template_based_script(script_path) ⇒ Object
- #generate_script_from_template(template_path, args) ⇒ Object
- #script_base_dir ⇒ Object
- #script_tmp_dir ⇒ Object
Instance Method Details
#execute_script(script_path, args = '') ⇒ Object
25 26 27 28 |
# File 'lib/itunes/util/executor.rb', line 25 def execute_script(script_path, args='') execute_out, process_status = *Open3.capture2("osascript #{script_base_dir}/#{script_path} #{args}") execute_out.chomp end |
#execute_template_based_script(script_path) ⇒ Object
30 31 32 33 34 |
# File 'lib/itunes/util/executor.rb', line 30 def execute_template_based_script(script_path) execute_out, process_status = *Open3.capture2("osascript #{script_tmp_dir}/#{script_path}") ::FileUtils.rm "#{script_tmp_dir}/#{script_path}" execute_out.chomp end |
#generate_script_from_template(template_path, args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/itunes/util/executor.rb', line 5 def generate_script_from_template(template_path, args) body = '' script_name = "#{Time.now.to_i}.#{rand(1000)}.scpt" script_path = "#{script_tmp_dir}/#{script_name}" open("#{script_base_dir}/#{template_path}", 'r') do |f| f.each { |line| body << line } end args.each do |key, val| body.gsub!("#\{#{key}\}", val) end open(script_path, 'w') do |f| f.write(body) end script_name end |
#script_base_dir ⇒ Object
36 37 38 |
# File 'lib/itunes/util/executor.rb', line 36 def script_base_dir File.("#{File.dirname(__FILE__)}/../../../scripts") end |
#script_tmp_dir ⇒ Object
40 41 42 |
# File 'lib/itunes/util/executor.rb', line 40 def script_tmp_dir Dir.tmpdir end |