Class: Fastlane::FastFile
- Inherits:
-
Object
- Object
- Fastlane::FastFile
- Defined in:
- lib/fastlane/fast_file.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#current_platform ⇒ Object
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.
-
#runner ⇒ Object
Stores all relevant information from the currently running process.
DSL collapse
-
#after_all(&block) ⇒ Object
Is executed after each test run.
-
#before_all(&block) ⇒ Object
Is executed before each test run.
-
#error(&block) ⇒ Object
Is executed if an error occured during fastlane execution.
-
#lane(lane_name, &block) ⇒ Object
User defines a new lane.
-
#method_missing(method_sym, *arguments, &_block) ⇒ Object
Is used to look if the method is implemented as an action.
-
#override_lane(lane_name, &block) ⇒ Object
User defines a lane that can overwrite existing lanes.
-
#platform(platform_name, &block) ⇒ Object
User defines a platform block.
-
#private_lane(lane_name, &block) ⇒ Object
User defines a new private lane, which can’t be called from the CLI.
Other things collapse
- #actions_path(path) ⇒ Object
- #collector ⇒ Object
- #desc(string) ⇒ Object
- #desc_collection ⇒ Object
- #import(path = nil) ⇒ Object
-
#is_platform_block?(key) ⇒ Boolean
Is the given key a platform block or a lane?.
-
#sh(command) ⇒ Object
Execute shell command.
Overwriting Ruby methods collapse
- #puts(value) ⇒ Object
-
#say(value) ⇒ Object
Speak out loud.
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ Object
constructor
The runner which can be executed to trigger the given actions.
- #parse(data) ⇒ Object
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 = File.(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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/fastlane/fast_file.rb', line 103 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) rescue NameError => ex # Action not found # Is there a lane under this name? return self.runner.try_switch_to_lane(method_sym, arguments) end # It's important to *not* have this code inside the rescue block # otherwise all NameErrors will be catched and the error message is # confusing 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 end |
Instance Attribute Details
#current_platform ⇒ Object
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 |
#runner ⇒ Object
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
144 145 146 147 148 |
# File 'lib/fastlane/fast_file.rb', line 144 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
93 94 95 |
# File 'lib/fastlane/fast_file.rb', line 93 def after_all(&block) @runner.set_after_all(@current_platform, block) end |
#before_all(&block) ⇒ Object
Is executed before each test run
88 89 90 |
# File 'lib/fastlane/fast_file.rb', line 88 def before_all(&block) @runner.set_before_all(@current_platform, block) end |
#collector ⇒ Object
130 131 132 |
# File 'lib/fastlane/fast_file.rb', line 130 def collector runner.collector end |
#desc(string) ⇒ Object
157 158 159 |
# File 'lib/fastlane/fast_file.rb', line 157 def desc(string) desc_collection << string end |
#desc_collection ⇒ Object
161 162 163 |
# File 'lib/fastlane/fast_file.rb', line 161 def desc_collection @desc_collection ||= [] end |
#error(&block) ⇒ Object
Is executed if an error occured during fastlane execution
98 99 100 |
# File 'lib/fastlane/fast_file.rb', line 98 def error(&block) @runner.set_error(@current_platform, block) end |
#import(path = nil) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/fastlane/fast_file.rb', line 165 def import(path = nil) raise "Please pass a path to the `import` action".red unless path path = path.dup.gsub("~", Dir.home) unless Pathname.new(path).absolute? # unless an absolute path path = File.join(File.('..', @path), path) end raise "Could not find Fastfile at path '#{path}'".red unless File.exists?(path) parse(File.read(path)) end |
#is_platform_block?(key) ⇒ Boolean
Is the given key a platform block or a lane?
135 136 137 138 139 140 141 142 |
# File 'lib/fastlane/fast_file.rb', line 135 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
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fastlane/fast_file.rb', line 38 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, is_private: false)) @desc_collection = nil # reset the collected description again for the next lane end |
#override_lane(lane_name, &block) ⇒ Object
User defines a lane that can overwrite existing lanes. Useful when importing a Fastfile
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fastlane/fast_file.rb', line 64 def override_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, is_private: false), true) @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
77 78 79 80 81 82 83 84 85 |
# File 'lib/fastlane/fast_file.rb', line 77 def platform(platform_name, &block) SupportedPlatforms.verify!platform_name self.current_platform = platform_name block.call self.current_platform = nil end |
#private_lane(lane_name, &block) ⇒ Object
User defines a new private lane, which can’t be called from the CLI
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fastlane/fast_file.rb', line 51 def private_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, is_private: true)) @desc_collection = nil # reset the collected description again for the next lane end |
#puts(value) ⇒ Object
192 193 194 195 196 197 |
# File 'lib/fastlane/fast_file.rb', line 192 def puts(value) # Overwrite this, since there is already a 'puts' method defined in the Ruby standard library value ||= yield collector.did_launch_action(:puts) Fastlane::Actions::PutsAction.run([value]) end |
#say(value) ⇒ Object
Speak out loud
183 184 185 186 187 188 189 190 |
# File 'lib/fastlane/fast_file.rb', line 183 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
151 152 153 154 155 |
# File 'lib/fastlane/fast_file.rb', line 151 def sh(command) Actions.execute_action(command) do Actions.sh_no_action(command) end end |