Class: Assetify::Pkg
- Inherits:
-
Object
- Object
- Assetify::Pkg
- Includes:
- Helpers
- Defined in:
- lib/assetify/asset/pkg.rb
Overview
Some Assets are inside rocks, need tools…
Constant Summary collapse
- PATH =
'/tmp/'.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #fullpath ⇒ Object
- #get(file, force = false) ⇒ Object
-
#initialize(name, url, _opts = {}) ⇒ Pkg
constructor
A new instance of Pkg.
- #path ⇒ Object
- #read_from_pkg(regex = '.*') ⇒ Object
-
#unpack_all ⇒ Object
Used when pkgs doesn’t provide a block, just dump it somewhere.
Methods included from Helpers
Constructor Details
#initialize(name, url, _opts = {}) ⇒ Pkg
Returns a new instance of Pkg.
13 14 15 16 17 |
# File 'lib/assetify/asset/pkg.rb', line 13 def initialize(name, url, _opts = {}) @name = name @pkgname = url.split('/').last @url = url end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/assetify/asset/pkg.rb', line 9 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/assetify/asset/pkg.rb', line 9 def url @url end |
Instance Method Details
#fullpath ⇒ Object
23 24 25 |
# File 'lib/assetify/asset/pkg.rb', line 23 def fullpath File.join(path, @pkgname) end |
#get(file, force = false) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/assetify/asset/pkg.rb', line 40 def get(file, force = false) # Download and write to tmp if force or doensnt exists write(get_data(url)) if force || !File.exist?(fullpath) # Better way when multiple are found....? read_from_pkg(file) end |
#path ⇒ Object
19 20 21 |
# File 'lib/assetify/asset/pkg.rb', line 19 def path File.join(PATH, name.to_s) end |
#read_from_pkg(regex = '.*') ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/assetify/asset/pkg.rb', line 27 def read_from_pkg(regex = '.*') data = {} Archive.read_open_filename(fullpath) do |ar| while (entry = ar.next_header) if entry.pathname =~ /#{regex}/ data[entry.pathname] = ar.read_data # return data end end end data end |
#unpack_all ⇒ Object
Used when pkgs doesn’t provide a block, just dump it somewhere.
50 51 52 53 54 55 56 57 58 |
# File 'lib/assetify/asset/pkg.rb', line 50 def unpack_all read_from_pkg.each do |file, data| _fname, *dir = file =~ %r{/$} ? [nil, file] : file.split('/').reverse dir = File.join Opt[:vendor], dir.reverse.join('/') FileUtils.mkdir_p dir unless Dir.exist?(dir) next if file =~ %r{/$} # next if data.empty? File.open(Opt[:vendor] + "/#{file}", 'w+') { |f| f.puts(data) } end end |