Class: Slideshow::Fetch
- Inherits:
-
Object
- Object
- Slideshow::Fetch
- Includes:
- LogUtils::Logging
- Defined in:
- lib/slideshow/commands/fetch.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #fetch(shortcut_or_source) ⇒ Object
- #fetch_all ⇒ Object
- #fetch_plugin(src) ⇒ Object
- #fetch_quick(src) ⇒ Object
- #fetch_template(src) ⇒ Object
-
#initialize(opts, config) ⇒ Fetch
constructor
A new instance of Fetch.
-
#update ⇒ Object
update shortcut index.
Constructor Details
#initialize(opts, config) ⇒ Fetch
Returns a new instance of Fetch.
11 12 13 14 |
# File 'lib/slideshow/commands/fetch.rb', line 11 def initialize( opts, config ) @opts = opts @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/slideshow/commands/fetch.rb', line 16 def config @config end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
16 17 18 |
# File 'lib/slideshow/commands/fetch.rb', line 16 def opts @opts end |
Instance Method Details
#fetch(shortcut_or_source) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/slideshow/commands/fetch.rb', line 44 def fetch( shortcut_or_source ) logger.debug "fetch >#{shortcut_or_source}<" ## check for builtin shortcut (assume no / or \) if shortcut_or_source.index( '/' ).nil? && shortcut_or_source.index( '\\' ).nil? shortcut = shortcut_or_source sources = config.map_fetch_shortcut( shortcut ) if sources.empty? puts "** Error: No mapping found for shortcut '#{shortcut}'." return end puts " Mapping fetch shortcut '#{shortcut}' to: #{sources.join(',')}" else sources = [shortcut_or_source] # pass arg through unmapped end sources.each do |source| ## if manifest includes .plugin assume it's a plugin if source.include?( '.txt.plugin' ) || source.include?( '.plugin.txt' ) fetch_plugin( source ) elsif source.include?( '.txt.quick' ) || source.include?( '.quick.txt' ) fetch_quick( source ) else # otherwise assume it's a template pack fetch_template( source ) end end end |
#fetch_all ⇒ Object
19 20 21 22 23 |
# File 'lib/slideshow/commands/fetch.rb', line 19 def fetch_all config.default_fetch_shortcuts.each do |shortcut| fetch( shortcut ) end end |
#fetch_plugin(src) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/slideshow/commands/fetch.rb', line 107 def fetch_plugin( src ) uri = URI.parse( src ) logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}" # downcase basename w/ extension (remove .txt) pakname = File.basename( uri.path ).downcase.gsub('.txt','').gsub('.plugin','') pakpath = File.( "#{config.config_dir}/plugins/#{pakname}" ) logger.debug "pakname >#{pakname}<" logger.debug "pakpath >#{pakpath}<" Pakman::Fetcher.new.fetch_pak( src, pakpath ) end |
#fetch_quick(src) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/slideshow/commands/fetch.rb', line 93 def fetch_quick( src ) uri = URI.parse( src ) logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}" # downcase basename w/ extension (remove .txt) pakname = File.basename( uri.path ).downcase.gsub('.txt','') pakpath = File.( "#{config.config_dir}/templates/#{pakname}" ) logger.debug "pakname >#{pakname}<" logger.debug "pakpath >#{pakpath}<" Pakman::Fetcher.new.fetch_pak( src, pakpath ) end |
#fetch_template(src) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/slideshow/commands/fetch.rb', line 78 def fetch_template( src ) # src = 'http://github.com/geraldb/slideshow/raw/d98e5b02b87ee66485431b1bee8fb6378297bfe4/code/templates/fullerscreen.txt' # src = 'http://github.com/geraldb/sandbox/raw/13d4fec0908fbfcc456b74dfe2f88621614b5244/s5blank/s5blank.txt' uri = URI.parse( src ) logger.debug "scheme: #{uri.scheme}, host: #{uri.host}, port: #{uri.port}, path: #{uri.path}" pakname = File.basename( uri.path ).downcase.gsub('.txt','') pakpath = File.( "#{config.config_dir}/templates/#{pakname}" ) logger.debug "packname >#{pakname}<" logger.debug "pakpath >#{pakpath}<" Pakman::Fetcher.new.fetch_pak( src, pakpath ) end |
#update ⇒ Object
update shortcut index
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/slideshow/commands/fetch.rb', line 26 def update # update shortcut index dest = config.shortcut_index_file destfull = File.( dest ) destpath = File.dirname( destfull ) FileUtils.makedirs( destpath ) unless File.directory?( destpath ) logger.debug "destfull=>#{destfull}<" logger.debug "destpath=>#{destpath}<" ## todo/fix: use a config setting for index url (do NOT hard core) src = 'https://raw.github.com/slideshow-s9/registry/master/slideshow.index.yml' puts "Updating shortcut index - downloading '#{src}'..." ::Fetcher::Worker.new.copy( src, destfull ) end |