Class: BrickAndMortar::Brick::Config
- Inherits:
-
Object
- Object
- BrickAndMortar::Brick::Config
- Defined in:
- lib/brick_and_mortar/brick.rb
Defined Under Namespace
Classes: UnrecognizedFormat, UnrecognizedRetrievalMethod
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #create! ⇒ Object
- #destroy! ⇒ Object
- #exists? ⇒ Boolean (also: #exist?)
-
#initialize(data, brick_store, verbose = true) ⇒ Config
constructor
A new instance of Config.
- #laid?(project_vendor_dir) ⇒ Boolean
- #lay!(project_vendor_dir) ⇒ Object
- #name_with_version ⇒ Object
Constructor Details
#initialize(data, brick_store, verbose = true) ⇒ Config
Returns a new instance of Config.
79 80 81 82 83 84 85 |
# File 'lib/brick_and_mortar/brick.rb', line 79 def initialize(data, brick_store, verbose = true) @name = data['name'] @version = data['version'] @location = Location.new(data['location']) @destination = File.join(brick_store, name_with_version) @verbose = verbose end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
77 78 79 |
# File 'lib/brick_and_mortar/brick.rb', line 77 def destination @destination end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
77 78 79 |
# File 'lib/brick_and_mortar/brick.rb', line 77 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
77 78 79 |
# File 'lib/brick_and_mortar/brick.rb', line 77 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
77 78 79 |
# File 'lib/brick_and_mortar/brick.rb', line 77 def version @version end |
Instance Method Details
#create! ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/brick_and_mortar/brick.rb', line 97 def create! if exists? if @verbose puts "Using #{name_with_version} in #{@destination}" end else case @location.method when 'git' if @verbose puts "Installing #{name_with_version} to #{@destination} from #{@location.path} with git" end Git.clone_repo(@location.path, @destination) when 'svn' if @verbose puts "Installing #{@name_with_version} to #{@destination} from #{@location.path} with svn" end Svn.checkout_repo(@location.path, @destination) when 'download' if @verbose puts "Installing #{@name_with_version} to #{@destination} from #{@location.path}" end if @location.format == Location::FORMATS[:zip] Download.get_and_unpack_zip(@location.path, @destination) elsif @location.format == Location::FORMATS[:tar_gz] Download.get_and_unpack_tar_gz(@location.path, @destination) elsif @location.format == Location::FORMATS[:tar_bz2] Download.get_and_unpack_tar_bz2(@location.path, @destination) else raise UnrecognizedFormat.new(@location.format) end else raise UnrecognizedRetrievalMethod.new(@location.method) end end end |
#destroy! ⇒ Object
144 145 146 |
# File 'lib/brick_and_mortar/brick.rb', line 144 def destroy! FileUtils.rm_rf @destination, {:secure => true} end |
#exists? ⇒ Boolean Also known as: exist?
91 92 93 |
# File 'lib/brick_and_mortar/brick.rb', line 91 def exists? File.exist? @destination end |
#laid?(project_vendor_dir) ⇒ Boolean
133 134 135 |
# File 'lib/brick_and_mortar/brick.rb', line 133 def laid?(project_vendor_dir) File.exist? File.join(project_vendor_dir, name) end |
#lay!(project_vendor_dir) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/brick_and_mortar/brick.rb', line 137 def lay!(project_vendor_dir) create! unless laid?(project_vendor_dir) File.symlink @destination, File.join(project_vendor_dir, name) end end |
#name_with_version ⇒ Object
87 88 89 |
# File 'lib/brick_and_mortar/brick.rb', line 87 def name_with_version "#{@name}-#{@version}" end |