Class: Terracop::Cop::Base
- Inherits:
-
Object
- Object
- Terracop::Cop::Base
- Defined in:
- lib/terracop/cop/base.rb
Overview
Base class for all cops.
Direct Known Subclasses
Aws::BadPasswordPolicy, Aws::DescribeSecurityGroupRules, Aws::EnsurePropagatedTags, Aws::EnsureTags, Aws::FaultIntolerant, Aws::IamInlinePolicy, Aws::IamPolicyAttachment, Aws::SecurityGroupRuleCop, Style::DashInResourceName, Style::ResourceTypeInName, Style::SnakeCase
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#index ⇒ Object
Returns the value of attribute index.
-
#name ⇒ Object
Returns the value of attribute name.
-
#offenses ⇒ Object
readonly
Returns the value of attribute offenses.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #check ⇒ Object
- #human_name ⇒ Object
-
#initialize(type, name, index, attributes) ⇒ Base
constructor
A new instance of Base.
- #offense(message, severity = :convention) ⇒ Object
Constructor Details
#initialize(type, name, index, attributes) ⇒ Base
Returns a new instance of Base.
75 76 77 78 79 80 81 |
# File 'lib/terracop/cop/base.rb', line 75 def initialize(type, name, index, attributes) self.type = type self.name = name self.index = index self.attributes = attributes @offenses = [] end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
22 23 24 |
# File 'lib/terracop/cop/base.rb', line 22 def attributes @attributes end |
#index ⇒ Object
Returns the value of attribute index.
22 23 24 |
# File 'lib/terracop/cop/base.rb', line 22 def index @index end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/terracop/cop/base.rb', line 22 def name @name end |
#offenses ⇒ Object (readonly)
Returns the value of attribute offenses.
102 103 104 |
# File 'lib/terracop/cop/base.rb', line 102 def offenses @offenses end |
#type ⇒ Object
Returns the value of attribute type.
22 23 24 |
# File 'lib/terracop/cop/base.rb', line 22 def type @type end |
Class Method Details
.config ⇒ Object
37 38 39 40 41 |
# File 'lib/terracop/cop/base.rb', line 37 def config config = Terracop.config[cop_name] || {} config['Enabled'] = config['Enabled'].nil? ? true : config['Enabled'] config end |
.cop_name ⇒ Object
33 34 35 |
# File 'lib/terracop/cop/base.rb', line 33 def cop_name name.gsub(/^Terracop::Cop::/, '').gsub('::', '/') end |
.run(type, name, index, attributes) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/terracop/cop/base.rb', line 25 def run(type, name, index, attributes) return unless applies_to?(type, name) cop = new(type, name, index, attributes) cop.check cop.offenses end |
Instance Method Details
#check ⇒ Object
87 88 89 90 |
# File 'lib/terracop/cop/base.rb', line 87 def check = "#{self.class.name} does not implement the #check method" raise NotImplementedError, end |
#human_name ⇒ Object
83 84 85 |
# File 'lib/terracop/cop/base.rb', line 83 def human_name index ? "#{name}[#{index}]" : name end |
#offense(message, severity = :convention) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/terracop/cop/base.rb', line 92 def offense(, severity = :convention) @offenses << { cop_name: self.class.cop_name, severity: severity, type: type, name: human_name, message: } end |