Class: Bundler::Plugin::DSL

Inherits:
Dsl
  • Object
show all
Defined in:
lib/bundler/plugin/dsl.rb

Overview

Dsl to parse the Gemfile looking for plugins to install

Defined Under Namespace

Classes: PluginGemfileError

Constant Summary

Constants inherited from Dsl

Dsl::VALID_KEYS, Dsl::VALID_PLATFORMS

Instance Attribute Summary collapse

Attributes inherited from Dsl

#dependencies, #gemspecs

Instance Method Summary collapse

Methods inherited from Dsl

#check_primary_source_safety, #env, #eval_gemfile, evaluate, #gem, #gemspec, #git, #git_source, #github, #group, #install_if, #path, #platforms, #to_definition

Methods included from RubyDsl

#ruby

Constructor Details

#initializeDSL

Returns a new instance of DSL.



25
26
27
28
29
# File 'lib/bundler/plugin/dsl.rb', line 25

def initialize
  super
  @sources = Plugin::SourceList.new
  @inferred_plugins = [] # The source plugins inferred from :type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Raises:



35
36
37
# File 'lib/bundler/plugin/dsl.rb', line 35

def method_missing(name, *args)
  raise PluginGemfileError, "Undefined local variable or method `#{name}' for Gemfile" unless Bundler::Dsl.method_defined? name
end

Instance Attribute Details

#inferred_pluginsObject (readonly)

This lists the plugins that was added automatically and not specified by the user.

When we encounter :type attribute with a source block, we add a plugin by name bundler-source-<type> to list of plugins to be installed.

These plugins are optional and are not installed when there is conflict with any other plugin.



23
24
25
# File 'lib/bundler/plugin/dsl.rb', line 23

def inferred_plugins
  @inferred_plugins
end

Instance Method Details

#plugin(name, *args) ⇒ Object



31
32
33
# File 'lib/bundler/plugin/dsl.rb', line 31

def plugin(name, *args)
  _gem(name, *args)
end

#source(source, *args, &blk) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bundler/plugin/dsl.rb', line 39

def source(source, *args, &blk)
  options = args.last.is_a?(Hash) ? args.pop.dup : {}
  options = normalize_hash(options)
  return super unless options.key?("type")

  plugin_name = "bundler-source-#{options["type"]}"

  return if @dependencies.any? {|d| d.name == plugin_name }

  plugin(plugin_name)
  @inferred_plugins << plugin_name
end