module Headdesk::Check
Check
for a potential issue in an apk or ipa
:reek: ModuleInitialize
Attributes
apk[R]
ipa[R]
report[R]
status[R]
Public Class Methods
condition?(conditions, key)
click to toggle source
:reek: ManualDispatch
# 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()
click to toggle source
# File lib/headdesk/check.rb, line 13 def self.for_apk APK.all || [] end
for_ipa()
click to toggle source
# File lib/headdesk/check.rb, line 17 def self.for_ipa IPA.all || [] end
included(klass)
click to toggle source
# File lib/headdesk/check.rb, line 21 def self.included(klass) klass.extend(ClassMethods) end
new(bundle)
click to toggle source
:reek: DuplicateMethodCall and :reek:ManualDispatch
# 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
Public Instance Methods
after()
click to toggle source
# File lib/headdesk/check.rb, line 149 def after; end
before()
click to toggle source
# File lib/headdesk/check.rb, line 147 def before; end
check_control_flow(status_to_assign, conditions = nil)
click to toggle source
:reek: ManualDispatch and :reek:TooManyStatements and :reek:FeatureEnvy
# 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)
click to toggle source
# File lib/headdesk/check.rb, line 59 def describe(desc = nil) @last_desc = desc if desc @last_desc end
export(merge = {})
click to toggle source
# File lib/headdesk/check.rb, line 120 def export(merge = {}) @report[:export].merge! merge end
fail_check(conditions = {})
click to toggle source
# File lib/headdesk/check.rb, line 116 def fail_check(conditions = {}) check_control_flow(:fail, conditions) end
preconditions?()
click to toggle source
# File lib/headdesk/check.rb, line 124 def preconditions? true end
process()
click to toggle source
:reek: ManualDispatch
# File lib/headdesk/check.rb, line 139 def process return report unless respond_to?(:call) && preconditions? @status = :success report[:status] = run report end
run()
click to toggle source
# File lib/headdesk/check.rb, line 128 def run before catch(:halt_check) do call end after @status end
skip_check(conditions = {})
click to toggle source
# File lib/headdesk/check.rb, line 112 def skip_check(conditions = {}) check_control_flow(:skip, conditions) end