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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bundler/multilock/ext/dsl.rb', line 46

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



38
39
40
41
42
# File 'lib/bundler/multilock/ext/dsl.rb', line 38

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

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



67
68
69
70
71
# File 'lib/bundler/multilock/ext/dsl.rb', line 67

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

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