Class: RailsBestPractices::Prepares::SchemaPrepare

Inherits:
Core::Check
  • Object
show all
Defined in:
lib/rails_best_practices/prepares/schema_prepare.rb

Overview

Remember the model attributes.

Constant Summary collapse

ATTRIBUTE_TYPES =

all attribute types

[:integer, :float, :boolean, :string, :text, :date, :time, :datetime, :binary]

Constants inherited from Core::Check

Core::Check::CONTROLLER_FILES, Core::Check::HELPER_FILES, Core::Check::MAILER_FILES, Core::Check::MIGRATION_FILES, Core::Check::MODEL_FILES, Core::Check::NODE_TYPES, Core::Check::PARTIAL_VIEW_FILES, Core::Check::ROUTE_FILE, Core::Check::SCHEMA_FILE, Core::Check::VIEW_FILES

Instance Attribute Summary

Attributes inherited from Core::Check

#errors

Instance Method Summary collapse

Methods inherited from Core::Check

#add_error, #method_missing, #node_end, #node_start, #url

Constructor Details

#initializeSchemaPrepare

Returns a new instance of SchemaPrepare.



19
20
21
# File 'lib/rails_best_practices/prepares/schema_prepare.rb', line 19

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsBestPractices::Core::Check

Instance Method Details

#end_call(call_node) ⇒ Object

assign @model_attributes to Prepares.model_attributes.



37
38
39
40
41
# File 'lib/rails_best_practices/prepares/schema_prepare.rb', line 37

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

#interesting_filesObject



15
16
17
# File 'lib/rails_best_practices/prepares/schema_prepare.rb', line 15

def interesting_files
  SCHEMA_FILE
end

#interesting_nodesObject



11
12
13
# File 'lib/rails_best_practices/prepares/schema_prepare.rb', line 11

def interesting_nodes
  [:call]
end

#start_call(call_node) ⇒ Object

check call node to remember the model attributes.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_best_practices/prepares/schema_prepare.rb', line 24

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