Class: Bundler::LazySpecification

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

Defined Under Namespace

Classes: Identifier

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



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

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)



83
84
85
86
87
88
89
# File 'lib/bundler/lazy_specification.rb', line 83

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



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

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name



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

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform



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

def platform
  @platform
end

#remoteObject

Returns the value of attribute remote



13
14
15
# File 'lib/bundler/lazy_specification.rb', line 13

def remote
  @remote
end

#sourceObject

Returns the value of attribute source



13
14
15
# File 'lib/bundler/lazy_specification.rb', line 13

def source
  @source
end

#versionObject (readonly)

Returns the value of attribute version



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

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
# File 'lib/bundler/lazy_specification.rb', line 32

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

#__materialize__Object



57
58
59
# File 'lib/bundler/lazy_specification.rb', line 57

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

#full_nameObject



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

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

#identifierObject



73
74
75
# File 'lib/bundler/lazy_specification.rb', line 73

def identifier
  @__identifier ||= Identifier.new(name, version, source, platform, dependencies)
end

#respond_to?(*args) ⇒ Boolean



61
62
63
# File 'lib/bundler/lazy_specification.rb', line 61

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

#satisfies?(dependency) ⇒ Boolean



36
37
38
# File 'lib/bundler/lazy_specification.rb', line 36

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

#to_lockObject



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

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



65
66
67
68
69
70
71
# File 'lib/bundler/lazy_specification.rb', line 65

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