Class: Precheck::Rule
Defined Under Namespace
Classes: RuleReturn
Instance Attribute Summary
#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
-
#check_item(item) ⇒ Object
-
#customize_with_data(data: nil) ⇒ Object
some rules can be customized with extra data at runtime, see CustomTextRule as an example.
-
#friendly_name ⇒ Object
-
#handle_item?(item) ⇒ Boolean
each rule can define what type of ItemToCheck subclass they support override this method and return true or false.
-
#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
constructor
-
#inspect ⇒ Object
-
#item_field_supported?(item_name: nil) ⇒ Boolean
-
#needs_customization? ⇒ Boolean
some rules can be customized with extra data at runtime, see CustomTextRule as an example.
-
#perform_check(item: nil) ⇒ Object
-
#rule_block ⇒ Object
-
#skip_item_not_meant_for_this_rule(item) ⇒ Object
-
#supported_fields_symbol_set ⇒ Object
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.
-
#to_s ⇒ Object
#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
.description ⇒ Object
78
79
80
|
# File 'precheck/lib/precheck/rule.rb', line 78
def self.description
not_implemented(__method__)
end
|
.env_name ⇒ Object
70
71
72
|
# File 'precheck/lib/precheck/rule.rb', line 70
def self.env_name
not_implemented(__method__)
end
|
.friendly_name ⇒ Object
82
83
84
|
# File 'precheck/lib/precheck/rule.rb', line 82
def self.friendly_name
not_implemented(__method__)
end
|
.key ⇒ Object
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)
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)
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_name ⇒ Object
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
134
135
136
|
# File 'precheck/lib/precheck/rule.rb', line 134
def handle_item?(item)
not_implemented(__method__)
end
|
#inspect ⇒ Object
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
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
99
100
101
|
# File 'precheck/lib/precheck/rule.rb', line 99
def needs_customization?
return false
end
|
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
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_block ⇒ Object
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)
return nil
end
|
#supported_fields_symbol_set ⇒ Object
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_s ⇒ Object
66
67
68
|
# File 'precheck/lib/precheck/rule.rb', line 66
def to_s
@key
end
|