Module: RuboCop::SketchUp::SketchUpTargetRange

Included in:
Cop::SketchupBugs::MaterialName, Cop::SketchupBugs::RenderMode, Cop::SketchupBugs::UniformScaling
Defined in:
lib/rubocop/sketchup/sketchup_target_range.rb

Overview

Mix-in module for Cops that are valid only for a given SketchUp version range. This mix-in uses the configured target SketchUp version to determine if it’s relevant.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

module ClassMethods



34
35
36
# File 'lib/rubocop/sketchup/sketchup_target_range.rb', line 34

def self.included(mod)
  mod.extend(ClassMethods)
end

Instance Method Details

#sketchup_target_max_versionObject



42
43
44
# File 'lib/rubocop/sketchup/sketchup_target_range.rb', line 42

def sketchup_target_max_version
  self.class.sketchup_target_max_version
end

#sketchup_target_min_versionObject



38
39
40
# File 'lib/rubocop/sketchup/sketchup_target_range.rb', line 38

def sketchup_target_min_version
  self.class.sketchup_target_min_version
end

#valid_for_target_sketchup_version?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rubocop/sketchup/sketchup_target_range.rb', line 46

def valid_for_target_sketchup_version?
  # If no target version is configured, ignore this check.
  return true unless sketchup_target_version?

  # If no version is set - then it's valid for all known versions.
  unless sketchup_target_min_version || sketchup_target_max_version
    return true
  end

  # If there is a finite version range, check if the target SketchUp
  # version is withing that.
  if sketchup_target_min_version && sketchup_target_max_version
    range = (sketchup_target_min_version..sketchup_target_max_version)
    return range.include?(sketchup_target_version)
  end

  if sketchup_target_min_version
    return sketchup_target_version >= sketchup_target_min_version
  end

  if sketchup_target_max_version
    return sketchup_target_version <= sketchup_target_max_version
  end

  raise 'bug!' # Should not end up here.
end