Module: TheSchemaIs::Common

Extended by:
Memoist
Included in:
MissingColumn, Presence, UnknownColumn, WrongColumnDefinition, WrongTableName
Defined in:
lib/the_schema_is/cops.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(cls) ⇒ Object



30
31
32
33
34
35
# File 'lib/the_schema_is/cops.rb', line 30

def self.included(cls)
  cls.define_singleton_method(:badge) do
    RuboCop::Cop::Badge.for("TheSchemaIs::#{name.split('::').last}")
  end
  super
end

Instance Method Details

#external_dependency_checksumObject

We need this method to tell Rubocop that EVEN if app/models/user.rb haven’t changed, and .rubocop.yml haven’t changed, we STILL may need to rerun the cop if schema.rb have changed.



47
48
49
50
51
# File 'lib/the_schema_is/cops.rb', line 47

def external_dependency_checksum
  return unless schema_path

  Digest::SHA1.hexdigest(File.read(schema_path))
end

#on_class(node) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/the_schema_is/cops.rb', line 37

def on_class(node)
  @model = Cops::Parser.model(node,
                              base_classes: cop_config.fetch('BaseClass'),
                              table_prefix: cop_config['TablePrefix']) or return

  register_offense(node)
end