Class: Fastlane::FastFile

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

Constant Summary collapse

SharedValues =
Fastlane::Actions::SharedValues

Instance Attribute Summary collapse

DSL collapse

Other things collapse

Overwriting Ruby methods collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Object

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



13
14
15
16
17
18
19
20
# File 'lib/fastlane/fast_file.rb', line 13

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

Is used to look if the method is implemented as an action



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fastlane/fast_file.rb', line 77

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.fastlane_class + 'Action'
  class_ref = nil
  begin
    class_ref = Fastlane::Actions.const_get(class_name)
    if class_ref && class_ref.respond_to?(:run)
      # Action is available, now execute it
      return self.runner.execute_action(method_sym, class_ref, arguments)
    else
      raise "Action '#{method_sym}' of class '#{class_name}' was found, but has no `run` method.".red
    end
  rescue NameError => ex
    # Action not found
    # Is there a lane under this name?
    return self.runner.try_switch_to_lane(method_sym, arguments)
  end
end

Instance Attribute Details

#current_platformObject

the platform in which we’re currently in when parsing the Fastfile This is used to identify the platform in which the lane is in



8
9
10
# File 'lib/fastlane/fast_file.rb', line 8

def current_platform
  @current_platform
end

#runnerObject

Stores all relevant information from the currently running process



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

def runner
  @runner
end

Instance Method Details

#actions_path(path) ⇒ Object



114
115
116
117
118
# File 'lib/fastlane/fast_file.rb', line 114

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

  Actions.load_external_actions(path)
end

#after_all(&block) ⇒ Object

Is executed after each test run



67
68
69
# File 'lib/fastlane/fast_file.rb', line 67

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

#before_all(&block) ⇒ Object

Is executed before each test run



62
63
64
# File 'lib/fastlane/fast_file.rb', line 62

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

#collectorObject



100
101
102
# File 'lib/fastlane/fast_file.rb', line 100

def collector
  runner.collector
end

#desc(string) ⇒ Object



127
128
129
# File 'lib/fastlane/fast_file.rb', line 127

def desc(string)
  desc_collection << string
end

#desc_collectionObject



131
132
133
# File 'lib/fastlane/fast_file.rb', line 131

def desc_collection
  @desc_collection ||= []
end

#error(&block) ⇒ Object

Is executed if an error occured during fastlane execution



72
73
74
# File 'lib/fastlane/fast_file.rb', line 72

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

#is_platform_block?(key) ⇒ Boolean

Is the given key a platform block or a lane?

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
# File 'lib/fastlane/fast_file.rb', line 105

def is_platform_block?(key)
  raise 'No key given'.red unless key

  return false if (self.runner.lanes[nil][key.to_sym] rescue false)
  return true if self.runner.lanes[key.to_sym].kind_of?Hash

  raise "Could not find '#{key}'. Available lanes: #{self.runner.available_lanes.join(', ')}".red
end

#lane(lane_name, &block) ⇒ Object

User defines a new lane



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

def lane(lane_name, &block)
  raise "You have to pass a block using 'do' for lane '#{lane_name}'. Make sure you read the docs on GitHub.".red unless block
  
  self.runner.add_lane(Lane.new(platform: self.current_platform,
                                   block: block,
                             description: desc_collection,
                                    name: lane_name))

  @desc_collection = nil # reset the collected description again for the next lane
end

#parse(data) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/fast_file.rb', line 22

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

#platform(platform_name, &block) ⇒ Object

User defines a platform block



51
52
53
54
55
56
57
58
59
# File 'lib/fastlane/fast_file.rb', line 51

def platform(platform_name, &block)
  SupportedPlatforms.verify!platform_name

  self.current_platform = platform_name

  block.call

  self.current_platform = nil
end

#puts(value) ⇒ Object



149
150
151
152
153
154
155
156
# File 'lib/fastlane/fast_file.rb', line 149

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

#say(value) ⇒ Object

Speak out loud



140
141
142
143
144
145
146
147
# File 'lib/fastlane/fast_file.rb', line 140

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
    collector.did_launch_action(:say)
    Fastlane::Actions::SayAction.run([value])
  end
end

#sh(command) ⇒ Object

Execute shell command



121
122
123
124
125
# File 'lib/fastlane/fast_file.rb', line 121

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