Sha256: 79fe3bd239e9950c411a4a65654f3ce27f3f37481592aa8df64b68aeb4e3a05b

Contents?: true

Size: 1009 Bytes

Versions: 2

Compression:

Stored size: 1009 Bytes

Contents

require "rails"

module Scenic
  # @api private
  module SchemaDumper
    def tables(stream)
      super
      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
    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

2 entries across 2 versions & 1 rubygems

Version Path
scenic-1.1.1 lib/scenic/schema_dumper.rb
scenic-1.1.0 lib/scenic/schema_dumper.rb