Class: Fewer::Engines::Abstract

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

Direct Known Subclasses

Css, Less

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, names) ⇒ Abstract

Returns a new instance of Abstract.



6
7
8
9
10
# File 'lib/fewer/engines/abstract.rb', line 6

def initialize(root, names)
  @root = root
  @names = names
  check_paths!
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



4
5
6
# File 'lib/fewer/engines/abstract.rb', line 4

def names
  @names
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/fewer/engines/abstract.rb', line 4

def root
  @root
end

Instance Method Details

#check_paths!Object



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

def check_paths!
  if (missing = paths.reject { |path| File.exist?(path) }).any?
    files = missing.map { |path| path.to_s }.join("\n")
    raise Fewer::MissingSourceFileError.new("Missing source file#{'s' if missing.size > 1}:\n#{files}")
  end
end

#content_typeObject



19
20
21
# File 'lib/fewer/engines/abstract.rb', line 19

def content_type
  'text/plain'
end

#extensionObject



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

def extension
end

#mtimeObject



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

def mtime
  paths.map { |path|
    File.mtime(path).to_i
  }.sort.last
end

#pathsObject



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

def paths
  names.map { |name|
    # TODO: Fix rather large security hole...
    File.join(root, "#{name}#{extension}")
  }
end

#readObject



39
40
41
42
43
# File 'lib/fewer/engines/abstract.rb', line 39

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