Class: Rack::Bundle::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bundle/bundles/base.rb

Direct Known Subclasses

CSSBundle, JSBundle

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*files) ⇒ Base

Returns a new instance of Base.



13
14
15
# File 'lib/rack/bundle/bundles/base.rb', line 13

def initialize *files
  @files = files
end

Class Attribute Details

.extensionObject

Returns the value of attribute extension.



4
5
6
# File 'lib/rack/bundle/bundles/base.rb', line 4

def extension
  @extension
end

.joinerObject

Returns the value of attribute joiner.



4
5
6
# File 'lib/rack/bundle/bundles/base.rb', line 4

def joiner
  @joiner
end

.mime_typeObject

Returns the value of attribute mime_type.



4
5
6
# File 'lib/rack/bundle/bundles/base.rb', line 4

def mime_type
  @mime_type
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



5
6
7
# File 'lib/rack/bundle/bundles/base.rb', line 5

def contents
  @contents
end

#filesObject

Returns the value of attribute files.



5
6
7
# File 'lib/rack/bundle/bundles/base.rb', line 5

def files
  @files
end

Class Method Details

.new_from_contents(contents) ⇒ Object



7
8
9
10
11
# File 'lib/rack/bundle/bundles/base.rb', line 7

def self.new_from_contents contents
  instance = new
  instance.contents = contents
  instance
end

Instance Method Details

#==(bundle) ⇒ Object



41
42
43
# File 'lib/rack/bundle/bundles/base.rb', line 41

def == bundle
  self.class == bundle.class && hash == bundle.hash
end

#extensionObject



29
30
31
# File 'lib/rack/bundle/bundles/base.rb', line 29

def extension
  self.class.extension
end

#hashObject



21
22
23
# File 'lib/rack/bundle/bundles/base.rb', line 21

def hash
  @hash ||= MD5.new(@files.map { |file| File.basename(file.path) + File.mtime(file.path).to_s }.join).to_s
end

#joinerObject



33
34
35
# File 'lib/rack/bundle/bundles/base.rb', line 33

def joiner
  self.class.joiner
end

#mime_typeObject



37
38
39
# File 'lib/rack/bundle/bundles/base.rb', line 37

def mime_type
  self.class.mime_type
end

#pathObject



25
26
27
# File 'lib/rack/bundle/bundles/base.rb', line 25

def path
  "/rack-bundle-#{hash}.#{extension}"
end