Class: Precheck::Rule

Inherits:
FastlaneCore::ConfigItem show all
Defined in:
precheck/lib/precheck/rule.rb

Direct Known Subclasses

TextRule, URLRule

Defined Under Namespace

Classes: RuleReturn

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, #env_names, #key, #optional, #sensitive, #short_option, #skip_type_validation, #verify_block

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FastlaneCore::ConfigItem

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

Constructor Details

#initialize(short_option: nil, verify_block: nil, is_string: nil, type: nil, conflicting_options: nil, conflict_block: nil, deprecated: nil, sensitive: nil, display_in_shell: nil) ⇒ Rule

Returns a new instance of Rule.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'precheck/lib/precheck/rule.rb', line 40

def initialize(short_option: nil,
               verify_block: nil,
               is_string: nil,
               type: nil,
               conflicting_options: nil,
               conflict_block: nil,
               deprecated: nil,
               sensitive: nil,
               display_in_shell: nil)

  super(key: self.class.key,
        env_name: self.class.env_name,
        description: self.class.description,
        short_option: short_option,
        default_value: self.class.default_value,
        verify_block: verify_block,
        is_string: is_string,
        type: type,
        optional: true,
        conflicting_options: conflicting_options,
        conflict_block: conflict_block,
        deprecated: deprecated,
        sensitive: sensitive,
        display_in_shell: display_in_shell)
end

Class Method Details

.default_valueObject



86
87
88
# File 'precheck/lib/precheck/rule.rb', line 86

def self.default_value
  CredentialsManager::AppfileConfig.try_fetch_value(self.key)
end

.descriptionObject



78
79
80
# File 'precheck/lib/precheck/rule.rb', line 78

def self.description
  not_implemented(__method__)
end

.env_nameObject



70
71
72
# File 'precheck/lib/precheck/rule.rb', line 70

def self.env_name
  not_implemented(__method__)
end

.friendly_nameObject



82
83
84
# File 'precheck/lib/precheck/rule.rb', line 82

def self.friendly_name
  not_implemented(__method__)
end

.keyObject



74
75
76
# File 'precheck/lib/precheck/rule.rb', line 74

def self.key
  not_implemented(__method__)
end

Instance Method Details

#check_item(item) ⇒ Object



118
119
120
121
122
123
124
125
# File 'precheck/lib/precheck/rule.rb', line 118

def check_item(item)
  # validate the item we have was properly matched to this rule: TextItem -> TextRule, URLItem -> URLRule
  return skip_item_not_meant_for_this_rule(item) unless handle_item?(item)
  return skip_item_not_meant_for_this_rule(item) unless item_field_supported?(item_name: item.item_name)

  # do the actual checking now
  return perform_check(item: item)
end

#customize_with_data(data: nil) ⇒ Object

some rules can be customized with extra data at runtime, see CustomTextRule as an example



104
105
106
# File 'precheck/lib/precheck/rule.rb', line 104

def customize_with_data(data: nil)
  not_implemented(__method__)
end

#friendly_nameObject



90
91
92
# File 'precheck/lib/precheck/rule.rb', line 90

def friendly_name
  return self.class.friendly_name
end

#handle_item?(item) ⇒ Boolean

each rule can define what type of ItemToCheck subclass they support override this method and return true or false

Returns:



134
135
136
# File 'precheck/lib/precheck/rule.rb', line 134

def handle_item?(item)
  not_implemented(__method__)
end

#inspectObject



94
95
96
# File 'precheck/lib/precheck/rule.rb', line 94

def inspect
  "#{self.class}(description: #{@description}, key: #{@key})"
end

#item_field_supported?(item_name: nil) ⇒ Boolean

Returns:



138
139
140
141
142
# File 'precheck/lib/precheck/rule.rb', line 138

def item_field_supported?(item_name: nil)
  return true if supported_fields_symbol_set.nil?
  return true if supported_fields_symbol_set.include?(item_name)
  return false
end

#needs_customization?Boolean

some rules can be customized with extra data at runtime, see CustomTextRule as an example

Returns:



99
100
101
# File 'precheck/lib/precheck/rule.rb', line 99

def needs_customization?
  return false
end

#perform_check(item: nil) ⇒ Object



144
145
146
147
148
149
150
151
152
153
# File 'precheck/lib/precheck/rule.rb', line 144

def perform_check(item: nil)
  if item.item_data.to_s == "" && item.is_optional
    # item is optional, and empty, so that's totally fine
    check_result = RuleReturn.new(validation_state: VALIDATION_STATES[:passed])
    return RuleCheckResult.new(item, check_result, self)
  end

  check_result = self.rule_block.call(item.item_data)
  return RuleCheckResult.new(item, check_result, self)
end

#rule_blockObject



114
115
116
# File 'precheck/lib/precheck/rule.rb', line 114

def rule_block
  not_implemented(__method__)
end

#skip_item_not_meant_for_this_rule(item) ⇒ Object



127
128
129
130
# File 'precheck/lib/precheck/rule.rb', line 127

def skip_item_not_meant_for_this_rule(item)
  # item isn't mean for this rule, which is fine, we can just keep passing it along
  return nil
end

#supported_fields_symbol_setObject

some rules only support specific fields, by default, all fields are supported unless restricted by providing a list of symbols matching the item_name as defined as the ItemToCheck is generated



110
111
112
# File 'precheck/lib/precheck/rule.rb', line 110

def supported_fields_symbol_set
  return nil
end

#to_sObject



66
67
68
# File 'precheck/lib/precheck/rule.rb', line 66

def to_s
  @key
end