Class: Assetify::Pkg
Constant Summary collapse
- PATH =
"/tmp/"
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) ⇒ Pkg
constructor
A new instance of Pkg.
- #path ⇒ Object
- #read_from_pkg(regex = ".*") ⇒ Object
- #unpack_to_vendor ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(name, url) ⇒ Pkg
Returns a new instance of Pkg.
11 12 13 14 15 |
# File 'lib/assetify/pkg.rb', line 11 def initialize(name, url) @name = name @pkgname = url.split("/").last @url = url end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/assetify/pkg.rb', line 7 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/assetify/pkg.rb', line 7 def url @url end |
Instance Method Details
#fullpath ⇒ Object
21 22 23 |
# File 'lib/assetify/pkg.rb', line 21 def fullpath File.join(path, @pkgname) end |
#get(file, force = false) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/assetify/pkg.rb', line 38 def get(file, force = false) # Download and write to tmp if force or doensnt exists write(get_data(url)) if force || !File.exists?(File.join(fullpath)) # Better way when multiple are found....? read_from_pkg(file) end |
#path ⇒ Object
17 18 19 |
# File 'lib/assetify/pkg.rb', line 17 def path File.join(PATH, name) end |
#read_from_pkg(regex = ".*") ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/assetify/pkg.rb', line 25 def read_from_pkg(regex = ".*") data = {} Archive.read_open_filename(fullpath) do |ar| while entry = ar.next_header if entry.pathname =~ /#{regex}/ data.merge! entry.pathname => ar.read_data # return data end end end data end |
#unpack_to_vendor ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/assetify/pkg.rb', line 45 def unpack_to_vendor read_from_pkg.each do |file, data| fname, *dir = file =~ /\/$/ ? [nil, file] : file.split("/").reverse dir = File.join Opt[:vendor], dir.reverse.join("/") FileUtils.mkdir_p dir unless Dir.exists?(dir) next if file =~ /\/$/ # next if data.empty? File.open(Opt[:vendor] + "/#{file}", "w+") { |f| f.puts(data) } end end |