Class: Danger::Dangerfile
- Inherits:
-
Object
- Object
- Danger::Dangerfile
- Includes:
- DSL
- Defined in:
- lib/danger/dangerfile.rb,
lib/danger/dangerfile_dsl.rb
Defined Under Namespace
Modules: DSL
Instance Attribute Summary collapse
-
#defined_in_file ⇒ Pathname
The path where the Dangerfile was loaded from.
-
#env ⇒ Object
Returns the value of attribute env.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#warnings ⇒ Object
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#parse(path, contents = nil) ⇒ Object
Parses the file at a path, optionally takes the content of the file for DI.
-
#print_known_info ⇒ Object
Iterates through the DSL’s attributes, and table’s the output.
-
#to_s ⇒ String
A string useful to represent the Dangerfile in a message presented to the user.
Methods included from DSL
#fail, #initialize, #message, #method_missing, #warn
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Danger::Dangerfile::DSL
Instance Attribute Details
#defined_in_file ⇒ Pathname
Returns the path where the Dangerfile was loaded from. It is nil if the Dangerfile was generated programmatically.
15 16 17 |
# File 'lib/danger/dangerfile.rb', line 15 def defined_in_file @defined_in_file end |
#env ⇒ Object
Returns the value of attribute env.
10 11 12 |
# File 'lib/danger/dangerfile.rb', line 10 def env @env end |
#errors ⇒ Object
Returns the value of attribute errors.
10 11 12 |
# File 'lib/danger/dangerfile.rb', line 10 def errors @errors end |
#messages ⇒ Object
Returns the value of attribute messages.
10 11 12 |
# File 'lib/danger/dangerfile.rb', line 10 def @messages end |
#verbose ⇒ Object
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/danger/dangerfile.rb', line 10 def verbose @verbose end |
#warnings ⇒ Object
Returns the value of attribute warnings.
10 11 12 |
# File 'lib/danger/dangerfile.rb', line 10 def warnings @warnings end |
Instance Method Details
#parse(path, contents = nil) ⇒ Object
Parses the file at a path, optionally takes the content of the file for DI
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/danger/dangerfile.rb', line 48 def parse(path, contents = nil) print_known_info if verbose contents ||= File.open(path, 'r:utf-8', &:read) # Work around for Rubinius incomplete encoding in 1.9 mode if contents.respond_to?(:encoding) && contents.encoding.name != 'UTF-8' contents.encode!('UTF-8') end if contents.tr!('“”‘’‛', %(""''')) # Changes have been made puts "Your #{path.basename} has had smart quotes sanitised. " \ 'To avoid issues in the future, you should not use ' \ 'TextEdit for editing it. If you are not using TextEdit, ' \ 'you should turn off smart quotes in your editor of choice.'.red end if contents.include?("puts") puts "You used `puts` in your Dangerfile. To print out text to GitHub use `message` instead" end self.defined_in_file = path instance_eval do # rubocop:disable Lint/RescueException begin # rubocop:disable Eval eval(contents, nil, path.to_s) # rubocop:enable Eval rescue Exception => e = "Invalid `#{path.basename}` file: #{e.}" raise DSLError.new(, path, e.backtrace, contents) end # rubocop:enable Lint/RescueException end end |
#print_known_info ⇒ Object
Iterates through the DSL’s attributes, and table’s the output
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/danger/dangerfile.rb', line 25 def print_known_info puts "Danger v#{Danger::VERSION}" width = AvailableValues.all.map(&:to_s).map(&:length).max puts "DSL Attributes:" puts "-" * (width + 4) AvailableValues.all.each do |value| spaces = (width - value.to_s.length) puts "| #{value.to_s.blue}#{' ' * spaces} | #{self.send(value)}" end puts "-" * (width + 4) puts "Metadata:" puts "#{'SCM'.blue} : #{env.scm.class}" puts "#{'Source'.blue} : #{env.ci_source.class}" puts "#{'Requests'.blue} : #{env.request_source.class}" puts " #{'Base commit'.blue} : #{env.request_source.base_commit}" puts " #{'HEAD commit'.blue} : #{env.request_source.head_commit}" puts " git diff #{env.request_source.base_commit} #{env.request_source.head_commit}".yellow puts "\n\n" end |
#to_s ⇒ String
Returns a string useful to represent the Dangerfile in a message presented to the user.
20 21 22 |
# File 'lib/danger/dangerfile.rb', line 20 def to_s 'Dangerfile' end |