Class: Embarista::ManifestBuilder
- Inherits:
-
Object
- Object
- Embarista::ManifestBuilder
- Includes:
- FileUtils
- Defined in:
- lib/embarista/manifest_builder.rb
Instance Attribute Summary collapse
-
#document_root ⇒ Object
readonly
Returns the value of attribute document_root.
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#tmp ⇒ Object
readonly
Returns the value of attribute tmp.
-
#tmp_document_root ⇒ Object
readonly
Returns the value of attribute tmp_document_root.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#add(path, path_from_document_root = nil) ⇒ Object
Pass in the file to be versioned and staged in the tmp document root.
-
#initialize(opts = {}) ⇒ ManifestBuilder
constructor
A new instance of ManifestBuilder.
Constructor Details
#initialize(opts = {}) ⇒ ManifestBuilder
Returns a new instance of ManifestBuilder.
10 11 12 13 14 15 16 17 |
# File 'lib/embarista/manifest_builder.rb', line 10 def initialize(opts={}) @root = Pathname.new(opts[:root] || Dir.getwd). @document_root = Pathname.new(opts[:document_root] || 'public').(@root) @tmp = Pathname.new(opts[:tmp] || 'tmp').(@root) @tmp_document_root = @tmp + @document_root.relative_path_from(@root) @manifest = opts[:manifest] || {} @version = opts[:version] end |
Instance Attribute Details
#document_root ⇒ Object (readonly)
Returns the value of attribute document_root.
8 9 10 |
# File 'lib/embarista/manifest_builder.rb', line 8 def document_root @document_root end |
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
8 9 10 |
# File 'lib/embarista/manifest_builder.rb', line 8 def manifest @manifest end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/embarista/manifest_builder.rb', line 8 def root @root end |
#tmp ⇒ Object (readonly)
Returns the value of attribute tmp.
8 9 10 |
# File 'lib/embarista/manifest_builder.rb', line 8 def tmp @tmp end |
#tmp_document_root ⇒ Object (readonly)
Returns the value of attribute tmp_document_root.
8 9 10 |
# File 'lib/embarista/manifest_builder.rb', line 8 def tmp_document_root @tmp_document_root end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
8 9 10 |
# File 'lib/embarista/manifest_builder.rb', line 8 def version @version end |
Instance Method Details
#add(path, path_from_document_root = nil) ⇒ Object
Pass in the file to be versioned and staged in the tmp document root.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/embarista/manifest_builder.rb', line 20 def add(path, path_from_document_root=nil) full_path = Pathname.new(path).(root) path_from_document_root = Pathname.new(path_from_document_root || full_path.relative_path_from(document_root)) relative_dir = path_from_document_root.dirname md5 = Digest::MD5.file(full_path).hexdigest ext = full_path.extname name_without_ext = full_path.basename.to_s.chomp(ext) suffix = "-#{md5}" suffix = "-#{version}#{suffix}" if version versioned_file = "#{name_without_ext}#{suffix}#{ext}" versioned_path_from_document_root = relative_dir + versioned_file versioned_full_path = tmp_document_root + versioned_path_from_document_root mkdir_p versioned_full_path.dirname cp full_path, versioned_full_path http_path = '/' + path_from_document_root.to_s versioned_http_path = '/' + versioned_path_from_document_root.to_s manifest[http_path] = versioned_http_path end |