Class: AssetManager::Manager

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

Instance Method Summary collapse

Instance Method Details

#asset(source, target) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/asset_manager/manager.rb', line 18

def asset(source, target)
  location = "#{@repo}/#{source}"
  target_location = get_location(source, target)
  FileUtils.cp(location, target_location)
rescue Exception => e
  File.open("./.assets/run.log", "a") do |file|
    file.puts e
  end
  puts "An error occurred running asset #{location}, logged to .assets/run.log."
end

#get_location(source, target) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/asset_manager/manager.rb', line 29

def get_location(source, target)
  filename = source.split("/").last
  if target.is_a? Symbol
    "#{location_by_type(target)}/#{filename}"
  else
    target
  end
end

#location_by_type(type) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/asset_manager/manager.rb', line 38

def location_by_type(type)
  case type
    when :stylesheet then "app/assets/stylesheets"
    when :javascript then "app/assets/javascript"
    when :image      then "app/assets/images"
  end
end

#source(location, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/asset_manager/manager.rb', line 7

def source(location, &block)
  AssetManager::FETCHERS.each do |f|
    if AssetManager::Fetch.send("is_#{f.to_s}?", location)
      @repo = AssetManager::Fetch.send(f, location)
      break
    end
  end

  instance_eval(&block)
end