Class: Fastlane::FastFile
- Inherits:
-
Object
- Object
- Fastlane::FastFile
- Defined in:
- lib/fastlane/fast_file.rb
Constant Summary collapse
Fastlane::Actions::SharedValues
Instance Attribute Summary collapse
-
#runner ⇒ Object
Returns the value of attribute runner.
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.
-
#platform(platform_name, &block) ⇒ Object
User defines a platform block.
Other things collapse
- #actions_path(path) ⇒ Object
- #collector ⇒ Object
- #desc(string) ⇒ Object
- #desc_collection ⇒ Object
-
#did_finish ⇒ Object
Fastfile was finished executing.
-
#is_platform_block?(key) ⇒ Boolean
Is the given key a platform block or a lane?.
-
#say(value) ⇒ Object
Speak out loud.
-
#sh(command) ⇒ Object
Execute shell command.
- #verify_supported_os(name, class_ref) ⇒ Object
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.
8 9 10 11 12 13 14 15 |
# File 'lib/fastlane/fast_file.rb', line 8 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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 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 72 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 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) collector.did_launch_action(method_sym) step_name = class_ref.step_text rescue nil step_name = method_sym.to_s unless step_name verify_supported_os(method_sym, class_ref) Helper.log_alert("Step: " + step_name) begin Dir.chdir('..') do # go up from the fastlane folder, to the project folder Actions.execute_action(method_sym) do # arguments is an array by default, containing an hash with the actual parameters # Since we usually just need the passed hash, we'll just use the first object if there is only one if arguments.count == 0 arguments = ConfigurationHelper.parse(class_ref, {}) # no parameters => empty hsh elsif arguments.count == 1 and arguments.first.kind_of?Hash arguments = ConfigurationHelper.parse(class_ref, arguments.first) # Correct configuration passed elsif not class_ref. # This action does not use the new action format # Just passing the arguments to this method else Helper.log.fatal "------------------------------------------------------------------------------------".red Helper.log.fatal "If you've been an existing fastlane user, please check out the MigrationGuide to 1.0".yellow Helper.log.fatal "https://github.com/KrauseFx/fastlane/blob/master/docs/MigrationGuide.md".yellow Helper.log.fatal "------------------------------------------------------------------------------------".red raise "You have to pass the options for '#{method_sym}' in a different way. Please check out the current documentation on GitHub!".red end class_ref.run(arguments) end end rescue => ex collector.did_raise_error(method_sym) raise ex end else raise "Action '#{method_sym}' of class '#{class_name}' was found, but has no `run` method.".red end end |
Instance Attribute Details
#runner ⇒ Object
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
150 151 152 153 154 |
# File 'lib/fastlane/fast_file.rb', line 150 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
62 63 64 |
# File 'lib/fastlane/fast_file.rb', line 62 def after_all(&block) @runner.set_after_all(@current_platform, block) end |
#before_all(&block) ⇒ Object
Is executed before each test run
57 58 59 |
# File 'lib/fastlane/fast_file.rb', line 57 def before_all(&block) @runner.set_before_all(@current_platform, block) end |
#collector ⇒ Object
185 186 187 |
# File 'lib/fastlane/fast_file.rb', line 185 def collector @collector ||= ActionCollector.new end |
#desc(string) ⇒ Object
181 182 183 |
# File 'lib/fastlane/fast_file.rb', line 181 def desc(string) desc_collection << string end |
#desc_collection ⇒ Object
189 190 191 |
# File 'lib/fastlane/fast_file.rb', line 189 def desc_collection @desc_collection ||= [] end |
#did_finish ⇒ Object
Fastfile was finished executing
177 178 179 |
# File 'lib/fastlane/fast_file.rb', line 177 def did_finish collector.did_finish end |
#error(&block) ⇒ Object
Is executed if an error occured during fastlane execution
67 68 69 |
# File 'lib/fastlane/fast_file.rb', line 67 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?
141 142 143 144 145 146 147 148 |
# File 'lib/fastlane/fast_file.rb', line 141 def is_platform_block?(key) raise 'No key given'.red unless key return false if (self.runner.blocks[nil][key.to_sym] rescue false) return true if self.runner.blocks[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
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fastlane/fast_file.rb', line 34 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 desc = desc_collection.join("\n\n") platform = @current_platform @runner.set_block(lane_name, platform, block, desc) @desc_collection = nil # reset the collected description again for the next lane end |
#parse(data) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/fastlane/fast_file.rb', line 17 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
46 47 48 49 50 51 52 53 54 |
# File 'lib/fastlane/fast_file.rb', line 46 def platform(platform_name, &block) SupportedPlatforms.verify!platform_name @current_platform = platform_name block.call @current_platform = nil end |
#say(value) ⇒ Object
Speak out loud
132 133 134 135 136 137 138 |
# File 'lib/fastlane/fast_file.rb', line 132 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
157 158 159 160 161 |
# File 'lib/fastlane/fast_file.rb', line 157 def sh(command) Actions.execute_action(command) do Actions.sh_no_action(command) end end |
#verify_supported_os(name, class_ref) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/fastlane/fast_file.rb', line 163 def verify_supported_os(name, class_ref) if class_ref.respond_to?(:is_supported?) if Actions.lane_context[Actions::SharedValues::PLATFORM_NAME] # This value is filled in based on the executed platform block. Might be nil when lane is in root of Fastfile platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME] unless class_ref.is_supported?(platform) raise "Action '#{name}' doesn't support required operating system '#{platform}'.".red end end end end |