lib/dvdprofiler2xbmc/app_config.rb in royw-dvdprofiler2xbmc-0.0.17 vs lib/dvdprofiler2xbmc/app_config.rb in royw-dvdprofiler2xbmc-0.0.18
- old
+ new
@@ -12,56 +12,69 @@
# @config, @help, @initial, @data_type, @validate, and @validate_item
# are mashes that share the same keys. For example @help.foo would be
# the help text for @config.foo
+ # == Synopsis
# the current config values
@config = Mash.new
+ # == Synopsis
# help about the config item
@help = Mash.new
+ # == Synopsis
# initial (default) config values
@initial = Mash.new
+ # == Synopsis
# data type constants used in the editor
@data_type = Mash.new
+ # == Synopsis
# validate the config item
@validate = Mash.new
+ # == Synopsis
# validate an entry for a config item, note usually need to allow
# empty string for either array entry termination or to accept
# a default value
@validate_item = Mash.new
+ # == Synopsis
# the @navigation array contains hashes where each hash is a "page"
# that contains an array of @config keys. This provides a natural
# organization for UIs.
@navigation = []
+ # make class variables readable
class << self
attr_reader :help, :initial, :navigation, :config, :data_type, :validate, :validate_item
end
+ # the user's config file
@yaml_filespec = File.join(ENV['HOME'], '.dvdprofiler2xbmcrc')
+ # == Synopsis
# shortcut accessor for @config items
def self.[](k)
@config[k]
end
+ # == Synopsis
# shortcut accessor for @config items
def self.[]=(k,v)
@config[k] = v
end
+ # == Synopsis
# does the config file exist?
def self.exist?
File.exist?(@yaml_filespec)
end
+ # == Synopsis
# load the config file, overwriting current values
def self.load
begin
if File.exist?(@yaml_filespec)
cfg = YAML.load_file(@yaml_filespec)
@@ -86,10 +99,11 @@
rescue Exception => e
AppConfig[:logger].error { "Error loading config file \"#{@yaml_filespec} - " + e.to_s + "\n" + e.backtrace.join("\n") }
end
end
+ # == Synopsis
# save the config file
def self.save
begin
unless @config.blank?
File.delete(@yaml_filespec) if File.exist?(@yaml_filespec)
@@ -103,10 +117,11 @@
rescue Exception => e
AppConfig[:logger].error { "Error saving config file \"#{@yaml_filespec} - " + e.to_s + "\n" + e.backtrace.join("\n")}
end
end
+ # == Synopsis
# generate a string for displaying the current config
def self.to_s
buf = []
@navigation.each do |page|
page.each do |heading, keys|
@@ -125,10 +140,11 @@
end
end
buf.join("\n")
end
+ # == Synopsis
# is the current config valid?
def self.valid?
valid = true
@validate.each do |field, value|
unless @validate[field].call(@config[field])
@@ -136,10 +152,11 @@
end
end
valid
end
+ # == Synopsis
# set the config to the default values
def self.default
# Note, all paths and extensions are case sensitive
# this is the version of the rc file and is used to trigger
@@ -328,10 +345,9 @@
:no_isbn => 'no_isbn',
:no_imdb_lookup => 'no_imdb_lookup',
:no_tmdb_lookup => 'no_tmdb_lookup',
}
@config.extensions = @initial.extensions
-# @data_type.extensions = :HASH_FIXED_SYMBOL_KEYS_STRING_VALUES
# substitutions:
# %t => movie title
# %e => extension from @config.extensions
# %p => part