Class: RedmineInstaller::Profile

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

Constant Summary collapse

PROFILES_FILE =
File.join(Dir.home, '.redmine-installer-profiles.yml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, data = {}) ⇒ Profile

Returns a new instance of Profile.



20
21
22
23
# File 'lib/redmine-installer/profile.rb', line 20

def initialize(id=nil, data={})
  super(data)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'lib/redmine-installer/profile.rb', line 18

def id
  @id
end

Class Method Details

.get!(profile_id) ⇒ Object



8
9
10
11
12
13
14
15
16
# 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

Instance Method Details

#saveObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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