lib/visage-app/profile.rb in visage-app-0.3.3 vs lib/visage-app/profile.rb in visage-app-0.9.0.pre1
- old
+ new
@@ -9,19 +9,23 @@
module Visage
class Profile
attr_reader :options, :selected_hosts, :hosts, :selected_metrics, :metrics,
:name, :errors
+ def self.load
+ Visage::Config::File.load('profiles.yaml', :create => true, :ignore_bundled => true) || {}
+ end
+
def self.get(id)
url = id.downcase.gsub(/[^\w]+/, "+")
- profiles = Visage::Config.profiles || {}
+ profiles = self.load
profiles[url] ? self.new(profiles[url]) : nil
end
def self.all(opts={})
sort = opts[:sort]
- profiles = Visage::Config.profiles || {}
+ profiles = self.load
profiles = sort == "name" ? profiles.sort.map {|i| i.last } : profiles.values
profiles.map { |prof| self.new(prof) }
end
def initialize(opts={})
@@ -61,10 +65,10 @@
:metrics => @options[:metrics],
:profile_name => @options[:profile_name],
:url => @options[:profile_name].downcase.gsub(/[^\w]+/, "+") }
# Save it.
- profiles = Visage::Config.profiles || {}
+ profiles = self.load
profiles[attrs[:url]] = attrs
Visage::Config::File.open('profiles.yaml') do |file|
file << profiles.to_yaml
end