Class: CdnFu::Lister

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

Instance Method Summary collapse

Constructor Details

#initializeLister

Returns a new instance of Lister.



3
4
5
6
# File 'lib/cdn_fu/lister.rb', line 3

def initialize
  @globs = []
  @files = []
end

Instance Method Details

#file(name, options = {}) ⇒ Object



12
13
14
15
# File 'lib/cdn_fu/lister.rb', line 12

def file(name,options = {})
  options[:name] = name
  @files << options
end

#glob(name, options = {}) ⇒ Object



7
8
9
10
# File 'lib/cdn_fu/lister.rb', line 7

def glob(name,options = {})
  options[:name] = name
  @globs << options
end

#listObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cdn_fu/lister.rb', line 17

def list
  file_infos ||= []
  asset_root = Config.config.asset_root_dir
  asset_root ||= Dir.pwd

  @globs.each do |glob|
    glob_str = glob[:name]
    Dir.glob(File.join(asset_root,glob_str)).each do |file|
      fi = FileInfo.new
      fi.local_path = File.expand_path(file)
      fi.gzip = glob[:gzip]
      fi.minify = glob[:minify]
      root_sub_path = fi.local_path.gsub(asset_root,'')
      glob_sub_path = root_sub_path.gsub(glob_str[0,glob_str.index('*')],'')
      fi.remote_path = glob[:path] ? File.join(glob[:path],glob_sub_path) : root_sub_path
      file_infos << fi
    end
  end

  @files.each do |file|
    fi = FileInfo.new
    fi.local_path = File.join(asset_root,file[:name])
    fi.gzip = file[:gzip]
    fi.minify = file[:minify]
    fi.remote_path = file[:path] ? file[:path] : fi.local_path.gsub(Config.config.asset_root_dir,'')
    file_infos << fi
  end
  file_infos
end