Class: FastlaneCore::ConfigurationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane_core/configuration/configuration_file.rb

Overview

Responsible for loading configuration files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, path, block_for_missing) ⇒ ConfigurationFile



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fastlane_core/configuration/configuration_file.rb', line 9

def initialize(config, path, block_for_missing)
  self.config = config
  @block_for_missing = block_for_missing

  begin
    # rubocop:disable Lint/Eval
    eval(File.read(path)) # this is okay in this case
    # rubocop:enable Lint/Eval
  rescue SyntaxError => ex
    if ex.to_s.include? ""
      Helper.log.fatal ex
      raise "Invalid quotation: You used the invalid quote ‘ instead of '. Make sure to use a good text editor like Sublime Text to edit your configuration file".red
    else
      line = ex.to_s.match(/\(eval\):(\d+)/)[1]
      raise "Syntax error in your configuration file '#{path}' on line #{line}: #{ex}".red
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fastlane_core/configuration/configuration_file.rb', line 28

def method_missing(method_sym, *arguments, &block)
  # First, check if the key is actually available
  if self.config.all_keys.include? method_sym
    value = arguments.first || (block.call if block_given?) # this is either a block or a value
    if value
      self.config[method_sym] = value
    end
  else
    # We can't set this value, maybe the tool using this configuration system has its own
    # way of handling this block, as this might be a special block (e.g. ipa block) that's only
    # executed on demand
    if @block_for_missing
      @block_for_missing.call(method_sym, arguments, block)
    else
      self.config[method_sym] = '' # important, since this will raise a good exception for free
    end
  end
end

Instance Attribute Details

#configObject

A reference to the actual configuration



5
6
7
# File 'lib/fastlane_core/configuration/configuration_file.rb', line 5

def config
  @config
end