Sha256: 9d1bda3547fd0d1fa4c50e228ecf2c3e35c8d1e2ffacaed43fca90853f0b9770

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'scenic/definition'

module Scenic
  # Visualize database view dependencies for Scenic
  module Cascade
    # Finds view definitions
    module DefinitionFinder
      def self.included(klass)
        klass.extend(ClassMethods)
      end

      # Provides class methods to injected class
      module ClassMethods
        def find_definitions_of(view_name)
          go(view_name, 1)
        end

        def find_latest_definition_of(view_name)
          latest_definition = find_definitions_of(view_name).last
          unless latest_definition.nil?
            # @type var latest_definition: Scenic::Definition
            return latest_definition
          end

          raise ArgumentError, "View #{view_name} does not exist"
        end

        private

        def go(view_name, version)
          definition = Scenic::Definition.new(view_name, version)
          return [] unless File.exist?(definition.full_path)

          [definition, *go(view_name, version + 1)]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scenic-cascade-0.1.0 lib/scenic/cascade/definition_finder.rb