Sha256: 4a6ee6b8876c2707d031b78ce86078d6f78576f7c18764d84690795295f385e3

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module WhoAmI
  class Comment
    def initialize(table_name:)
      @model_info = TableInfo.new(table_name)
    end

    def output
      output_header + output_schema + output_indices
    end

    private

    def output_header
      "# == Schema Info\n" \
      "#\n" \
      "# Table name: #{@model_info.table_name}\n" \
      "#\n"
    end

    def output_schema
      if @model_info.columns.none?
        return ""
      end

      tt = TextTable.new(join: "    ", prefix: "#   ")

      @model_info.columns.each do |column_info|
        tt.push([
          column_info.name,
          column_info.type,
          column_info.attributes.join(", "),
        ])
      end

      tt.to_s + "#\n"
    end

    def output_indices
      if @model_info.indices.none?
        return ""
      end

      tt = TextTable.new(join: "    ", prefix: "#   ")

      @model_info.indices.each do |index|
        tt.push([index.name, "(#{index.columns.join(", ")})"])
      end

      header =
        "# Indices:\n" \
        "#\n"

      header + tt.to_s + "#\n"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
who_am_i-0.0.6 lib/who_am_i/comment.rb
who_am_i-0.0.5 lib/who_am_i/comment.rb
who_am_i-0.0.4 lib/who_am_i/comment.rb
who_am_i-0.0.3 lib/who_am_i/comment.rb
who_am_i-0.0.2 lib/who_am_i/comment.rb
who_am_i-0.0.1 lib/who_am_i/comment.rb