Class: Fastlane::FastFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/fast_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Object

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



6
7
8
9
10
11
12
13
# File 'lib/fastlane/fast_file.rb', line 6

def initialize(path = nil)
  return unless (path || '').length > 0
  raise "Could not find Fastfile at path '#{path}'".red unless File.exist?(path)
  @path = path
  content = File.read(path)

  parse(content)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fastlane/fast_file.rb', line 63

def method_missing(method_sym, *arguments, &_block)
  # First, check if there is a predefined method in the actions folder

  class_name = method_sym.to_s.classify + 'Action'
  class_ref = nil
  begin
    class_ref = Fastlane::Actions.const_get(class_name)
  rescue NameError => ex
    # Action not found
    raise "Could not find method '#{method_sym}'. Check out the README for more details: https://github.com/KrauseFx/fastlane".red
  end

  if class_ref && class_ref.respond_to?(:run)
    line = "----------" + ("-" * method_sym.to_s.length) + "----"
    Helper.log.info line.green
    Helper.log.info "--- Step: #{method_sym.to_s} ---".green
    Helper.log.info line.green

    Dir.chdir('..') do # go up from the fastlane folder, to the project folder
      Actions.execute_action(method_sym) do
        class_ref.run(arguments)
      end
    end
  else
    raise "Action '#{method_sym}' of class '#{class_name}' was found, but has no `run` method.".red
  end
end

Instance Attribute Details

#runnerObject

Returns the value of attribute runner.



3
4
5
# File 'lib/fastlane/fast_file.rb', line 3

def runner
  @runner
end

Instance Method Details

#actions_path(path) ⇒ Object



50
51
52
53
54
# File 'lib/fastlane/fast_file.rb', line 50

def actions_path(path)
  raise "Path '#{path}' not found!".red unless File.directory?(path)

  Actions.load_external_actions(path)
end

#after_all(&block) ⇒ Object



33
34
35
# File 'lib/fastlane/fast_file.rb', line 33

def after_all(&block)
  @runner.set_after_all(block)
end

#before_all(&block) ⇒ Object



29
30
31
# File 'lib/fastlane/fast_file.rb', line 29

def before_all(&block)
  @runner.set_before_all(block)
end

#error(&block) ⇒ Object



37
38
39
# File 'lib/fastlane/fast_file.rb', line 37

def error(&block)
  @runner.set_error(block)
end

#lane(key, &block) ⇒ Object



25
26
27
# File 'lib/fastlane/fast_file.rb', line 25

def lane(key, &block)
  @runner.set_block(key, block)
end

#parse(data) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/fastlane/fast_file.rb', line 15

def parse(data)
  @runner = Runner.new

  Dir.chdir(Fastlane::FastlaneFolder.path || Dir.pwd) do # context: fastlane subfolder
    eval(data) # this is okay in this case
  end

  self
end

#say(value) ⇒ Object

Speak out loud



42
43
44
45
46
47
48
# File 'lib/fastlane/fast_file.rb', line 42

def say(value)
  # Overwrite this, since there is already a 'say' method defined in the Ruby standard library
  value ||= yield
  Actions.execute_action('say') do
    Fastlane::Actions::SayAction.run([value])
  end
end

#sh(command) ⇒ Object

Execute shell command



57
58
59
60
61
# File 'lib/fastlane/fast_file.rb', line 57

def sh(command)
  Actions.execute_action(command) do
    Actions.sh_no_action(command)
  end
end