Class: Fewer::Engines::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/fewer/engines/abstract.rb

Direct Known Subclasses

Css, Js, Less

Constant Summary collapse

SANITISE_REGEXP =
/\.?\.#{File::Separator}/

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, paths, options = {}) ⇒ Abstract

Returns a new instance of Abstract.



14
15
16
17
18
19
20
# File 'lib/fewer/engines/abstract.rb', line 14

def initialize(root, paths, options = {})
  @root = root.to_s
  @paths = paths
  @options = options
  sanitise_paths!
  check_paths!
end

Class Attribute Details

.content_typeObject

Returns the value of attribute content_type.



9
10
11
# File 'lib/fewer/engines/abstract.rb', line 9

def content_type
  @content_type
end

.extensionObject

Returns the value of attribute extension.



9
10
11
# File 'lib/fewer/engines/abstract.rb', line 9

def extension
  @extension
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/fewer/engines/abstract.rb', line 12

def options
  @options
end

#pathsObject (readonly)

Returns the value of attribute paths.



12
13
14
# File 'lib/fewer/engines/abstract.rb', line 12

def paths
  @paths
end

#rootObject (readonly)

Returns the value of attribute root.



12
13
14
# File 'lib/fewer/engines/abstract.rb', line 12

def root
  @root
end

Instance Method Details

#encodedObject



22
23
24
# File 'lib/fewer/engines/abstract.rb', line 22

def encoded
  Serializer.encode(root, paths)
end

#etagObject



32
33
34
35
# File 'lib/fewer/engines/abstract.rb', line 32

def etag
  # MD5 for concatenation of all files
  Digest::MD5.hexdigest(source)
end

#mtimeObject



26
27
28
29
30
# File 'lib/fewer/engines/abstract.rb', line 26

def mtime
  paths.map { |path|
    File.mtime(path)
  }.max || Time.now
end

#readObject



37
38
39
# File 'lib/fewer/engines/abstract.rb', line 37

def read
  source
end

#sourceObject



41
42
43
44
45
# File 'lib/fewer/engines/abstract.rb', line 41

def source
  @source ||= paths.map { |path|
    File.read(path)
  }.join("\n")
end