Class: BrickAndMortar::Brick::Location
- Inherits:
-
Object
- Object
- BrickAndMortar::Brick::Location
- Defined in:
- lib/brick_and_mortar/brick.rb
Defined Under Namespace
Classes: NoPathOrUrlProvided, UnrecognizedFormat
Constant Summary collapse
- FORMATS =
{ :plain => 'plain', :zip => 'zip', :tar_gz => 'tar.gz', :tar_bz2 => 'tar.bz2' }
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
(also: #url)
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize(data) ⇒ Location
Returns a new instance of Location.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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' 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 |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/brick_and_mortar/brick.rb', line 12 def format @format end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
12 13 14 |
# File 'lib/brick_and_mortar/brick.rb', line 12 def method @method end |
#path ⇒ Object (readonly) Also known as: url
Returns the value of attribute path.
12 13 14 |
# File 'lib/brick_and_mortar/brick.rb', line 12 def path @path end |
Class Method Details
.url_to_format(url) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# 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 |