Method: Fastlane::FastFile#parse

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

#parse(data, path = nil) ⇒ Object



47
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
# File 'fastlane/lib/fastlane/fast_file.rb', line 47

def parse(data, path = nil)
  @runner ||= Runner.new

  Dir.chdir(FastlaneCore::FastlaneFolder.path || Dir.pwd) do # context: fastlane subfolder
    # create nice path that we want to print in case of some problem
    relative_path = path.nil? ? '(eval)' : Pathname.new(path).relative_path_from(Pathname.new(Dir.pwd)).to_s

    begin
      # We have to use #get_binding method, because some test files defines method called `path` (for example SwitcherFastfile)
      # and local variable has higher priority, so it causes to remove content of original Fastfile for example. With #get_binding
      # is this always clear and safe to declare any local variables we want, because the eval function uses the instance scope
      # instead of local.

      # rubocop:disable Security/Eval
      eval(data, parsing_binding, relative_path) # using eval is ok for this case
      # rubocop:enable Security/Eval
    rescue SyntaxError => ex
      match = ex.to_s.match(/#{Regexp.escape(relative_path)}:(\d+)/)
      if match
        line = match[1]
        UI.content_error(data, line)
        UI.user_error!("Syntax error in your Fastfile on line #{line}: #{ex}")
      else
        UI.user_error!("Syntax error in your Fastfile: #{ex}")
      end
    end
  end

  self
end