Module: Headdesk::Check
- Defined in:
- lib/headdesk/check.rb
Overview
Check for a potential issue in an apk or ipa
:reek:ModuleInitialize
Defined Under Namespace
Modules: APK, ClassMethods, IPA
Instance Attribute Summary collapse
-
#apk ⇒ Object
readonly
Returns the value of attribute apk.
-
#ipa ⇒ Object
readonly
Returns the value of attribute ipa.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.condition?(conditions, key) ⇒ Boolean
:reek:ManualDispatch.
- .for_apk ⇒ Object
- .for_ipa ⇒ Object
- .included(klass) ⇒ Object
Instance Method Summary collapse
- #after ⇒ Object
- #before ⇒ Object
-
#check_control_flow(status_to_assign, conditions = nil) ⇒ Object
:reek:ManualDispatch and :reek:TooManyStatements and :reek:FeatureEnvy.
- #describe(desc = nil) ⇒ Object
- #export(merge = {}) ⇒ Object
- #fail_check(conditions = {}) ⇒ Object
-
#initialize(bundle) ⇒ Object
:reek:DuplicateMethodCall and :reek:ManualDispatch.
- #preconditions? ⇒ Boolean
-
#process ⇒ Object
:reek:ManualDispatch.
- #run ⇒ Object
- #skip_check(conditions = {}) ⇒ Object
Instance Attribute Details
#apk ⇒ Object (readonly)
Returns the value of attribute apk.
11 12 13 |
# File 'lib/headdesk/check.rb', line 11 def apk @apk end |
#ipa ⇒ Object (readonly)
Returns the value of attribute ipa.
11 12 13 |
# File 'lib/headdesk/check.rb', line 11 def ipa @ipa end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
11 12 13 |
# File 'lib/headdesk/check.rb', line 11 def report @report end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/headdesk/check.rb', line 11 def status @status end |
Class Method Details
.condition?(conditions, key) ⇒ Boolean
:reek:ManualDispatch
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/headdesk/check.rb', line 182 def self.condition?(conditions, key) condition = conditions.fetch(key, nil) if !condition false elsif condition.respond_to? :call condition.call elsif %w[true false].include?(condition.to_s) condition.to_s == 'true' else raise ArgumentError, 'fail_check and skip_check only accept truthy, falsy, nil, or Proc arguments' end end |
.for_apk ⇒ Object
13 14 15 |
# File 'lib/headdesk/check.rb', line 13 def self.for_apk APK.all || [] end |
.for_ipa ⇒ Object
17 18 19 |
# File 'lib/headdesk/check.rb', line 17 def self.for_ipa IPA.all || [] end |
.included(klass) ⇒ Object
21 22 23 |
# File 'lib/headdesk/check.rb', line 21 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#after ⇒ Object
149 |
# File 'lib/headdesk/check.rb', line 149 def after; end |
#before ⇒ Object
147 |
# File 'lib/headdesk/check.rb', line 147 def before; end |
#check_control_flow(status_to_assign, conditions = nil) ⇒ Object
:reek:ManualDispatch and :reek:TooManyStatements and :reek:FeatureEnvy
65 66 67 68 69 70 71 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 |
# File 'lib/headdesk/check.rb', line 65 def check_control_flow(status_to_assign, conditions = nil) pass = !conditions || conditions.empty? raise ArgumentError, 'Do not specify both if: and unless:' if conditions.key?(:if) && conditions.key?(:unless) pass = Check.condition?(conditions, :if) if conditions.key? :if pass = !Check.condition?(conditions, :unless) if conditions.key? :unless skip = false raise ArgumentError, 'Do not specify both skip_if: and skip_unless:' if conditions.key?(:skip_if) && conditions.key?(:skip_unless) skip = Check.condition?(conditions, :skip_if) if conditions.key? :skip_if skip = !Check.condition?(conditions, :skip_unless) if conditions.key? :skip_unless # TODO: greater_than, less_than, equals # rubocop:disable RescueStandardError # Try and get an auto-description default_description = describe.to_s description = begin if conditions[:unless].respond_to?(:call) descriptionator = Headdesk::Descriptionator.new(:unless) desc = descriptionator.instance_exec(&conditions[:unless]) desc.is_a?(String) ? desc : default_description elsif conditions[:if].respond_to?(:call) descriptionator = Headdesk::Descriptionator.new(:if) desc = descriptionator.instance_exec(&conditions[:if]) desc.is_a?(String) ? desc : default_description else default_description end rescue default_description end # rubocop:enable RescueStandardError @status = status_to_assign if pass && !skip @report[:steps] << { description: description, status: skip ? :skip : @status } return unless pass throw :halt_check end |
#describe(desc = nil) ⇒ Object
59 60 61 62 |
# File 'lib/headdesk/check.rb', line 59 def describe(desc = nil) @last_desc = desc if desc @last_desc end |
#export(merge = {}) ⇒ Object
120 121 122 |
# File 'lib/headdesk/check.rb', line 120 def export(merge = {}) @report[:export].merge! merge end |
#fail_check(conditions = {}) ⇒ Object
116 117 118 |
# File 'lib/headdesk/check.rb', line 116 def fail_check(conditions = {}) check_control_flow(:fail, conditions) end |
#initialize(bundle) ⇒ Object
:reek:DuplicateMethodCall and :reek:ManualDispatch
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/headdesk/check.rb', line 45 def initialize(bundle) @apk = bundle @ipa = bundle @status = :skip @report = { description: self.class.describe, steps: [], export: {}, status: @status } @report[:name] = self.class.check_name if self.class.respond_to?(:check_name) @report[:doc] = "https://github.com/GoCarrot/headdesk/blob/v#{Headdesk::VERSION}/docs/#{self.class.doc}" if self.class.respond_to?(:check_name) end |
#preconditions? ⇒ Boolean
124 125 126 |
# File 'lib/headdesk/check.rb', line 124 def preconditions? true end |
#process ⇒ Object
:reek:ManualDispatch
139 140 141 142 143 144 145 |
# File 'lib/headdesk/check.rb', line 139 def process return report unless respond_to?(:call) && preconditions? @status = :success report[:status] = run report end |
#run ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/headdesk/check.rb', line 128 def run before catch(:halt_check) do call end after @status end |
#skip_check(conditions = {}) ⇒ Object
112 113 114 |
# File 'lib/headdesk/check.rb', line 112 def skip_check(conditions = {}) check_control_flow(:skip, conditions) end |