Class: Bundler::DirectorySource
- Defined in:
- lib/bowline/bundler/source.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#required_specs ⇒ Object
readonly
Returns the value of attribute required_specs.
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Attributes inherited from Source
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_spec(path, name, version, require_paths = %w(lib))) ⇒ Object
- #can_be_local? ⇒ Boolean
- #download(spec) ⇒ Object
- #gems ⇒ Object
-
#initialize(bundle, options) ⇒ DirectorySource
constructor
A new instance of DirectorySource.
- #locate_gemspecs ⇒ Object
- #merge_defined_specs(specs) ⇒ Object
- #to_s ⇒ Object
- #validate_gemspec(path, spec) ⇒ Object
Constructor Details
#initialize(bundle, options) ⇒ DirectorySource
Returns a new instance of DirectorySource.
190 191 192 193 194 195 196 197 198 |
# File 'lib/bowline/bundler/source.rb', line 190 def initialize(bundle, ) super if [:location] @location = Pathname.new([:location]). end @glob = [:glob] || "**/*.gemspec" @specs = {} @required_specs = [] end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
188 189 190 |
# File 'lib/bowline/bundler/source.rb', line 188 def location @location end |
#required_specs ⇒ Object (readonly)
Returns the value of attribute required_specs.
188 189 190 |
# File 'lib/bowline/bundler/source.rb', line 188 def required_specs @required_specs end |
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
188 189 190 |
# File 'lib/bowline/bundler/source.rb', line 188 def specs @specs end |
Instance Method Details
#==(other) ⇒ Object
286 287 288 289 |
# File 'lib/bowline/bundler/source.rb', line 286 def ==(other) # TMP HAX other.is_a?(DirectorySource) end |
#add_spec(path, name, version, require_paths = %w(lib))) ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/bowline/bundler/source.rb', line 200 def add_spec(path, name, version, require_paths = %w(lib)) raise DirectorySourceError, "already have a gem defined for '#{path}'" if @specs[path.to_s] @specs[path.to_s] = Gem::Specification.new do |s| s.name = name s.version = Gem::Version.new(version) end end |
#can_be_local? ⇒ Boolean
208 209 210 |
# File 'lib/bowline/bundler/source.rb', line 208 def can_be_local? true end |
#download(spec) ⇒ Object
295 296 297 |
# File 'lib/bowline/bundler/source.rb', line 295 def download(spec) # Nothing needed here end |
#gems ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/bowline/bundler/source.rb', line 212 def gems @gems ||= begin # Locate all gemspecs from the directory specs = locate_gemspecs specs = merge_defined_specs(specs) required_specs.each do |required| unless specs.any? {|k,v| v.name == required } raise DirectorySourceError, "No gemspec for '#{required}' was found in" \ " '#{location}'. Please explicitly specify a version." end end process_source_gems(specs) end end |
#locate_gemspecs ⇒ Object
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/bowline/bundler/source.rb', line 229 def locate_gemspecs Dir["#{location}/#{@glob}"].inject({}) do |specs, file| file = Pathname.new(file) if spec = eval(File.read(file)) # and validate_gemspec(file.dirname, spec) spec.location = file.dirname. specs[spec.full_name] = spec end specs end end |
#merge_defined_specs(specs) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/bowline/bundler/source.rb', line 240 def merge_defined_specs(specs) @specs.each do |path, spec| # Set the spec location spec.location = "#{location}/#{path}" if existing = specs.values.find { |s| s.name == spec.name } if existing.version != spec.version raise DirectorySourceError, "The version you specified for #{spec.name}" \ " is #{spec.version}. The gemspec is #{existing.version}." # Not sure if this is needed # ==== # elsif File.expand_path(existing.location) != File.expand_path(spec.location) # raise DirectorySourceError, "The location you specified for #{spec.name}" \ # " is '#{spec.location}'. The gemspec was found at '#{existing.location}'." end # elsif !validate_gemspec(spec.location, spec) # raise "Your gem definition is not valid: #{spec}" else specs[spec.full_name] = spec end end specs end |
#to_s ⇒ Object
291 292 293 |
# File 'lib/bowline/bundler/source.rb', line 291 def to_s "directory: '#{location}'" end |
#validate_gemspec(path, spec) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/bowline/bundler/source.rb', line 264 def validate_gemspec(path, spec) path = Pathname.new(path) msg = "Gemspec for #{spec.name} (#{spec.version}) is invalid:" # Check the require_paths (spec.require_paths || []).each do |require_path| unless path.join(require_path).directory? Bundler.logger.warn "#{msg} Missing require path: '#{require_path}'" return false end end # Check the executables (spec.executables || []).each do |exec| unless path.join(spec.bindir, exec).file? Bundler.logger.warn "#{msg} Missing executable: '#{File.join(spec.bindir, exec)}'" return false end end true end |