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}|\.\.#{File::Separator}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Abstract.



8
9
10
11
12
13
14
# File 'lib/fewer/engines/abstract.rb', line 8

def initialize(root, names, options = {})
  @root = root
  @names = names.is_a?(Array) ? names : [names]
  @options = options
  sanitise_names!
  check_paths!
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



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

def names
  @names
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#rootObject (readonly)

Returns the value of attribute root.



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

def root
  @root
end

Instance Method Details

#content_typeObject



16
17
18
# File 'lib/fewer/engines/abstract.rb', line 16

def content_type
  'text/plain'
end

#encodedObject



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

def encoded
  Serializer.encode(names)
end

#extensionObject



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

def extension
end

#mtimeObject



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

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

#pathsObject



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

def paths
  @paths ||= names.map { |name|
    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