class ManifestDestiny
Public Class Methods
configure(*args, &block)
click to toggle source
# File lib/manifest-destiny.rb, line 77 def self.configure(*args, &block) new(*args, &block) end
new(options = {}, &block)
click to toggle source
# File lib/manifest-destiny.rb, line 81 def initialize(options = {}, &block) @cache = options[:cache] @root = Pathname.new(options[:root] || Dir.pwd) if block_given? @config = Config.new(@root, &block) end end
Public Instance Methods
to_s()
click to toggle source
# File lib/manifest-destiny.rb, line 90 def to_s body = ["CACHE MANIFEST"] # Generate sha hash of cache and watch files hash = (@config.cache + @config.watch).map do |item| if (item =~ /:\/\//) Digest::SHA2.hexdigest(item) else begin path = File.new(File.join(@root, item)) Digest::SHA2.hexdigest(path.read) if ::File.file?(path) rescue $stderr.puts "Couldn't find file #{File.join(@root, item)}, not adding to cache hash" nil end end end body << "# #{Digest::SHA2.hexdigest(hash.compact.join)}" unless @config.cache.empty? body << "" << "CACHE:" body.concat @config.cache.uniq end unless @config.network.empty? body << "" << "NETWORK:" body.concat @config.network.uniq end unless @config.fallback.empty? body << "" << "FALLBACK:" @config.fallback.each do |namespace, url| body << "#{namespace} #{URI.escape(url.to_s)}" end end return body.join("\n") end