Created
October 7, 2020 06:28
-
-
Save felginep/3bb01c0d9a97110f6a8cf5c78157fd0a to your computer and use it in GitHub Desktop.
Create lanes with non optional parameters and raises an error if we try to access a missing value from the `option` hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### BEFORE ###### | |
lane :test do | |
build | |
end | |
lane :build do |options| | |
scheme = options[:scheme] | |
# ... | |
end | |
# => scheme is missing but execution continues (which can lead to problems later) | |
###### AFTER ###### | |
lane :test do | |
build | |
end | |
secure_lane :build do |options| | |
scheme = options[:scheme] | |
# ... | |
end | |
# => scheme is missing but we get the exception: "Can't find value for key :scheme in lane :build" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fastlane::FastFile # from https://github.com/fastlane/fastlane/blob/master/fastlane/lib/fastlane/fast_file.rb | |
# Hash that raises an error when we access a missing value | |
class RequiredOptions < Hash | |
def initialize(options, lane) | |
options.each { |key, value| self[key] = value } | |
@lane = lane | |
end | |
def [](key) | |
value = super(key) | |
UI.user_error!("Can't find value for key :#{key} in lane :#{@lane}") if value.nil? | |
value | |
end | |
end | |
def secure_lane(name, &block) | |
lane(name) do |options| | |
options = RequiredOptions.new(options, name) | |
block.call(options) | |
end | |
end | |
def secure_private_lane(name, &block) | |
private_lane(name) do |options| | |
options = RequiredOptions.new(options, name) | |
block.call(options) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment