Class: RedmineInstaller::Package
- Inherits:
-
TaskModule
- Object
- TaskModule
- RedmineInstaller::Package
- Defined in:
- lib/redmine-installer/package.rb
Constant Summary collapse
- SUPPORTED_ARCHIVE_FORMATS =
['.zip', '.gz', '.tgz']
- TAR_LONGLINK =
'././@LongLink'
Constants included from Utils
Instance Attribute Summary collapse
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#temp_dir ⇒ Object
readonly
Returns the value of attribute temp_dir.
Attributes inherited from TaskModule
Instance Method Summary collapse
- #clean_up ⇒ Object
- #ensure_and_valid_package ⇒ Object
- #extract ⇒ Object
-
#initialize(task, package) ⇒ Package
constructor
A new instance of Package.
-
#redmine_root ⇒ Object
Move files from temp dir to target.
Methods included from Utils
#class_name, #create_dir, #env_user, #error, #logger, #ok, #pastel, #print_title, #prompt, #run_command
Constructor Details
#initialize(task, package) ⇒ Package
Returns a new instance of Package.
14 15 16 17 |
# File 'lib/redmine-installer/package.rb', line 14 def initialize(task, package) super(task) @package = package.to_s end |
Instance Attribute Details
#package ⇒ Object (readonly)
Returns the value of attribute package.
12 13 14 |
# File 'lib/redmine-installer/package.rb', line 12 def package @package end |
#temp_dir ⇒ Object (readonly)
Returns the value of attribute temp_dir.
12 13 14 |
# File 'lib/redmine-installer/package.rb', line 12 def temp_dir @temp_dir end |
Instance Method Details
#clean_up ⇒ Object
80 81 82 83 |
# File 'lib/redmine-installer/package.rb', line 80 def clean_up @temp_dir && FileUtils.remove_entry_secure(@temp_dir) @temp_file && FileUtils.remove_entry_secure(@temp_file) end |
#ensure_and_valid_package ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/redmine-installer/package.rb', line 19 def ensure_and_valid_package if package.empty? @package = prompt.ask('Path to package:', required: true) end if !File.exist?(@package) if @package =~ /\Av?(\d\.\d\.\d)\Z/ @package = download_redmine_version($1) elsif valid_url?(@package) @package = download_from_url(@package) else error "File doesn't exist #{@package}" end end @type = File.extname(@package) unless SUPPORTED_ARCHIVE_FORMATS.include?(@type) error "File #{@package} must have format: #{SUPPORTED_ARCHIVE_FORMATS.join(', ')}" end end |
#extract ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/redmine-installer/package.rb', line 40 def extract print_title('Extracting redmine package') @temp_dir = Dir.mktmpdir case @type when '.zip' extract_zip when '.gz', '.tgz' extract_tar_gz end logger.info("Package was loaded into #{@temp_dir}.") end |
#redmine_root ⇒ Object
Move files from temp dir to target. First check if folder contains redmine or contains folder which contains redmine.
Package can have format: |– redmine-2
|-- app
`-- config
…
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/redmine-installer/package.rb', line 64 def redmine_root root = @temp_dir loop { ls = Dir.glob(File.join(root, '*')) if ls.size == 1 root = ls.first else break end } root end |