Class: Grabass::AssetManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/grabass.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ AssetManifest

Returns a new instance of AssetManifest.



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/grabass.rb', line 208

def initialize(filename)
  @filename = filename
  root = File.dirname File.absolute_path filename

  @assets = JSON.parse(File.read @filename).map do |item|
    if item.is_a? String
      Comment.new item
    else
      source, selections = item.to_a[0]

      selections = {'*' => selections} if selections.is_a? String
      selections = [selections] if selections.is_a? Hash

      selections.map! do |selection|
        selection.each do |glob, destination|
          selection[glob] = File.absolute_path destination, root
        end
      end

      Asset.new source, selections
    end
  end
end

Instance Method Details

#install(options = {}) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/grabass.rb', line 232

def install(options = {})
  puts "Installing assets from #{@filename}", '' unless options[:quiet]

  results = {:pass => 0, :fail => 0}

  @assets.each do |asset|
    match = true
    if asset.is_a? Comment
      match = options[:query].any? do |query|
        asset.content =~ query
      end

      asset.display options if match
    elsif asset.is_a? Asset
      match = options[:query].any? do |query|
        asset.source.location =~ query
      end

      if match
        puts asset.source.location
        asset_results = asset.install options
        results[:pass] += asset_results[:pass]
        results[:fail] += asset_results[:fail]
      end
    end
  end

  results
end