class Shibkit::MetaMeta::Config
Constants
- DEV_SOURCES_FILE
Location of default mock sources list (contains small fictional federations)
- REAL_SOURCES_FILE
Location of default real sources list (contains real-world federation details)
- TEST_SOURCES_FILE
Location of default test sources list # TODO
- VERSION_FILE
Slurp
Public Class Methods
# File lib/shibkit/meta_meta/config.rb, line 46 def initialize(&block) @logger = ::Logger.new(STDOUT) @logger.level = ::Logger::INFO @logger.datetime_format = "%Y-%m-%d %H:%M:%S" @logger.formatter = proc { |severity, datetime, progname, msg| "#{datetime}: #{severity} #{msg}\n" } @logger.progname = "MetaMeta" @download_cache_options = Hash.new @sources_file = :auto @selected_federation_uris = [] ## Execute block if passed one ## Does not get one. Needs a work around, eventually. instance_eval(&block) if block end
Public Instance Methods
@return [String]
# File lib/shibkit/meta_meta/config.rb, line 285 def auto_refresh=(bool) @auto_refresh = bool ? true : false end
@return [String]
# File lib/shibkit/meta_meta/config.rb, line 292 def auto_refresh? return @auto_refresh.nil? ? true : @auto_refresh end
# File lib/shibkit/meta_meta/config.rb, line 311 def auto_tag=(bool) @auto_tag = bool ? true : false end
# File lib/shibkit/meta_meta/config.rb, line 318 def auto_tag? return @auto_tag.nil? ? false : @auto_tag end
Load a metadata sources file automatically (true or false)
# File lib/shibkit/meta_meta/config.rb, line 220 def autoload=(setting) @autoload = setting ? true : false end
Should metadata sources and objects be loaded automatically? Normally, yes.
# File lib/shibkit/meta_meta/config.rb, line 227 def autoload? return true unless defined? @autoload return @autoload end
# File lib/shibkit/meta_meta/config.rb, line 185 def cache_fallback_ttl return @cache_fallback_ttl.nil? ? 7200 : @cache_fallback_ttl end
# File lib/shibkit/meta_meta/config.rb, line 178 def cache_fallback_ttl=(seconds) @cache_fallback_ttl = seconds.to_i self.download_cache_options = { :default_ttl => @cache_fallback_ttl } end
return or calculate the filesystem path to store the web cache
# File lib/shibkit/meta_meta/config.rb, line 407 def cache_root unless @cache_root tmp_dir = sensible_os? ? '/tmp' : ENV['TEMP'] @cache_root = File.join(tmp_dir, 'skmm-cache') end return @cache_root end
Set cache root
# File lib/shibkit/meta_meta/config.rb, line 400 def cache_root=(file_path) @cache_root = file_path end
# File lib/shibkit/meta_meta/config.rb, line 298 def can_delete=(bool) @can_delete = bool ? true : false end
# File lib/shibkit/meta_meta/config.rb, line 304 def can_delete? return @can_delete || false end
# File lib/shibkit/meta_meta/config.rb, line 64 def configure(&block) ## Execute block if passed one self.instance_eval(&block) if block end
Returns hash of options to set how remote files are cached and expired
# File lib/shibkit/meta_meta/config.rb, line 370 def download_cache_options @download_cache_options ||= Hash.new return download_cache_defaults.merge(@download_cache_options).freeze end
Options to set how remote files are cached and expired @param [Hash] Rack::Cache compatible hash of options @see rtomayko.github.com/rack-cache/ Rack::Cache for more information
# File lib/shibkit/meta_meta/config.rb, line 357 def download_cache_options=(options) @download_cache_options ||= Hash.new if download_cache_options @download_cache_options.merge!(options) else @download_cache_options = @options end end
# File lib/shibkit/meta_meta/config.rb, line 213 def downloads_logger return @downloads_logger || nil end
# File lib/shibkit/meta_meta/config.rb, line 206 def downloads_logger=(logger) return @downloads_logger = logger end
Forcibly set environment (not normally needed) @return [String]
# File lib/shibkit/meta_meta/config.rb, line 348 def environment return @environment || :development end
Forcibly set environment (not normally needed) @return [String]
# File lib/shibkit/meta_meta/config.rb, line 340 def environment=(environ) @environment = environ.to_sym end
Work out if we are in production or not by snooping on environment
# File lib/shibkit/meta_meta/config.rb, line 380 def in_production? ## Use attribute rather than method so we can distinguish between default and set values return true if @environment == :production return false if @environment == :development return false if @environment == :test if defined? Rails and Rails.respond_to? :env return Rails.env.production? end if defined? Rack and defined? RACK_ENV return true if RACK_ENV == 'production' end return false end
Returns current main logger
# File lib/shibkit/meta_meta/config.rb, line 199 def logger return @logger end
Set main logger
# File lib/shibkit/meta_meta/config.rb, line 192 def logger=(logger) @logger = logger end
Only use these federations/sources even if know about 100s - works on various functions (loading, processing and listing after it is set)
# File lib/shibkit/meta_meta/config.rb, line 251 def only_use(selection) @selected_federation_uris = [] case selection when String @selected_federation_uris << selection when Array @selected_federation_uris.concat(selection) when Hash @selected_federation_uris.concat(selection.keys) when :all, :everything, nil, false @selected_federation_uris = [] else raise "Expected federation/source selection to be single uri or array" end end
# File lib/shibkit/meta_meta/config.rb, line 434 def platform return [RUBY_VERSION, RUBY_PLATFORM, RUBY_RELEASE_DATE].join(':') end
Purge all XML data from object after creating object
# File lib/shibkit/meta_meta/config.rb, line 102 def purge_xml=(bool) @purge_xml = bool ? true : false end
Should all XML be purged from objects after creation?
# File lib/shibkit/meta_meta/config.rb, line 109 def purge_xml? return @purge_xml.nil? ? true : @purge_xml end
Store source XML alongside the parsed XML
# File lib/shibkit/meta_meta/config.rb, line 116 def remember_source_xml=(bool) @remember_source_xml = bool ? true : false end
Store source XML alongside the parsed XML
# File lib/shibkit/meta_meta/config.rb, line 123 def remember_source_xml? return @remember_source_xml.nil? ? false : @remember_source_xml end
List of federation/collection uris
# File lib/shibkit/meta_meta/config.rb, line 278 def selected_federation_uris return @selected_federation_uris || [] end
List of federation/collection uris
# File lib/shibkit/meta_meta/config.rb, line 271 def selected_federation_uris=(selection) only_use(selection) end
# File lib/shibkit/meta_meta/config.rb, line 243 def selected_groups return @selected_groups || [] end
# File lib/shibkit/meta_meta/config.rb, line 235 def selected_groups=(*list) @selected_groups = [list].flatten @selected_groups = [] if @selected_groups.include? :all end
# File lib/shibkit/meta_meta/config.rb, line 141 def smartcache_active=(bool) @smartcache_active = bool ? true : false end
# File lib/shibkit/meta_meta/config.rb, line 147 def smartcache_active? return @smartcache_active.nil? ? true : @smartcache_active end
# File lib/shibkit/meta_meta/config.rb, line 135 def smartcache_expiry return @smartcache_expiry || 60*60 end
# File lib/shibkit/meta_meta/config.rb, line 129 def smartcache_expiry=(seconds) @smartcache_expiry = seconds.to_i end
# File lib/shibkit/meta_meta/config.rb, line 159 def smartcache_info_file return File.join(cache_root, 'smartcache.yml') end
# File lib/shibkit/meta_meta/config.rb, line 153 def smartcache_object_file return File.join(cache_root, 'smartcache.marshal') end
# File lib/shibkit/meta_meta/config.rb, line 79 def sources_file @sources_file ||= :auto case @sources_file when :auto #file_path = self.in_production? ? REAL_SOURCES_FILE : DEV_SOURCES_FILE file_path = REAL_SOURCES_FILE when :dev, :development file_path = DEV_SOURCES_FILE when :test, :testing file_path = TEST_SOURCES_FILE when :real, :prod, :production, :all, :full file_path = REAL_SOURCES_FILE else file_path = @sources_file end return file_path end
# File lib/shibkit/meta_meta/config.rb, line 72 def sources_file=(file_path) @sources_file = file_path end
# File lib/shibkit/meta_meta/config.rb, line 165 def verbose_downloads=(bool) @verbose = bool ? true : false self.download_cache_options = { :verbose => @verbose } end
# File lib/shibkit/meta_meta/config.rb, line 172 def verbose_downloads? return @verbose.nil? ? false : @verbose end
# File lib/shibkit/meta_meta/config.rb, line 421 def version unless @version @version = File.open(VERSION_FILE, 'r') { |file| file.gets.strip } end return @version end
Private Instance Methods
# File lib/shibkit/meta_meta/config.rb, line 450 def download_cache_defaults return { :default_ttl => cache_fallback_ttl, :verbose => verbose_downloads?, :metastore => Addressable::URI.convert_path(File.join(cache_root, 'meta')).to_s, :entitystore => Addressable::URI.convert_path(File.join(cache_root, 'body')).to_s } end
Are we on a POSIX standard system or on MS-DOS/Windows, etc?
# File lib/shibkit/meta_meta/config.rb, line 443 def sensible_os? return ::Config::CONFIG['host_os'] =~ /mswin|mingw/ ? false : true end