Class: Dassets::SourceFile
- Inherits:
-
Object
- Object
- Dassets::SourceFile
- Defined in:
- lib/dassets/source_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_source_file) ⇒ Object
- #asset_file ⇒ Object
- #compiled ⇒ Object
- #digest_path ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(file_path) ⇒ SourceFile
constructor
A new instance of SourceFile.
- #mtime ⇒ Object
- #response_headers ⇒ Object
-
#source ⇒ Object
get the last matching one (in the case two sources with the same path are configured) since we select the last matching source file (from the last configured source) in ‘find_by_digest_path` above.
Constructor Details
#initialize(file_path) ⇒ SourceFile
Returns a new instance of SourceFile.
16 17 18 19 |
# File 'lib/dassets/source_file.rb', line 16 def initialize(file_path) @file_path = file_path.to_s @ext_list = File.basename(@file_path).split('.').reverse end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
14 15 16 |
# File 'lib/dassets/source_file.rb', line 14 def file_path @file_path end |
Class Method Details
.find_by_digest_path(path, options = nil) ⇒ Object
10 11 12 |
# File 'lib/dassets/source_file.rb', line 10 def self.find_by_digest_path(path, = nil) Dassets.source_files[path] || NullSourceFile.new(path, ) end |
Instance Method Details
#==(other_source_file) ⇒ Object
62 63 64 |
# File 'lib/dassets/source_file.rb', line 62 def ==(other_source_file) self.file_path == other_source_file.file_path end |
#asset_file ⇒ Object
30 31 32 |
# File 'lib/dassets/source_file.rb', line 30 def asset_file @asset_file ||= Dassets::AssetFile.new(self.digest_path) end |
#compiled ⇒ Object
44 45 46 47 48 |
# File 'lib/dassets/source_file.rb', line 44 def compiled @ext_list.inject(read_file(@file_path)) do |content, ext| self.source.engines[ext].compile(content) end end |
#digest_path ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/dassets/source_file.rb', line 34 def digest_path @digest_path ||= begin digest_basename = @ext_list.inject([]) do |digest_ext_list, ext| digest_ext_list << self.source.engines[ext].ext(ext) end.reject(&:empty?).reverse.join('.') File.join([digest_dirname(@file_path), digest_basename].reject(&:empty?)) end end |
#exists? ⇒ Boolean
50 51 52 |
# File 'lib/dassets/source_file.rb', line 50 def exists? File.file?(@file_path) end |
#mtime ⇒ Object
54 55 56 |
# File 'lib/dassets/source_file.rb', line 54 def mtime File.mtime(@file_path) end |
#response_headers ⇒ Object
58 59 60 |
# File 'lib/dassets/source_file.rb', line 58 def response_headers self.source.nil? ? Hash.new : self.source.response_headers end |
#source ⇒ Object
get the last matching one (in the case two sources with the same path are configured) since we select the last matching source file (from the last configured source) in ‘find_by_digest_path` above.
24 25 26 27 28 |
# File 'lib/dassets/source_file.rb', line 24 def source @source ||= Dassets.config.sources.select do |source| @file_path =~ /^#{slash_path(source.path)}/ end.last end |