Sha256: 7f16358cb1ec4e73838cd49f3fda6602e15746ef965bee14ac7511cd8e500ab3

Contents?: true

Size: 1014 Bytes

Versions: 5

Compression:

Stored size: 1014 Bytes

Contents

# encoding: utf-8
require 'rails_best_practices/core/check'

module RailsBestPractices
  module Prepares
    # Remember the model attributes.
    class SchemaPrepare < Core::Check
      # all attribute types
      ATTRIBUTE_TYPES = %w(integer float boolean string text date time datetime binary)

      def interesting_nodes
        [:command, :command_call]
      end

      def interesting_files
        SCHEMA_FILE
      end

      def initialize
        @model_attributes = Prepares.model_attributes
      end

      def start_command(node)
        if "create_table" == node.message.to_s
          @last_klazz = node.arguments.all[0].to_s.classify
        end
      end

      # check command_call node to remember the model attributes.
      def start_command_call(node)
        if ATTRIBUTE_TYPES.include? node.message.to_s
          attribute_name = node.arguments.all[0].to_s
          @model_attributes.add_attribute(@last_klazz, attribute_name, node.message.to_s)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_best_practices-1.3.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.2.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.1.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.0.1 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-1.0.0 lib/rails_best_practices/prepares/schema_prepare.rb