Class: RedmineInstaller::Profile
- Defined in:
- lib/redmine-installer/profile.rb
Constant Summary collapse
- PROFILES_FILE =
File.join(Dir.home, '.redmine-installer-profiles.yml')
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id = nil, data = {}) ⇒ Profile
constructor
A new instance of Profile.
- #save ⇒ Object
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
#id ⇒ Object (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, aliases: true) 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
#save ⇒ Object
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, aliases: true) 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.}" end |