class BrickAndMortar::Brick::Location
Constants
- FORMATS
Attributes
format[R]
method[R]
path[R]
url[R]
Public Class Methods
new(data)
click to toggle source
# File lib/brick_and_mortar/brick.rb, line 35 def initialize(data) @format = FORMATS[:plain] if data.respond_to?(:keys) if data['path'] && !data['path'].empty? && data['url'] && data['url'].empty? fail "Path was specified as \"#{data['path']}\", but url was specified as \"#{data['url']}\". Only one can be defined at a time." end @path = if data['path'] @method = 'copy' @format = self.class().url_to_format(data['path']) data['path'] elsif data['url'] @format = self.class().url_to_format(data['url']) data['url'] else @path end @method = data['method'] if data['method'] @format = data['format'] if data['format'] else if data.match(/^\s*svn:/) @method = 'svn' elsif data.match(/^\s*git:/) || data.match(/\.git\s*$/) @method = 'git' elsif data.match(/^\s*https?:/) @method = 'download' else @method = 'copy' end @path = data @format = self.class().url_to_format(data) end fail NoPathOrUrlProvided.new('Must have a path or URL') unless @path unless FORMATS.values.include?(@format) fail UnrecognizedFormat.new("Unrecognized format: #{@format}. Recognized formats: #{FORMATS}.") end end
url_to_format(url)
click to toggle source
# File lib/brick_and_mortar/brick.rb, line 21 def self.url_to_format(url) if url.match(/\.#{FORMATS[:zip]}$/) FORMATS[:zip] elsif url.match(/\.#{FORMATS[:tar_gz]}$/) FORMATS[:tar_gz] elsif url.match(/\.#{FORMATS[:tar_bz2]}$/) FORMATS[:tar_bz2] else FORMATS[:plain] end end