Sha256: 9c3b192eeb5bfd57e97f682adae67342427cefe3a83c208ae77c1e3a0d472a0e

Contents?: true

Size: 1.68 KB

Versions: 89

Compression:

Stored size: 1.68 KB

Contents

module Capistrano
  class ExtensionProxy #:nodoc:
    def initialize(config, mod)
      @config = config
      extend(mod)
    end

    def method_missing(sym, *args, &block)
      @config.send(sym, *args, &block)
    end
  end

  # Holds the set of registered plugins, keyed by name (where the name is a
  # symbol).
  EXTENSIONS = {}

  # Register the given module as a plugin with the given name. It will henceforth
  # be available via a proxy object on Configuration instances, accessible by
  # a method with the given name.
  def self.plugin(name, mod)
    name = name.to_sym
    return false if EXTENSIONS.has_key?(name)

    methods = Capistrano::Configuration.public_instance_methods +
      Capistrano::Configuration.protected_instance_methods +
      Capistrano::Configuration.private_instance_methods

    if methods.any? { |m| m.to_sym == name }
      raise Capistrano::Error, "registering a plugin named `#{name}' would shadow a method on Capistrano::Configuration with the same name"
    end

    Capistrano::Configuration.class_eval <<-STR, __FILE__, __LINE__+1
      def #{name}
        @__#{name}_proxy ||= Capistrano::ExtensionProxy.new(self, Capistrano::EXTENSIONS[#{name.inspect}])
      end
    STR

    EXTENSIONS[name] = mod
    return true
  end

  # Unregister the plugin with the given name.
  def self.remove_plugin(name)
    name = name.to_sym
    if EXTENSIONS.delete(name)
      Capistrano::Configuration.send(:remove_method, name)
      return true
    end

    return false
  end

  def self.configuration(*args) #:nodoc:
    warn "[DEPRECATION] Capistrano.configuration is deprecated. Use Capistrano::Configuration.instance instead"
    Capistrano::Configuration.instance(*args)
  end
end

Version data entries

89 entries across 89 versions & 11 rubygems

Version Path
capistrano-2.7.0 lib/capistrano/extensions.rb
capistrano-2.6.1.pre lib/capistrano/extensions.rb
capistrano-2.6.0 lib/capistrano/extensions.rb
capistrano-2.5.21 lib/capistrano/extensions.rb
capistrano-2.5.20 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.024 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.023 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.022 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.021 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.020 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.019 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.018 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.017 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.016 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.015 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.014 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.013 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.012 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.011 lib/capistrano/extensions.rb
le1t0-capistrano-2.5.18.010 lib/capistrano/extensions.rb