Module: Bundler::Multilock::Ext::Dsl

Defined in:
lib/bundler/multilock/ext/dsl.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#eval_gemfile(gemfile, contents = nil, &block) ⇒ Object

Significant changes:

* allow a block


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bundler/multilock/ext/dsl.rb', line 35

def eval_gemfile(gemfile, contents = nil, &block)
  expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
  original_gemfile = @gemfile
  @gemfile = expanded_gemfile_path
  @gemfiles << expanded_gemfile_path
  contents ||= Bundler.read_file(@gemfile.to_s)
  if block
    instance_eval(&block)
  else
    instance_eval(contents.dup.tap { |x| x.untaint if RUBY_VERSION < "2.7" }, @gemfile.to_s, 1)
  end
rescue Exception => e # rubocop:disable Lint/RescueException
  message = "There was an error " \
            "#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
            "`#{File.basename gemfile.to_s}`: #{e.message}"

  raise Bundler::Dsl::DSLError.new(message, gemfile, e.backtrace, contents)
ensure
  @gemfile = original_gemfile
end

#initializeObject



27
28
29
30
31
# File 'lib/bundler/multilock/ext/dsl.rb', line 27

def initialize
  super
  @gemfiles = Set.new
  Multilock.loaded! unless Multilock.lockfile_definitions.empty?
end

#lockfile(*args, **kwargs, &block) ⇒ Object



56
57
58
59
60
# File 'lib/bundler/multilock/ext/dsl.rb', line 56

def lockfile(*args, **kwargs, &block)
  return true if Multilock.loaded?

  Multilock.add_lockfile(*args, builder: self, **kwargs, &block)
end