Class: Bundler::DirectorySource

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

Direct Known Subclasses

GitSource

Instance Attribute Summary collapse

Attributes inherited from Source

#local, #repository

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DirectorySource

Returns a new instance of DirectorySource.



176
177
178
179
180
181
182
183
# File 'lib/bundler/source.rb', line 176

def initialize(options)
  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.



174
175
176
# File 'lib/bundler/source.rb', line 174

def location
  @location
end

#required_specsObject (readonly)

Returns the value of attribute required_specs.



174
175
176
# File 'lib/bundler/source.rb', line 174

def required_specs
  @required_specs
end

#specsObject (readonly)

Returns the value of attribute specs.



174
175
176
# File 'lib/bundler/source.rb', line 174

def specs
  @specs
end

Instance Method Details

#==(other) ⇒ Object



271
272
273
274
# File 'lib/bundler/source.rb', line 271

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

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



185
186
187
188
189
190
191
# File 'lib/bundler/source.rb', line 185

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

Returns:

  • (Boolean)


193
194
195
# File 'lib/bundler/source.rb', line 193

def can_be_local?
  true
end

#download(spec) ⇒ Object



280
281
282
# File 'lib/bundler/source.rb', line 280

def download(spec)
  # Nothing needed here
end

#gemsObject



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/bundler/source.rb', line 197

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_gemspecsObject



214
215
216
217
218
219
220
221
222
223
# File 'lib/bundler/source.rb', line 214

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



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/bundler/source.rb', line 225

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



276
277
278
# File 'lib/bundler/source.rb', line 276

def to_s
  "#{@name} (#{@version}) Located at: '#{location}'"
end

#validate_gemspec(path, spec) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/bundler/source.rb', line 249

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