Sha256: fc428b5b731d419d4dfdb86c07b5439a81c5c3a659f9e51c628efe18e3449b1b

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Manifold
  module API
    # Encapsulates a single manifold.
    class Workspace
      attr_reader :name, :project, :template_path

      DEFAULT_TEMPLATE_PATH = Pathname.pwd.join(
        "lib", "manifold", "templates", "workspace_template.yml"
      )

      def initialize(name, project:, template_path: DEFAULT_TEMPLATE_PATH)
        self.name = name
        self.project = project
        self.template_path = template_path
      end

      def add
        [tables_directory, routines_directory].each(&:mkpath)
        FileUtils.cp(template_path, manifold_path)
      end

      def tables_directory
        project.workspaces_directory.join(name, "tables")
      end

      def routines_directory
        project.workspaces_directory.join(name, "routines")
      end

      def manifold_file
        return nil unless manifold_exists?

        File.new(manifold_path)
      end

      def manifold_exists?
        manifold_path.file?
      end

      def manifold_path
        project.workspaces_directory.join(name, "manifold.yml")
      end

      private

      attr_writer :name, :project, :template_path
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
manifold-cli-0.0.7 lib/manifold/project/workspace.rb