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

Constructor Details

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

Returns a new instance of LazySpecification.



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

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)



61
62
63
64
65
66
67
68
# File 'lib/bundler/lazy_specification.rb', line 61

def method_missing(method, *args, &blk)
  if Gem::Specification.new.respond_to?(method)
    raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification
    @specification.send(method, *args, &blk)
  else
    super
  end
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



8
9
10
# File 'lib/bundler/lazy_specification.rb', line 8

def dependencies
  @dependencies
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/bundler/lazy_specification.rb', line 8

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform.



8
9
10
# File 'lib/bundler/lazy_specification.rb', line 8

def platform
  @platform
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/bundler/lazy_specification.rb', line 8

def version
  @version
end

Instance Method Details

#__materialize__Object



47
48
49
# File 'lib/bundler/lazy_specification.rb', line 47

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

#full_nameObject



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

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

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/bundler/lazy_specification.rb', line 51

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

#satisfies?(dependency) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/bundler/lazy_specification.rb', line 28

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

#to_lockObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bundler/lazy_specification.rb', line 32

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

  dependencies.sort_by {|d| d.name }.each do |dep|
    next if dep.type == :development
    out << "    #{dep.to_lock}\n"
  end

  out
end

#to_sObject



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

def to_s
  "#{name} (#{version})"
end