Sha256: 42e86c90fb2bb155976ac2e752285eeb4913b81db6aa896f9c7d9091aa9243c2

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

require "rails"

module Scenic
  # @api private
  module SchemaDumper
    def tables(stream)
      super
      views(stream)
    end

    def views(stream)
      if dumpable_views_in_database.any?
        stream.puts
      end

      dumpable_views_in_database.each do |view|
        stream.puts(view.to_schema)
        indexes(view.name, stream)
      end
    end

    private

    def dumpable_views_in_database
      @dumpable_views_in_database ||= Scenic.database.views.reject do |view|
        ignored?(view.name)
      end
    end

    unless ActiveRecord::SchemaDumper.private_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 then remove_prefix_and_suffix(table_name) == ignored
          when Regexp then 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

11 entries across 11 versions & 2 rubygems

Version Path
scenic-1.8.0 lib/scenic/schema_dumper.rb
scenic-1.7.0 lib/scenic/schema_dumper.rb
scenic-1.6.0 lib/scenic/schema_dumper.rb
scenic-1.5.5 lib/scenic/schema_dumper.rb
scenic-jets-1.5.5 lib/scenic/schema_dumper.rb
scenic-jets-1.5.4 lib/scenic/schema_dumper.rb
scenic-1.5.4 lib/scenic/schema_dumper.rb
scenic-1.5.3 lib/scenic/schema_dumper.rb
scenic-1.5.2 lib/scenic/schema_dumper.rb
scenic-1.5.1 lib/scenic/schema_dumper.rb
scenic-1.5.0 lib/scenic/schema_dumper.rb