Class: Bundler::DirectorySource

Inherits:
Source
  • Object
show all
Defined in:
lib/bundler08/source.rb

Direct Known Subclasses

GitSource

Instance Attribute Summary collapse

Attributes inherited from Source

#bundle

Instance Method Summary collapse

Constructor Details

#initialize(bundle, options) ⇒ DirectorySource

Returns a new instance of DirectorySource.



189
190
191
192
193
194
195
196
197
# File 'lib/bundler08/source.rb', line 189

def initialize(bundle, options)
  super
  if options[:location]
    @location = Pathname.new(options[:location]).expand_path
  end
  @glob           = options[:glob] || "**/*.gemspec"
  @specs          = {}
  @required_specs = []
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



187
188
189
# File 'lib/bundler08/source.rb', line 187

def location
  @location
end

#required_specsObject (readonly)

Returns the value of attribute required_specs.



187
188
189
# File 'lib/bundler08/source.rb', line 187

def required_specs
  @required_specs
end

#specsObject (readonly)

Returns the value of attribute specs.



187
188
189
# File 'lib/bundler08/source.rb', line 187

def specs
  @specs
end

Instance Method Details

#==(other) ⇒ Object



285
286
287
288
# File 'lib/bundler08/source.rb', line 285

def ==(other)
  # TMP HAX
  other.is_a?(DirectorySource)
end

#add_spec(path, name, version, require_paths = %w(lib)) ⇒ Object



199
200
201
202
203
204
205
# File 'lib/bundler08/source.rb', line 199

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

#download(spec) ⇒ Object



294
295
296
# File 'lib/bundler08/source.rb', line 294

def download(spec)
  # Nothing needed here
end

#gemsObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/bundler08/source.rb', line 211

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

#local?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/bundler08/source.rb', line 207

def local?
  true
end

#locate_gemspecsObject



228
229
230
231
232
233
234
235
236
237
# File 'lib/bundler08/source.rb', line 228

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.expand_path
      specs[spec.full_name] = spec
    end
    specs
  end
end

#merge_defined_specs(specs) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/bundler08/source.rb', line 239

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_sObject



290
291
292
# File 'lib/bundler08/source.rb', line 290

def to_s
  "directory: '#{location}'"
end

#validate_gemspec(path, spec) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/bundler08/source.rb', line 263

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