Class: Precheck::UnreachableURLRule

Inherits:
URLRule show all
Defined in:
precheck/lib/precheck/rules/unreachable_urls_rule.rb

Instance Attribute Summary

Attributes inherited from FastlaneCore::ConfigItem

#allow_shell_conversion, #code_gen_default_value, #code_gen_sensitive, #conflict_block, #conflicting_options, #default_value, #default_value_dynamic, #deprecated, #description, #display_in_shell, #env_name, #key, #optional, #sensitive, #short_option, #skip_type_validation, #verify_block

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from URLRule

#handle_item?

Methods inherited from Rule

#check_item, #customize_with_data, default_value, #friendly_name, #handle_item?, #initialize, #inspect, #item_field_supported?, #needs_customization?, #perform_check, #skip_item_not_meant_for_this_rule, #supported_fields_symbol_set, #to_s

Methods inherited from FastlaneCore::ConfigItem

#auto_convert_value, #data_type, #deprecated_description, #doc_default_value, #ensure_boolean_type_passes_validation, #ensure_generic_type_passes_validation, #help_default_value, #initialize, #is_string, #string?, #to_s, #update_code_gen_default_value_if_able!, #valid?, #verify!

Constructor Details

This class inherits a constructor from Precheck::Rule

Class Method Details

.descriptionObject



20
21
22
# File 'precheck/lib/precheck/rules/unreachable_urls_rule.rb', line 20

def self.description
  "unreachable URLs in app metadata"
end

.env_nameObject



12
13
14
# File 'precheck/lib/precheck/rules/unreachable_urls_rule.rb', line 12

def self.env_name
  "RULE_UNREACHABLE_URLS"
end

.friendly_nameObject



16
17
18
# File 'precheck/lib/precheck/rules/unreachable_urls_rule.rb', line 16

def self.friendly_name
  "No broken urls"
end

.keyObject



8
9
10
# File 'precheck/lib/precheck/rules/unreachable_urls_rule.rb', line 8

def self.key
  :unreachable_urls
end

Instance Method Details

#rule_blockObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'precheck/lib/precheck/rules/unreachable_urls_rule.rb', line 24

def rule_block
  return lambda { |url|
    url = url.to_s.strip
    return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: "empty url") if url.empty?

    begin
      uri = Addressable::URI.parse(url)
      uri.fragment = nil
      request = Faraday.new(uri.normalize.to_s) do |connection|
        connection.use(FaradayMiddleware::FollowRedirects)
        connection.adapter(:net_http)
      end
      return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: url) unless request.head.status == 200
    rescue StandardError => e
      UI.verbose("URL #{url} not reachable 😵: #{e.message}")
      # I can only return :fail here, but I also want to return #{url}
      return RuleReturn.new(validation_state: VALIDATION_STATES[:failed], failure_data: "unreachable: #{url}")
    end

    return RuleReturn.new(validation_state: VALIDATION_STATES[:passed])
  }
end