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

new(&block) click to toggle source
# 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

auto_refresh=(bool) click to toggle source

@return [String]

# File lib/shibkit/meta_meta/config.rb, line 285
def auto_refresh=(bool)

 @auto_refresh = bool ? true : false

end
auto_refresh?() click to toggle source

@return [String]

# File lib/shibkit/meta_meta/config.rb, line 292
def auto_refresh?

 return @auto_refresh.nil? ? true : @auto_refresh

end
auto_tag=(bool) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 311
def auto_tag=(bool)
  
   @auto_tag = bool ? true : false
  
end
auto_tag?() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 318
def auto_tag?
  
  return @auto_tag.nil? ? false : @auto_tag
  
end
autoload=(setting) click to toggle source

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
autoload?() click to toggle source

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
cache_fallback_ttl() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 185
def cache_fallback_ttl
  
  return @cache_fallback_ttl.nil? ? 7200 : @cache_fallback_ttl 

end
cache_fallback_ttl=(seconds) click to toggle source
# 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
cache_root() click to toggle source

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
cache_root=(file_path) click to toggle source

Set cache root

# File lib/shibkit/meta_meta/config.rb, line 400
def cache_root=(file_path)

  @cache_root = file_path
  
end
can_delete=(bool) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 298
def can_delete=(bool)
  
  @can_delete = bool ? true : false
  
end
can_delete?() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 304
def can_delete?
  
  return @can_delete || false
  
end
configure(&block) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 64
def configure(&block)
  
  ## Execute block if passed one
  self.instance_eval(&block) if block
  
end
download_cache_options() click to toggle source

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
download_cache_options=(options) click to toggle source

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
downloads_logger() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 213
def downloads_logger

  return @downloads_logger || nil

end
downloads_logger=(logger) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 206
def downloads_logger=(logger)

  return @downloads_logger = logger

end
environment() click to toggle source

Forcibly set environment (not normally needed) @return [String]

# File lib/shibkit/meta_meta/config.rb, line 348
def environment

  return @environment || :development

end
environment=(environ) click to toggle source

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
in_production?() click to toggle source

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
logger() click to toggle source

Returns current main logger

# File lib/shibkit/meta_meta/config.rb, line 199
def logger

  return @logger

end
logger=(logger) click to toggle source

Set main logger

# File lib/shibkit/meta_meta/config.rb, line 192
def logger=(logger)
  
  @logger = logger

end
merge_primary_tags=(bool) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 325
def merge_primary_tags=(bool)
  
   @merge_primary_tags = bool ? true : false
  
end
merge_primary_tags?() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 332
def merge_primary_tags?
  
  return @merge_primary_tags.nil? ? true : @merge_primary_tags
  
end
only_use(selection) click to toggle source

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
platform() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 434
def platform

 return [RUBY_VERSION, RUBY_PLATFORM, RUBY_RELEASE_DATE].join(':')
  
end
purge_xml=(bool) click to toggle source

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
purge_xml?() click to toggle source

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
remember_source_xml=(bool) click to toggle source

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
remember_source_xml?() click to toggle source

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
selected_federation_uris() click to toggle source

List of federation/collection uris

# File lib/shibkit/meta_meta/config.rb, line 278
def selected_federation_uris

  return @selected_federation_uris || []

end
selected_federation_uris=(selection) click to toggle source

List of federation/collection uris

# File lib/shibkit/meta_meta/config.rb, line 271
def selected_federation_uris=(selection)

  only_use(selection)

end
selected_groups() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 243
def selected_groups

  return @selected_groups || []

end
selected_groups=(*list) click to toggle source
# 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
smartcache_active=(bool) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 141
def smartcache_active=(bool)
  
   @smartcache_active = bool ? true : false
  
end
smartcache_active?() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 147
def smartcache_active?
  
   return @smartcache_active.nil? ? true : @smartcache_active
  
end
smartcache_expiry() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 135
def smartcache_expiry
  
 return @smartcache_expiry || 60*60

end
smartcache_expiry=(seconds) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 129
def smartcache_expiry=(seconds)
  
  @smartcache_expiry = seconds.to_i

end
smartcache_info_file() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 159
def smartcache_info_file 

  return File.join(cache_root, 'smartcache.yml')

end
smartcache_object_file() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 153
def smartcache_object_file 

  return File.join(cache_root, 'smartcache.marshal')

end
sources_file() click to toggle source
# 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
sources_file=(file_path) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 72
def sources_file=(file_path)

  @sources_file = file_path
  
end
verbose_downloads=(bool) click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 165
def verbose_downloads=(bool)

 @verbose = bool ? true : false
 self.download_cache_options = { :verbose => @verbose }

end
verbose_downloads?() click to toggle source
# File lib/shibkit/meta_meta/config.rb, line 172
def verbose_downloads?

 return @verbose.nil? ? false : @verbose 

end
version() click to toggle source
# 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

download_cache_defaults() click to toggle source
# 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
sensible_os?() click to toggle source

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