class OfflineDeployer::Maker
Attributes
destination[R]
from_tag[R]
long_name[R]
to_tag[R]
Public Class Methods
new(from_tag = nil, to_tag = nil, destination = nil)
click to toggle source
# File lib/offline_deployer/maker.rb, line 3 def initialize(from_tag = nil, to_tag = nil, destination = nil) @from_tag = from_tag.presence || default_from_tag @to_tag = to_tag.presence || default_to_tag @destination = destination || default_destination @long_name = from_tag.present? end
Public Instance Methods
call()
click to toggle source
# File lib/offline_deployer/maker.rb, line 12 def call pull_and_bundle unless Rails.env.development? write_update_info_and_deleted_files add_files_to_archive handle_gems move_archive_to_destination print_release_info return_file_path_and_name end
Private Instance Methods
add_files_to_archive()
click to toggle source
# File lib/offline_deployer/maker.rb, line 83 def add_files_to_archive `cd #{app_root} && git archive -o #{archive_file_path} #{to_tag} #{archive_files.join(' ')}` `cd #{app_root} && zip #{archive_file_path} .update` end
app_root()
click to toggle source
# File lib/offline_deployer/maker.rb, line 24 def app_root OfflineDeployer.settings.app_root end
archive_file_name()
click to toggle source
# File lib/offline_deployer/maker.rb, line 88 def archive_file_name long_name ? "#{archive_name_prefix}-#{from_tag}-#{to_tag}.zip" : "#{archive_name_prefix}-#{to_tag}.zip" end
archive_file_path()
click to toggle source
# File lib/offline_deployer/maker.rb, line 92 def archive_file_path "#{app_root}/#{archive_file_name}" end
archive_files()
click to toggle source
# File lib/offline_deployer/maker.rb, line 75 def archive_files @archive_files ||= get_file_names(changed_files - deleted_files) end
archive_name_prefix()
click to toggle source
# File lib/offline_deployer/maker.rb, line 96 def archive_name_prefix OfflineDeployer.settings.archive_name_prefix end
changed_files()
click to toggle source
# File lib/offline_deployer/maker.rb, line 67 def changed_files @changed_files ||= `cd #{app_root} && git diff --name-status #{from_tag} #{to_tag}`.split("\n") end
default_destination()
click to toggle source
# File lib/offline_deployer/maker.rb, line 49 def default_destination "#{app_root}/tmp/releases/versions/" end
default_from_tag()
click to toggle source
# File lib/offline_deployer/maker.rb, line 41 def default_from_tag tags[1] end
default_to_tag()
click to toggle source
# File lib/offline_deployer/maker.rb, line 45 def default_to_tag tags[0] end
deleted_files()
click to toggle source
# File lib/offline_deployer/maker.rb, line 71 def deleted_files @deleted_files ||= changed_files.select { |file| file.starts_with?('D') } end
get_file_names(files_array)
click to toggle source
# File lib/offline_deployer/maker.rb, line 79 def get_file_names(files_array) files_array.map { |file| file.split("\t")[1] } end
handle_gems()
click to toggle source
# File lib/offline_deployer/maker.rb, line 100 def handle_gems OfflineDeployer::GemsHandler.new(from_tag, to_tag, app_root, archive_file_path).call end
move_archive_to_destination()
click to toggle source
# File lib/offline_deployer/maker.rb, line 104 def move_archive_to_destination FileUtils.mkdir_p destination `mv #{archive_file_path} #{destination}` end
print_release_info()
click to toggle source
# File lib/offline_deployer/maker.rb, line 109 def print_release_info puts 'Added files:' puts archive_files.join("\n") puts "FROM_VERSION: #{from_tag}, TO_VERSION: #{to_tag}" puts "Created #{archive_file_name} in #{destination}" end
pull_and_bundle()
click to toggle source
# File lib/offline_deployer/maker.rb, line 28 def pull_and_bundle Dir.chdir(app_root) do `git pull` Bundler.with_clean_env do `bundle install` end end end
return_file_path_and_name()
click to toggle source
# File lib/offline_deployer/maker.rb, line 116 def return_file_path_and_name ["#{destination}/#{archive_file_name}", archive_file_name] end
write_update_info_and_deleted_files()
click to toggle source
# File lib/offline_deployer/maker.rb, line 53 def write_update_info_and_deleted_files File.open('.update', 'w+') do |f| f.write( { FROM_VERSION: from_tag, TO_VERSION: to_tag, DELETED_FILES: get_file_names(deleted_files) }.to_yaml ) end `mv .update #{app_root}` unless Rails.env.development? end