Class: Bundler::LazySpecification

Inherits:
Object
  • Object
show all
Includes:
MatchPlatform
Defined in:
lib/bundler/lazy_specification.rb

Constant Summary

Constants included from GemHelpers

GemHelpers::GENERICS, GemHelpers::GENERIC_CACHE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MatchPlatform

#match_platform

Methods included from GemHelpers

generic, generic_local_platform

Constructor Details

#initialize(name, version, platform, source = nil) ⇒ LazySpecification

Returns a new instance of LazySpecification



13
14
15
16
17
18
19
20
# File 'lib/bundler/lazy_specification.rb', line 13

def initialize(name, version, platform, source = nil)
  @name          = name
  @version       = version
  @dependencies  = []
  @platform      = platform
  @source        = source
  @specification = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object (private)



77
78
79
80
81
82
83
# File 'lib/bundler/lazy_specification.rb', line 77

def method_missing(method, *args, &blk)
  raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification

  return super unless respond_to?(method)

  @specification.send(method, *args, &blk)
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies



10
11
12
# File 'lib/bundler/lazy_specification.rb', line 10

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name



10
11
12
# File 'lib/bundler/lazy_specification.rb', line 10

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform



10
11
12
# File 'lib/bundler/lazy_specification.rb', line 10

def platform
  @platform
end

#remoteObject

Returns the value of attribute remote



11
12
13
# File 'lib/bundler/lazy_specification.rb', line 11

def remote
  @remote
end

#sourceObject

Returns the value of attribute source



11
12
13
# File 'lib/bundler/lazy_specification.rb', line 11

def source
  @source
end

#versionObject (readonly)

Returns the value of attribute version



10
11
12
# File 'lib/bundler/lazy_specification.rb', line 10

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
# File 'lib/bundler/lazy_specification.rb', line 30

def ==(other)
  identifier == other.identifier
end

#__materialize__Object



55
56
57
# File 'lib/bundler/lazy_specification.rb', line 55

def __materialize__
  @specification = source.specs.search(Gem::Dependency.new(name, version)).last
end

#full_nameObject



22
23
24
25
26
27
28
# File 'lib/bundler/lazy_specification.rb', line 22

def full_name
  if platform == Gem::Platform::RUBY || platform.nil?
    "#{@name}-#{@version}"
  else
    "#{@name}-#{@version}-#{platform}"
  end
end

#identifierObject



67
68
69
# File 'lib/bundler/lazy_specification.rb', line 67

def identifier
  @__identifier ||= [name, version, source, platform, dependencies].hash
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/bundler/lazy_specification.rb', line 59

def respond_to?(*args)
  super || @specification ? @specification.respond_to?(*args) : nil
end

#satisfies?(dependency) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/bundler/lazy_specification.rb', line 34

def satisfies?(dependency)
  @name == dependency.name && dependency.requirement.satisfied_by?(Gem::Version.new(@version))
end

#to_lockObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bundler/lazy_specification.rb', line 38

def to_lock
  out = String.new

  if platform == Gem::Platform::RUBY || platform.nil?
    out << "    #{name} (#{version})\n"
  else
    out << "    #{name} (#{version}-#{platform})\n"
  end

  dependencies.sort_by(&:to_s).uniq.each do |dep|
    next if dep.type == :development
    out << "    #{dep.to_lock}\n"
  end

  out
end

#to_sObject



63
64
65
# File 'lib/bundler/lazy_specification.rb', line 63

def to_s
  @__to_s ||= "#{name} (#{version})"
end