Class: Redmine::Installer::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine-installer/task.rb

Direct Known Subclasses

Backup, Install, Upgrade

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Task

Returns a new instance of Task.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/redmine-installer/task.rb', line 15

def initialize(options={})
  self.options = options
  self.settings = {}
  self.env = options[:env]

  # Initialize steps for task
  @steps = {}
  index = 1
  self.class::STEPS.each do |step|
    @steps[index] = step.new(index, self)
    index += 1
  end
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



11
12
13
# File 'lib/redmine-installer/task.rb', line 11

def env
  @env
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/redmine-installer/task.rb', line 9

def options
  @options
end

#redmine_rootObject

Returns the value of attribute redmine_root.



7
8
9
# File 'lib/redmine-installer/task.rb', line 7

def redmine_root
  @redmine_root
end

#settingsObject

Returns the value of attribute settings.



10
11
12
# File 'lib/redmine-installer/task.rb', line 10

def settings
  @settings
end

#stepsObject (readonly)

Returns the value of attribute steps.



13
14
15
# File 'lib/redmine-installer/task.rb', line 13

def steps
  @steps
end

#tmp_redmine_rootObject

Returns the value of attribute tmp_redmine_root.



8
9
10
# File 'lib/redmine-installer/task.rb', line 8

def tmp_redmine_root
  @tmp_redmine_root
end

Class Method Details

.inherited(child) ⇒ Object

Creating methods for recognition type of task

Examples:

class Install < Task
end

Install.new.install? #=> true


75
76
77
78
79
80
81
82
# File 'lib/redmine-installer/task.rb', line 75

def self.inherited(child)
  method_name = "#{child.class_name.downcase}?".to_sym

  define_method(method_name) { false }
  child.send(:define_method, method_name) { true }

  super
end

.stepObject



63
64
65
# File 'lib/redmine-installer/task.rb', line 63

def self.step
  Redmine::Installer::Step
end

Instance Method Details

#check_packageObject

Package is required for install task and upgrade with source file



57
58
59
60
61
# File 'lib/redmine-installer/task.rb', line 57

def check_package
  if package.nil?
    raise Redmine::Installer::Error, I18n.translate(:error_argument_package_is_missing)
  end
end

#runObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/redmine-installer/task.rb', line 29

def run
  @steps.each do |id, step|
    step.print_title
    step.print_header
    step.up
    step.print_footer
    step.ran = true
    puts # new line
  end

  @steps.each do |id, step|
    step.final_step
  end
rescue Redmine::Installer::Error => e
  # Rescue from error comes from installer
  # run steps again for cleaning
  @steps.values.reverse.each do |step|
    next unless step.ran
    step.down
  end

  $stderr.puts(ANSI.red, e.message, ANSI.clear)
  $stderr.flush
  exit(1)
end