Class: Hulk::Bundle

Inherits:
Object
  • Object
show all
Defined in:
lib/hulk/bundle.rb

Direct Known Subclasses

CssBundle, JsBundle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Bundle

Returns a new instance of Bundle.



8
9
10
11
12
# File 'lib/hulk/bundle.rb', line 8

def initialize(name)
  @name = name.to_s
  @raw = []
  @compiled = nil
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/hulk/bundle.rb', line 6

def name
  @name
end

Instance Method Details

#<<(val) ⇒ Object



14
15
16
17
# File 'lib/hulk/bundle.rb', line 14

def <<(val)
  (@raw << val) and return unless compiled?
  raise Hulk::FrozenBundleError.new("This bundle has already been compiled.")
end

#compile!Object



28
29
30
# File 'lib/hulk/bundle.rb', line 28

def compile!
  @compiled ||= generate_compiled(@raw.join)
end

#compiled?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/hulk/bundle.rb', line 19

def compiled?
  !@compiled.nil?
end

#digestObject



23
24
25
26
# File 'lib/hulk/bundle.rb', line 23

def digest
  return nil unless compiled?
  @digest ||= Digest::MD5.hexdigest(compile!)
end

#filenameObject



32
33
34
# File 'lib/hulk/bundle.rb', line 32

def filename
  "#{digest}-#{name}.#{ext}"
end