lib/annotator/attributes.rb
# Update attribudes array to the current database state
Update attribudes array to the current database state
Update attribudes array to the current database state
def update!
      @model.columns.each do |column|
        if row = @attrs.find {|x| x[:name] == column.name}
          if row[:type] != type_str(column)
            puts "  M #{@model}##{column.name} [#{row[:type]} -> #{type_str(column)}]"
            row[:type] = type_str(column)
          elsif row[:desc] == InitialDescription::DEFAULT_DESCRIPTION
            new_desc = InitialDescription.for(@model, column.name)
            if row[:desc] != new_desc
              puts "  M #{@model}##{column.name} description updated"
              row[:desc] = new_desc
            end
          end
        else
          puts "  A #{@model}##{column.name} [#{type_str(column)}]"
          @attrs << {
            :name => column.name,
            :type => type_str(column),
            :desc => InitialDescription.for(@model, column.name)
          }
        end
      end
      orphans = @attrs.map{|x| x[:name]} - @model.columns.map(&:name)
      unless orphans.empty?
        orphans.each do |orphan|
          puts "  D #{@model}##{orphan}"
          @attrs = @attrs.select {|x| x[:name] != orphan}
        end
      end
      @attrs
    end
def update! @model . columns . each do | column | if row = @attrs . find { | x | x [ :name ] == column . name } if row [ :type ] != type_str ( column ) puts "  M #{@model}##{column.name} [#{row[:type]} -> #{type_str(column)}]" row [ :type ] = type_str ( column ) elsif row [ :desc ] == InitialDescription :: DEFAULT_DESCRIPTION new_desc = InitialDescription . for ( @model , column . name ) if row [ :desc ] != new_desc puts "  M #{@model}##{column.name} description updated" row [ :desc ] = new_desc end end else puts "  A #{@model}##{column.name} [#{type_str(column)}]" @attrs << { :name => column . name , :type => type_str ( column ) , :desc => InitialDescription . for ( @model , column . name ) } end end orphans = @attrs . map { | x | x [ :name ] } - @model . columns . map ( & :name ) unless orphans . empty? orphans . each do | orphan | puts "  D #{@model}##{orphan}" @attrs = @attrs . select { | x | x [ :name ] != orphan } end end @attrs end
Update attribudes array to the current database state
Update attribudes array to the current database state
# find columns that no more exist in db