Sha256: 179aca8f573e0b443026b61feeff0cb4b72e4b8c85fb291830002a64398bd942

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

require "rails"

module Scenic
  module SchemaDumper
    extend ActiveSupport::Concern

    included { alias_method_chain :tables, :views }

    def tables_with_views(stream)
      tables_without_views(stream)
      views(stream)
    end

    def views(stream)
      views_in_database.select { |view| !ignored?(view.name) }.each do |view|
        stream.puts(view.to_schema)
      end
    end

    def views_in_database
      @views_in_database ||= Scenic.database.views.sort
    end

    private

    unless ActiveRecord::SchemaDumper.instance_methods(false).include?(:ignored?)
      # This method will be present in Rails 4.2.0 and can be removed then.
      def ignored?(table_name)
        ["schema_migrations", ignore_tables].flatten.any? do |ignored|
          case ignored
          when String; remove_prefix_and_suffix(table_name) == ignored
          when Regexp; remove_prefix_and_suffix(table_name) =~ ignored
          else
            raise StandardError, "ActiveRecord::SchemaDumper.ignore_tables accepts an array of String and / or Regexp values."
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scenic-0.3.0 lib/scenic/schema_dumper.rb
scenic-0.2.1 lib/scenic/schema_dumper.rb
scenic-0.2.0 lib/scenic/schema_dumper.rb