Sha256: 4828ffc2e85c1b6a9e11450d09a70f685b9353c56c3731f2554844756f498004

Contents?: true

Size: 640 Bytes

Versions: 2

Compression:

Stored size: 640 Bytes

Contents

module Scenic
  # @api private
  class Definition
    def initialize(name, version)
      @name = name.to_s
      @version = version.to_i
    end

    def to_sql
      File.read(full_path).tap do |content|
        if content.empty?
          raise "Define view query in #{path} before migrating."
        end
      end
    end

    def full_path
      Rails.root.join(path)
    end

    def path
      File.join("db", "views", filename)
    end

    def version
      @version.to_s.rjust(2, "0")
    end

    private

    attr_reader :name

    def filename
      "#{UnaffixedName.for(name).tr('.', '_')}_v#{version}.sql"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scenic-1.7.0 lib/scenic/definition.rb
scenic-1.6.0 lib/scenic/definition.rb