class RedmineInstaller::Profile

Constants

PROFILES_FILE

Attributes

id[R]

Public Class Methods

get!(profile_id) click to toggle source
# File lib/redmine-installer/profile.rb, line 8
def self.get!(profile_id)
  data = YAML.load_file(PROFILES_FILE) rescue nil

  if data.is_a?(Hash) && data.has_key?(profile_id)
    Profile.new(profile_id, data[profile_id])
  else
    raise RedmineInstaller::ProfileError, "Profile ID=#{profile_id} does not exist"
  end
end
new(id=nil, data={}) click to toggle source
Calls superclass method
# File lib/redmine-installer/profile.rb, line 20
def initialize(id=nil, data={})
  super(data)
  @id = id
end

Public Instance Methods

save() click to toggle source
# File lib/redmine-installer/profile.rb, line 25
def save
  FileUtils.touch(PROFILES_FILE)

  all_data = YAML.load_file(PROFILES_FILE)
  all_data = {} unless all_data.is_a?(Hash)

  @id ||= all_data.keys.last.to_i + 1

  all_data[@id] = to_h

  File.write(PROFILES_FILE, YAML.dump(all_data))

  puts "Profile was saved under ID=#{@id}"
rescue => e
  puts "Profile could not be save due to #{e.message}"
end