class Marv::Project::Actions
Public Class Methods
new(project, builder)
click to toggle source
Initialize project actions
# File lib/marv/project/actions.rb, line 8 def initialize(project, builder) @project = project @task = project.task @builder = builder @global = Marv::Global.new(project.task) end
Public Instance Methods
build_to_temp_dir()
click to toggle source
Built to a temporary directory
# File lib/marv/project/actions.rb, line 134 def build_to_temp_dir @builder.build_project # Copy build files to temporary directory @task.shell.mute do @task.directory @project.build_path, ::File.join(@project.package_path, @package_name), :force => true end end
create_link()
click to toggle source
Create
project link
# File lib/marv/project/actions.rb, line 87 def create_link unless ::File.directory?(@project.build_path) @task.shell.mute do @task.empty_directory @project.build_path end end begin @task.create_link @link_target, @project.build_path rescue Exception => e @task.say_error "An error occured while creating project link", e.message, false. true abort end end
create_package()
click to toggle source
Create
package
# File lib/marv/project/actions.rb, line 103 def create_package create_package_dir set_package_filename build_to_temp_dir create_temp_zip create_zip_file remove_temp_files end
create_package_dir()
click to toggle source
Create
package directory
# File lib/marv/project/actions.rb, line 113 def create_package_dir @task.shell.mute do unless ::File.directory?(@project.package_path) @task.empty_directory @project.package_path end end end
create_temp_zip()
click to toggle source
Create
temporary package
# File lib/marv/project/actions.rb, line 144 def create_temp_zip tmp_filename = ::File.join(@project.package_path, "#{@package_name}.tmp") # Create an temporary file ::Zip.continue_on_exists_proc = true ::Zip::File.open(tmp_filename, Zip::File::CREATE) do |zip| # Get all filenames filenames = ::Dir.glob(::File.join(@project.package_path, @package_name, '**', '*')) # Add each file in the zip file filenames.each do |filename| zip.add filename.gsub("#{@project.package_path}/", ''), filename end end end
create_zip_file()
click to toggle source
Create
the package
# File lib/marv/project/actions.rb, line 161 def create_zip_file zip_filename = ::File.join(@project.package_path, "#{@package_name}.zip") @task.copy_file ::File.join(@project.package_path, "#{@package_name}.tmp"), zip_filename end
get_package_name()
click to toggle source
Get package name
# File lib/marv/project/actions.rb, line 129 def get_package_name ::File.basename(@project.root) end
link(dir)
click to toggle source
Link project
# File lib/marv/project/actions.rb, line 16 def link(dir) @link_dir = dir @task.say_warning "This will link project #{@project.project_id} to server #{dir}." link_options link_target @task.say_empty create_link end
link_global()
click to toggle source
Link global
# File lib/marv/project/actions.rb, line 66 def link_global if @link_dir == 'global' ::File.join(@global.global_path, @link_options[:folder], ::File.basename(@project.root)) end end
link_options()
click to toggle source
Ask for link details
# File lib/marv/project/actions.rb, line 38 def link_options options = {} options[:folder] = @task.ask_input "Where do you want to link your project?", :limited_to => ["themes", "plugins"], :default => "themes" @link_options = options end
link_target()
click to toggle source
Link target
# File lib/marv/project/actions.rb, line 73 def link_target target = link_to_server unless link_to_server.nil? target = link_to_folder unless link_to_folder.nil? target = link_global unless link_global.nil? if target.nil? @task.say_error "Destination server does not exist!", nil, false, true abort end @link_target = target end
link_to_folder()
click to toggle source
Link to wordpress
# File lib/marv/project/actions.rb, line 57 def link_to_folder unless @link_dir == 'global' if ::File.directory?(@link_dir) ::File.join(@link_dir, 'wp-content', @link_options[:folder], ::File.basename(@project.root)) end end end
link_to_server()
click to toggle source
Link to server
# File lib/marv/project/actions.rb, line 46 def link_to_server unless @link_dir == 'global' path = ::File.join(@global.servers_path, @link_dir, 'wp-content', @link_options[:folder]) if ::File.directory?(path) ::File.join(path, ::File.basename(@project.root)) end end end
package(filename)
click to toggle source
Packgage project
# File lib/marv/project/actions.rb, line 29 def package(filename) @package_name = filename pkg_name = filename || get_package_name @task.say_warning "This will package project #{@project.project_id} as #{pkg_name}.zip." create_package end
remove_temp_files()
click to toggle source
Remove temporary build directory
# File lib/marv/project/actions.rb, line 167 def remove_temp_files @task.shell.mute do @task.remove_dir ::File.join(@project.package_path, @package_name) @task.remove_file ::File.join(@project.package_path, "#{@package_name}.tmp") end end
set_package_filename()
click to toggle source
Set the package file name
# File lib/marv/project/actions.rb, line 122 def set_package_filename if @package_name.nil? @package_name = get_package_name end end