Class: VeeweeTemplatesUpdater
- Inherits:
-
Object
- Object
- VeeweeTemplatesUpdater
- Defined in:
- lib/veewee-templates-updater.rb
Instance Method Summary collapse
- #handle_entry(entry) ⇒ Object
- #parse_archive(res) ⇒ Object
- #run(args) ⇒ Object
- #user ⇒ Object
- #veewee_spec ⇒ Object
- #veewee_tarball_url ⇒ Object
- #veewee_target(source) ⇒ Object
Instance Method Details
#handle_entry(entry) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/veewee-templates-updater.rb', line 31 def handle_entry(entry) if entry.file? File.open(veewee_target(entry.name),"w") do |target| while body = entry.read target.write(body) end end else FileUtils.mkdir_p veewee_target(entry.name) end end |
#parse_archive(res) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/veewee-templates-updater.rb', line 43 def parse_archive res printf "Extracting: " Zlib::GzipReader.open(res.path) do |tgz| last_entry_name = "" Archive::Tar::Minitar::Reader.open(tgz).each do |entry| # handle only templates next unless entry.name =~ /^[^\/]*\/templates\/([^\/]*)\/.*$/ # print name of template only for first path found printf "#{$1} " if last_entry_name != $1 last_entry_name = $1 # mkdir / unpack handle_entry entry end end printf "\n" end |
#run(args) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/veewee-templates-updater.rb', line 60 def run args veewee_spec || raise("Could not find veewee gem, install it first.") @user = args[0] if args.length > 0 puts "Veewee: #{veewee_spec.full_gem_path}" puts "Downloading: #{veewee_tarball_url}" open(veewee_tarball_url) do |res| parse_archive res end end |
#user ⇒ Object
23 24 25 |
# File 'lib/veewee-templates-updater.rb', line 23 def user @user ||= "jedi4ever" end |
#veewee_spec ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/veewee-templates-updater.rb', line 7 def veewee_spec @veewee_spec ||= if Gem::Specification.respond_to?(:find_by_name) Gem::Specification.find_by_name("veewee") else Gem.source_index.find_name("veewee").last end end |
#veewee_tarball_url ⇒ Object
27 28 29 |
# File 'lib/veewee-templates-updater.rb', line 27 def veewee_tarball_url "https://github.com/#{user}/veewee/tarball/master" end |
#veewee_target(source) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/veewee-templates-updater.rb', line 16 def veewee_target(source) # Remove the github project dir name it contains sha source.gsub!(/^[^\/]*\//,"") # Build path to local file/dir File.join(veewee_spec.full_gem_path,source) end |