Class: Shibkit::MetaMeta::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/shibkit/meta_meta/config.rb

Constant Summary collapse

REAL_SOURCES_FILE =

Location of default real sources list (contains real-world federation details)

"#{::File.dirname(__FILE__)}/data/real_sources.yml"
DEV_SOURCES_FILE =

Location of default mock sources list (contains small fictional federations)

"#{::File.dirname(__FILE__)}/data/real_sources.yml"
TEST_SOURCES_FILE =

Location of default test sources list # TODO

"#{::File.dirname(__FILE__)}/data/real_sources.yml"
VERSION_FILE =

Slurp

"#{::File.dirname(__FILE__)}/../../../VERSION"

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Config

Returns a new instance of Config.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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

Instance Method Details

#auto_refresh=(bool) ⇒ String

Returns:

  • (String)


285
286
287
288
289
# File 'lib/shibkit/meta_meta/config.rb', line 285

def auto_refresh=(bool)

 @auto_refresh = bool ? true : false

end

#auto_refresh?String

Returns:

  • (String)


292
293
294
295
296
# File 'lib/shibkit/meta_meta/config.rb', line 292

def auto_refresh?

 return @auto_refresh.nil? ? true : @auto_refresh

end

#auto_tag=(bool) ⇒ Object



311
312
313
314
315
# File 'lib/shibkit/meta_meta/config.rb', line 311

def auto_tag=(bool)
  
   @auto_tag = bool ? true : false
  
end

#auto_tag?Boolean

Returns:

  • (Boolean)


318
319
320
321
322
# File 'lib/shibkit/meta_meta/config.rb', line 318

def auto_tag?
  
  return @auto_tag.nil? ? false : @auto_tag
  
end

#autoload=(setting) ⇒ Object

Load a metadata sources file automatically (true or false)



220
221
222
223
224
# File 'lib/shibkit/meta_meta/config.rb', line 220

def autoload=(setting)

  @autoload = setting ? true : false

end

#autoload?Boolean

Should metadata sources and objects be loaded automatically? Normally, yes.

Returns:

  • (Boolean)


227
228
229
230
231
232
# File 'lib/shibkit/meta_meta/config.rb', line 227

def autoload?

  return true unless defined? @autoload
  return @autoload 

end

#cache_fallback_ttlObject



185
186
187
188
189
# 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) ⇒ Object



178
179
180
181
182
183
# 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_rootObject

return or calculate the filesystem path to store the web cache



407
408
409
410
411
412
413
414
415
416
417
418
# 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) ⇒ Object

Set cache root



400
401
402
403
404
# File 'lib/shibkit/meta_meta/config.rb', line 400

def cache_root=(file_path)

  @cache_root = file_path
  
end

#can_delete=(bool) ⇒ Object



298
299
300
301
302
# File 'lib/shibkit/meta_meta/config.rb', line 298

def can_delete=(bool)
  
  @can_delete = bool ? true : false
  
end

#can_delete?Boolean

Returns:

  • (Boolean)


304
305
306
307
308
# File 'lib/shibkit/meta_meta/config.rb', line 304

def can_delete?
  
  return @can_delete || false
  
end

#configure(&block) ⇒ Object



64
65
66
67
68
69
# 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_optionsObject

Returns hash of options to set how remote files are cached and expired



370
371
372
373
374
375
376
# 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) ⇒ Object

Options to set how remote files are cached and expired

Parameters:

  • Rack::Cache (Hash)

    compatible hash of options

See Also:



357
358
359
360
361
362
363
364
365
366
367
# 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_loggerObject



213
214
215
216
217
# File 'lib/shibkit/meta_meta/config.rb', line 213

def downloads_logger

  return @downloads_logger || nil

end

#downloads_logger=(logger) ⇒ Object



206
207
208
209
210
# File 'lib/shibkit/meta_meta/config.rb', line 206

def downloads_logger=(logger)

  return @downloads_logger = logger

end

#environmentString

Forcibly set environment (not normally needed)

Returns:

  • (String)


348
349
350
351
352
# File 'lib/shibkit/meta_meta/config.rb', line 348

def environment

  return @environment || :development

end

#environment=(environ) ⇒ String

Forcibly set environment (not normally needed)

Returns:

  • (String)


340
341
342
343
344
# File 'lib/shibkit/meta_meta/config.rb', line 340

def environment=(environ)

  @environment = environ.to_sym

end

#in_production?Boolean

Work out if we are in production or not by snooping on environment

Returns:

  • (Boolean)


380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# 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

#loggerObject

Returns current main logger



199
200
201
202
203
# File 'lib/shibkit/meta_meta/config.rb', line 199

def logger

  return @logger

end

#logger=(logger) ⇒ Object

Set main logger



192
193
194
195
196
# File 'lib/shibkit/meta_meta/config.rb', line 192

def logger=(logger)
  
  @logger = logger

end

#merge_primary_tags=(bool) ⇒ Object



325
326
327
328
329
# File 'lib/shibkit/meta_meta/config.rb', line 325

def merge_primary_tags=(bool)
  
   @merge_primary_tags = bool ? true : false
  
end

#merge_primary_tags?Boolean

Returns:

  • (Boolean)


332
333
334
335
336
# 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) ⇒ Object

Only use these federations/sources even if know about 100s - works on various functions (loading, processing and listing after it is set)



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# 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

#platformObject



434
435
436
437
438
# File 'lib/shibkit/meta_meta/config.rb', line 434

def platform

 return [RUBY_VERSION, RUBY_PLATFORM, RUBY_RELEASE_DATE].join(':')
  
end

#purge_xml=(bool) ⇒ Object

Purge all XML data from object after creating object



102
103
104
105
106
# File 'lib/shibkit/meta_meta/config.rb', line 102

def purge_xml=(bool)
  
   @purge_xml = bool ? true : false
  
end

#purge_xml?Boolean

Should all XML be purged from objects after creation?

Returns:

  • (Boolean)


109
110
111
112
113
# File 'lib/shibkit/meta_meta/config.rb', line 109

def purge_xml?
  
  return @purge_xml.nil? ? true : @purge_xml
  
end

#remember_source_xml=(bool) ⇒ Object

Store source XML alongside the parsed XML



116
117
118
119
120
# File 'lib/shibkit/meta_meta/config.rb', line 116

def remember_source_xml=(bool)
  
   @remember_source_xml = bool ? true : false
  
end

#remember_source_xml?Boolean

Store source XML alongside the parsed XML

Returns:

  • (Boolean)


123
124
125
126
127
# 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_urisObject

List of federation/collection uris



278
279
280
281
282
# File 'lib/shibkit/meta_meta/config.rb', line 278

def selected_federation_uris

  return @selected_federation_uris || []

end

#selected_federation_uris=(selection) ⇒ Object

List of federation/collection uris



271
272
273
274
275
# File 'lib/shibkit/meta_meta/config.rb', line 271

def selected_federation_uris=(selection)

  only_use(selection)

end

#selected_groupsObject



243
244
245
246
247
# File 'lib/shibkit/meta_meta/config.rb', line 243

def selected_groups

  return @selected_groups || []

end

#selected_groups=(*list) ⇒ Object



235
236
237
238
239
240
# 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) ⇒ Object



141
142
143
144
145
# File 'lib/shibkit/meta_meta/config.rb', line 141

def smartcache_active=(bool)
  
   @smartcache_active = bool ? true : false
  
end

#smartcache_active?Boolean

Returns:

  • (Boolean)


147
148
149
150
151
# File 'lib/shibkit/meta_meta/config.rb', line 147

def smartcache_active?
  
   return @smartcache_active.nil? ? true : @smartcache_active
  
end

#smartcache_expiryObject



135
136
137
138
139
# File 'lib/shibkit/meta_meta/config.rb', line 135

def smartcache_expiry
  
 return @smartcache_expiry || 60*60

end

#smartcache_expiry=(seconds) ⇒ Object



129
130
131
132
133
# File 'lib/shibkit/meta_meta/config.rb', line 129

def smartcache_expiry=(seconds)
  
  @smartcache_expiry = seconds.to_i

end

#smartcache_info_fileObject



159
160
161
162
163
# File 'lib/shibkit/meta_meta/config.rb', line 159

def smartcache_info_file 

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

end

#smartcache_object_fileObject



153
154
155
156
157
# File 'lib/shibkit/meta_meta/config.rb', line 153

def smartcache_object_file 

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

end

#sources_fileObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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) ⇒ Object



72
73
74
75
76
# File 'lib/shibkit/meta_meta/config.rb', line 72

def sources_file=(file_path)

  @sources_file = file_path
  
end

#verbose_downloads=(bool) ⇒ Object



165
166
167
168
169
170
# 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?Boolean

Returns:

  • (Boolean)


172
173
174
175
176
# File 'lib/shibkit/meta_meta/config.rb', line 172

def verbose_downloads?

 return @verbose.nil? ? false : @verbose 

end

#versionObject



421
422
423
424
425
426
427
428
429
430
431
# 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