Class: Rack::Tipi::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/tipi/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, path, route) ⇒ Asset

Returns a new instance of Asset.



8
9
10
11
12
# File 'lib/rack/tipi/asset.rb', line 8

def initialize(namespace, path, route)
  @namespace = namespace
  @path = Pathname.new(path).expand_path
  @route = route.sub(/\//, '')
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



6
7
8
# File 'lib/rack/tipi/asset.rb', line 6

def namespace
  @namespace
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/rack/tipi/asset.rb', line 6

def path
  @path
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
# File 'lib/rack/tipi/asset.rb', line 14

def ==(other)
  route == other.route if other.respond_to? :route
end

#contentObject



18
19
20
# File 'lib/rack/tipi/asset.rb', line 18

def content
  path.read
end

#mime_typeObject



22
23
24
# File 'lib/rack/tipi/asset.rb', line 22

def mime_type
  Rack::Mime.mime_type(path.extname)
end

#routeObject



26
27
28
# File 'lib/rack/tipi/asset.rb', line 26

def route
  "/#{namespace}/#{@route}"
end