class Pronto::RailsDataSchema
Public Instance Methods
run()
click to toggle source
# File lib/pronto/rails_data_schema.rb, line 5 def run return [] unless migration_patches.any? if schema_file_present? schema_patch = @patches.find { |patch| detect_schema_file(patch.new_file_full_path) } return generate_messages_for('data_schema.rb') unless changes_detected?(schema_patch) end [] end
Private Instance Methods
changes_detected?(patch)
click to toggle source
# File lib/pronto/rails_data_schema.rb, line 47 def changes_detected?(patch) patch && (patch.additions > 0 || patch.deletions > 0) end
detect_added_migration_file(patch)
click to toggle source
# File lib/pronto/rails_data_schema.rb, line 37 def detect_added_migration_file(patch) return unless patch.delta.added? /(.*)db[\\|\/]data[\\|\/](\d{14}_([_A-Za-z]+)\.rb)$/i =~ patch.delta.new_file[:path] end
detect_schema_file(path)
click to toggle source
# File lib/pronto/rails_data_schema.rb, line 43 def detect_schema_file(path) /db[\\|\/]data_schema.rb/i =~ path.to_s end
generate_messages_for(target)
click to toggle source
# File lib/pronto/rails_data_schema.rb, line 28 def generate_messages_for(target) migration_patches.map do |patch| first_line = patch.added_lines.first Message.new(patch.delta.new_file[:path], first_line, :warning, "Data migration file detected, but no changes in #{target}", nil, self.class) end end
migration_patches()
click to toggle source
# File lib/pronto/rails_data_schema.rb, line 22 def migration_patches return [] unless @patches @migration_patches ||= @patches .select { |patch| detect_added_migration_file(patch) } end
schema_file_present?()
click to toggle source
# File lib/pronto/rails_data_schema.rb, line 18 def schema_file_present? File.exist?('db/data_schema.rb') end