Class: Redmine::Installer::Profile
- Inherits:
-
Object
- Object
- Redmine::Installer::Profile
- Includes:
- Utils
- Defined in:
- lib/redmine-installer/profile.rb
Constant Summary collapse
- CONFIG_FILE =
File.join(Dir.home, '.redmine-installer-profiles.yml')
Instance Attribute Summary collapse
-
#task ⇒ Object
Returns the value of attribute task.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(task) ⇒ Profile
constructor
A new instance of Profile.
- #load(id) ⇒ Object
- #save ⇒ Object
Methods included from Utils
Constructor Details
#initialize(task) ⇒ Profile
Returns a new instance of Profile.
33 34 35 36 37 38 39 40 41 |
# File 'lib/redmine-installer/profile.rb', line 33 def initialize(task) self.task = task # Load profiles @data = YAML.load_file(CONFIG_FILE) rescue nil # Make empty Hash if there is no profiles @data = {} unless @data.is_a?(Hash) end |
Instance Attribute Details
#task ⇒ Object
Returns the value of attribute task.
31 32 33 |
# File 'lib/redmine-installer/profile.rb', line 31 def task @task end |
Class Method Details
.check_writable ⇒ Object
26 27 28 29 |
# File 'lib/redmine-installer/profile.rb', line 26 def self.check_writable FileUtils.touch(CONFIG_FILE) File.writable?(CONFIG_FILE) end |
.load(task, id) ⇒ Object
21 22 23 24 |
# File 'lib/redmine-installer/profile.rb', line 21 def self.load(task, id) profile = Profile.new(task) profile.load(id) end |
.save(task) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/redmine-installer/profile.rb', line 11 def self.save(task) return unless check_writable return unless confirm(:do_you_want_save_step_for_further_use, true) profile = Profile.new(task) profile.save say t(:your_profile_can_be_used_as, id: profile.id), 2 end |
Instance Method Details
#id ⇒ Object
43 44 45 |
# File 'lib/redmine-installer/profile.rb', line 43 def id @id ||= @data.keys.map(&:to_i).max.to_i + 1 end |
#load(id) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/redmine-installer/profile.rb', line 59 def load(id) @id = id.to_i configuration = @data[@id] return {} if configuration.nil? task.steps.each do |_, step| step.load(configuration) end return configuration end |
#save ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/redmine-installer/profile.rb', line 47 def save # All steps save configuration which can be use again configuration = {} task.steps.each do |_, step| step.save(configuration) end @data[id] = configuration File.open(CONFIG_FILE, 'w') {|f| f.puts(YAML.dump(@data))} end |