Class: Prebundler::GemfileInterpreter

Inherits:
Object
  • Object
show all
Defined in:
lib/prebundler/gemfile_interpreter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemfile_path, bundle_path, options) ⇒ GemfileInterpreter

Returns a new instance of GemfileInterpreter.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/prebundler/gemfile_interpreter.rb', line 11

def initialize(gemfile_path, bundle_path, options)
  @gems = {}
  @current_groups = [:global]
  @gemfile_path = gemfile_path
  @bundle_path = bundle_path
  @prefix = options[:prefix]
  instance_eval(File.read(gemfile_path))

  lockfile = Bundler::LockfileParser.new(File.read("#{gemfile_path}.lock"))

  lockfile.specs.each do |spec|
    gems[spec.name] ||= GemRef.create(spec.name, bundle_path, options)
    gems[spec.name].spec = spec
    gems[spec.name].dependencies = spec.dependencies.map(&:name)
  end

  # Get rid of gems without a spec, as they are likely not supposed
  # to be installed. This happens for gems like tzinfo-data which are
  # listed in the standard rails Gemfile but only installed on
  # certain platforms.
  gems.reject! { |_, g| g.spec.nil? }
end

Instance Attribute Details

#bundle_pathObject (readonly)

Returns the value of attribute bundle_path.



9
10
11
# File 'lib/prebundler/gemfile_interpreter.rb', line 9

def bundle_path
  @bundle_path
end

#gemfile_pathObject (readonly)

Returns the value of attribute gemfile_path.



9
10
11
# File 'lib/prebundler/gemfile_interpreter.rb', line 9

def gemfile_path
  @gemfile_path
end

#gemsObject (readonly)

Returns the value of attribute gems.



9
10
11
# File 'lib/prebundler/gemfile_interpreter.rb', line 9

def gems
  @gems
end

#prefixObject (readonly)

Returns the value of attribute prefix.



9
10
11
# File 'lib/prebundler/gemfile_interpreter.rb', line 9

def prefix
  @prefix
end

Class Method Details

.interpret(gemfile_path, bundle_path, options = {}) ⇒ Object



5
6
7
# File 'lib/prebundler/gemfile_interpreter.rb', line 5

def self.interpret(gemfile_path, bundle_path, options = {})
  Gemfile.new(new(gemfile_path, bundle_path, options).gems)
end

Instance Method Details

#current_contextObject



34
35
36
37
38
39
40
41
# File 'lib/prebundler/gemfile_interpreter.rb', line 34

def current_context
  {
    path: @current_path,
    groups: @current_groups,
    source: @current_source,
    prefix: prefix
  }
end

#gem(name, *args) ⇒ Object



50
51
52
53
# File 'lib/prebundler/gemfile_interpreter.rb', line 50

def gem(name, *args)
  options = args.find { |a| a.is_a?(Hash) } || {}
  gems[name] = GemRef.create(name, bundle_path, current_context.merge(options))
end

#gemspecObject



73
74
75
# File 'lib/prebundler/gemfile_interpreter.rb', line 73

def gemspec
  # do nothing
end

#git_source(*args) ⇒ Object

this is probably the wrong thing to do



47
48
# File 'lib/prebundler/gemfile_interpreter.rb', line 47

def git_source(*args)
end

#group(*groups) ⇒ Object



67
68
69
70
71
# File 'lib/prebundler/gemfile_interpreter.rb', line 67

def group(*groups)
  @current_groups = groups
  yield if block_given?
  @current_groups = [:global]
end

#path(dir) ⇒ Object



55
56
57
58
59
# File 'lib/prebundler/gemfile_interpreter.rb', line 55

def path(dir)
  @current_path = File.join(File.dirname(gemfile_path), dir)
  yield if block_given?
  @current_path = nil
end

#ruby(*args) ⇒ Object



43
44
# File 'lib/prebundler/gemfile_interpreter.rb', line 43

def ruby(*args)
end

#source(url) ⇒ Object



61
62
63
64
65
# File 'lib/prebundler/gemfile_interpreter.rb', line 61

def source(url)
  @current_source = url
  yield if block_given?
  @current_source = nil
end