Sha256: 3aeb84a6aa2ce0d7b7aa0cfa53abea394421e3b0398a3510e6ce6c39a35185c1

Contents?: true

Size: 565 Bytes

Versions: 3

Compression:

Stored size: 565 Bytes

Contents

module Scenic
  class Definition
    def initialize(name, version)
      @name = name
      @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

    def filename
      "#{@name}_v#{version}.sql"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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