Class: Gumbo::AssetFile

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/gumbo/asset_file.rb

Direct Known Subclasses

PackageFile, TemplateFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ AssetFile

Returns a new instance of AssetFile.



25
26
27
28
29
# File 'lib/gumbo/asset_file.rb', line 25

def initialize(attrs={})
  attrs.each do |k,v|
    send("#{k}=", v)
  end
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



5
6
7
# File 'lib/gumbo/asset_file.rb', line 5

def context
  @context
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/gumbo/asset_file.rb', line 5

def name
  @name
end

#output_dirObject

Returns the value of attribute output_dir.



5
6
7
# File 'lib/gumbo/asset_file.rb', line 5

def output_dir
  @output_dir
end

#source_dirObject

Returns the value of attribute source_dir.



5
6
7
# File 'lib/gumbo/asset_file.rb', line 5

def source_dir
  @source_dir
end

Class Method Details

.class_for(name) ⇒ Object



21
22
23
# File 'lib/gumbo/asset_file.rb', line 21

def self.class_for(name)
  @@extension_class_map[File.extname(name)] || self
end

.ext(*args) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/gumbo/asset_file.rb', line 12

def self.ext(*args)
  @@extension_class_map ||= {}
  if args.size == 1
    @ext = args.first
    @@extension_class_map[@ext] = self
  end
  @ext
end

.for(attrs = {}) ⇒ Object



8
9
10
# File 'lib/gumbo/asset_file.rb', line 8

def self.for(attrs={})
  class_for(attrs[:name]).new(attrs)
end

Instance Method Details

#buildObject



39
40
41
42
43
# File 'lib/gumbo/asset_file.rb', line 39

def build
  logger.info "#{source_file} -> #{output_file}"
  mkdir_p File.dirname(output_file)
  cp source_file, output_file
end

#eql?(o) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/gumbo/asset_file.rb', line 56

def eql?(o)
  o.is_a?(self.class) &&
    o.name == name
end

#hashObject



62
63
64
# File 'lib/gumbo/asset_file.rb', line 62

def hash
  name.hash
end

#loggerObject



66
67
68
# File 'lib/gumbo/asset_file.rb', line 66

def logger
  Gumbo.logger
end

#output_fileObject



35
36
37
# File 'lib/gumbo/asset_file.rb', line 35

def output_file
  @output_file ||= File.join(output_dir, name)
end

#replace_ext(path, ext) ⇒ Object



45
46
47
48
49
50
# File 'lib/gumbo/asset_file.rb', line 45

def replace_ext(path, ext)
  parts = path.split('.')
  parts.pop
  parts << ext
  parts.join('.')
end

#should_be_rebuilt?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/gumbo/asset_file.rb', line 52

def should_be_rebuilt?
  !File.exists?(output_file) || File.mtime(source_file) > File.mtime(output_file)
end

#source_fileObject



31
32
33
# File 'lib/gumbo/asset_file.rb', line 31

def source_file
  @source_file ||= File.join(source_dir, name)
end