Sha256: 4213ea5d1cadfd83c34bd91a36db1d0ca15a63bb54890ba0924bba8579c0855b

Contents?: true

Size: 1.61 KB

Versions: 14

Compression:

Stored size: 1.61 KB

Contents

module Danger
  class Plugin
    def initialize(dangerfile)
      @dangerfile = dangerfile
    end

    def self.instance_name
      to_s.gsub("Danger", "").danger_underscore.split("/").last
    end

    # Both of these methods exist on all objects
    # http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-warn
    # http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-fail
    # However, as we're using using them in the DSL, they won't
    # get method_missing called correctly.
    undef :warn, :fail

    # Since we have a reference to the Dangerfile containing all the information
    # We need to redirect the self calls to the Dangerfile

    # rubocop:disable Style/MethodMissing
    def method_missing(method_sym, *arguments, **keyword_arguments, &block)
      if keyword_arguments.empty?
        @dangerfile.send(method_sym, *arguments, &block)
      else
        @dangerfile.send(method_sym, *arguments, **keyword_arguments, &block)
      end
    end

    def self.all_plugins
      @all_plugins ||= []
    end

    def self.clear_external_plugins
      @all_plugins = @all_plugins.select { |plugin| Dangerfile.essential_plugin_classes.include? plugin }
    end

    def self.inherited(plugin)
      Plugin.all_plugins.push(plugin)
    end

    private

    # When using `danger local --pry`, every plugin had an unreasonable
    # amount of text output due to the Dangerfile reference in every
    # plugin. So, it is filtered out. Users will start out in the context
    # of the Dangerfile, and can view it by just typing `self` into the REPL.
    #
    def pretty_print_instance_variables
      super - [:@dangerfile]
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
danger-9.1.0 lib/danger/plugin_support/plugin.rb
danger-9.0.0 lib/danger/plugin_support/plugin.rb
danger-8.6.1 lib/danger/plugin_support/plugin.rb
danger-8.6.0 lib/danger/plugin_support/plugin.rb
danger-8.5.0 lib/danger/plugin_support/plugin.rb
danger-8.4.5 lib/danger/plugin_support/plugin.rb
danger-8.4.4 lib/danger/plugin_support/plugin.rb
danger-8.4.3 lib/danger/plugin_support/plugin.rb
danger-8.4.2 lib/danger/plugin_support/plugin.rb
danger-8.4.1 lib/danger/plugin_support/plugin.rb
danger-8.4.0 lib/danger/plugin_support/plugin.rb
danger-8.3.1 lib/danger/plugin_support/plugin.rb
danger-8.2.3 lib/danger/plugin_support/plugin.rb
danger-8.2.2 lib/danger/plugin_support/plugin.rb