Sha256: 2e00b8eb1a9e6359659e3d50ba7ab65299525573426f4b6abbec933ab43d94fb

Contents?: true

Size: 1.17 KB

Versions: 9

Compression:

Stored size: 1.17 KB

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 = [:integer, :float, :boolean, :string, :text, :date, :time, :datetime, :binary]

      def interesting_nodes
        [:call]
      end

      def interesting_files
        SCHEMA_FILE
      end

      def initialize
        @model_attributes = Core::ModelAttributes.new
      end

      # check call node to remember the model attributes.
      def start_call(call_node)
        case call_node.message
        when :create_table
          @last_klazz = call_node.arguments[1].to_s.classify
        when *ATTRIBUTE_TYPES
          attribute_name = call_node.arguments[1].to_s
          @model_attributes.add_attribute(@last_klazz, attribute_name, call_node.message)
        else
          # nothing to do
        end
      end

      # assign @model_attributes to Prepares.model_attributes.
      def end_call(call_node)
        if :create_table == call_node.message
          Prepares.model_attributes = @model_attributes
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rails_best_practices-0.10.1 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-0.10.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-raydog153-0.9.1 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-0.9.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-0.8.2 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-0.8.1 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-0.8.0 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-0.7.5 lib/rails_best_practices/prepares/schema_prepare.rb
rails_best_practices-0.7.4 lib/rails_best_practices/prepares/schema_prepare.rb