Method: Fastlane::FastFile#initialize

Defined in:
fastlane/lib/fastlane/fast_file.rb

#initialize(path = nil) ⇒ Object

Returns The runner which can be executed to trigger the given actions.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'fastlane/lib/fastlane/fast_file.rb', line 15

def initialize(path = nil)
  return unless (path || '').length > 0
  UI.user_error!("Could not find Fastfile at path '#{path}'") unless File.exist?(path)
  @path = File.expand_path(path)
  content = File.read(path, encoding: "utf-8")

  # From https://github.com/orta/danger/blob/master/lib/danger/Dangerfile.rb
  if content.tr!('“”‘’‛', %(""'''))
    UI.error("Your #{File.basename(path)} 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.')
  end

  content.scan(/^\s*require ["'](.*?)["']/).each do |current|
    gem_name = current.last
    next if gem_name.include?(".") # these are local gems

    begin
      require(gem_name)
    rescue LoadError
      UI.important("You have required a gem, if this is a third party gem, please use `fastlane_require '#{gem_name}'` to ensure the gem is installed locally.")
    end
  end

  parse(content, @path)
end