Class: Juicer::Asset::PathResolver
- Inherits:
-
Object
- Object
- Juicer::Asset::PathResolver
- Defined in:
- lib/juicer/asset/path_resolver.rb
Overview
Factory class that creates Juicer::Asset::Path
objects from a common set of options. Also facilitates asset host cycling on a set of asset paths.
path_resolver = Juicer::Asset::PathResolver.new(
:document_root => "/var/www",
:hosts => ["assets1.mysite.com", "assets2.mysite.com"]
)
asset = path_resolver.resolve("../images/logo.png")
asset.document_root
#=> "/var/www"
asset.absolute_path(path_resolver.cycle_hosts)
#=> "http://assets1.mysite.com/images/logo.png"
asset = path_resolver.resolve("/favicon.ico")
asset.absolute_path(path_resolver.cycle_hosts)
#=> "http://assets2.mysite.com/favicon.ico"
- Author
-
Christian Johansen ([email protected])
- Copyright
-
Copyright © 2009 Christian Johansen
- License
-
BSD
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#document_root ⇒ Object
readonly
Returns the value of attribute document_root.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
Instance Method Summary collapse
-
#cycle_hosts ⇒ Object
(also: #host)
Cycle asset hosts.
-
#initialize(options = {}) ⇒ PathResolver
constructor
Initialize resolver.
-
#resolve(path) ⇒ Object
Returns a
Juicer::Asset::Path
object for the given path, and the options set on the resolver.
Constructor Details
#initialize(options = {}) ⇒ PathResolver
Initialize resolver. All options set on the resolver will be carried on to the resolved assets.
38 39 40 41 42 43 44 45 |
# File 'lib/juicer/asset/path_resolver.rb', line 38 def initialize( = {}) [:base] ||= Dir.pwd @options = @base = [:base] @hosts = Juicer::Asset::Path.hosts_with_scheme([:hosts]) || [] @current_host = 0 @document_root = @options[:document_root] end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
32 33 34 |
# File 'lib/juicer/asset/path_resolver.rb', line 32 def base @base end |
#document_root ⇒ Object (readonly)
Returns the value of attribute document_root.
32 33 34 |
# File 'lib/juicer/asset/path_resolver.rb', line 32 def document_root @document_root end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
32 33 34 |
# File 'lib/juicer/asset/path_resolver.rb', line 32 def hosts @hosts end |
Instance Method Details
#cycle_hosts ⇒ Object Also known as: host
Cycle asset hosts. Returns an asset host
67 68 69 70 71 72 73 74 |
# File 'lib/juicer/asset/path_resolver.rb', line 67 def cycle_hosts return nil if @hosts.length == 0 host = @hosts[@current_host % @hosts.length] @current_host += 1 host end |