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) ⇒ GemfileInterpreter

Returns a new instance of GemfileInterpreter.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/prebundler/gemfile_interpreter.rb', line 11

def initialize(gemfile_path, bundle_path)
  @gems = {}
  @current_groups = [:global]
  @gemfile_path = gemfile_path
  @bundle_path = bundle_path
  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)
    gems[spec.name].spec = spec
    gems[spec.name].dependencies = spec.dependencies.map(&:name)
  end
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

Class Method Details

.interpret(gemfile_path, bundle_path) ⇒ Object



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

def self.interpret(gemfile_path, bundle_path)
  Gemfile.new(new(gemfile_path, bundle_path).gems)
end

Instance Method Details

#current_contextObject



27
28
29
30
31
32
33
# File 'lib/prebundler/gemfile_interpreter.rb', line 27

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

#gem(name, *args) ⇒ Object



35
36
37
38
# File 'lib/prebundler/gemfile_interpreter.rb', line 35

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



58
59
60
# File 'lib/prebundler/gemfile_interpreter.rb', line 58

def gemspec
  # do nothing
end

#group(*groups) ⇒ Object



52
53
54
55
56
# File 'lib/prebundler/gemfile_interpreter.rb', line 52

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

#path(dir) ⇒ Object



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

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

#source(url) ⇒ Object



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

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