Sha256: 7d2d0b755b8f2b9b7417554f11bc5b7ffebedcf011959f738e47c1d65d5cbb21

Contents?: true

Size: 978 Bytes

Versions: 10

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true

module RailsBestPractices
  module Prepares
    # Remember the model attributes.
    class SchemaPrepare < Core::Check
      interesting_nodes :command, :command_call
      interesting_files SCHEMA_FILE

      # all attribute types
      ATTRIBUTE_TYPES = %w[integer float boolean string text date time datetime binary].freeze

      def initialize
        @model_attributes = Prepares.model_attributes
      end

      add_callback :start_command do |node|
        if node.message.to_s == 'create_table'
          @last_klazz = node.arguments.all.first.to_s.classify
        end
      end

      # check command_call node to remember the model attributes.
      add_callback :start_command_call do |node|
        if ATTRIBUTE_TYPES.include? node.message.to_s
          attribute_name = node.arguments.all.first.to_s
          @model_attributes.add_attribute(@last_klazz, attribute_name, node.message.to_s)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.23.1 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.23.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.22.1 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.22.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.21.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.20.1 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.20.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.19.5 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.19.4 lib/rails_best_practices/prepares/schema_prepare.rb