Module: Danger::Dangerfile::DSL

Included in:
Danger::Dangerfile
Defined in:
lib/danger/dangerfile_dsl.rb

Enviroment collapse

Enviroment collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *_arguments, &_block) ⇒ Object

When an undefined method is called, we check to see if it’s something that either the ‘scm` or the `request_source` can handle. This opens us up to letting those object extend themselves naturally.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/danger/dangerfile_dsl.rb', line 48

def method_missing(method_sym, *_arguments, &_block)
  unless AvailableValues.all.include?(method_sym)
    raise "Unknown method '#{method_sym}', please check out the documentation for available variables".red
  end

  if AvailableValues.scm.include?(method_sym)
    # SCM Source
    return env.scm.send(method_sym)
  end

  if AvailableValues.request_source.include?(method_sym)
    # Request Source
    return env.request_source.send(method_sym)
  end
end

Instance Attribute Details

#envEnvironmentManager (readonly)

objects, which you can use to pull out extra bits of information. Warning the api of these objects is not considered a part of the Dangerfile public API, and is viable to change occasionally on the whims of developers.

Returns:



10
11
12
# File 'lib/danger/dangerfile_dsl.rb', line 10

def env
  @env
end

Instance Method Details

#fail(message) ⇒ Object

Declares a CI blocking error

Parameters:

  • message (String)

    The message to present to the user



22
23
24
25
# File 'lib/danger/dangerfile_dsl.rb', line 22

def fail(message)
  self.errors << message
  puts "Raising error '#{message}'"
end

#initializeObject



12
13
14
15
16
# File 'lib/danger/dangerfile_dsl.rb', line 12

def initialize
  self.warnings = []
  self.errors = []
  self.messages = []
end

#message(message) ⇒ Object

Print out a generate message on the PR

Parameters:

  • message (String)

    The message to present to the user



40
41
42
43
# File 'lib/danger/dangerfile_dsl.rb', line 40

def message(message)
  self.messages << message
  puts "Printing message '#{message}'"
end

#warn(message) ⇒ Object

Specifies a problem, but not critical

Parameters:

  • message (String)

    The message to present to the user



31
32
33
34
# File 'lib/danger/dangerfile_dsl.rb', line 31

def warn(message)
  self.warnings << message
  puts "Printing warning '#{message}'"
end