Class: Manifold::API::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/manifold/api/workspace.rb

Overview

Encapsulates a single manifold.

Constant Summary collapse

DEFAULT_TEMPLATE_PATH =
File.expand_path(
  "../templates/workspace_template.yml", __dir__
).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, template_path: DEFAULT_TEMPLATE_PATH, logger: Logger.new($stdout)) ⇒ Workspace

Returns a new instance of Workspace.



13
14
15
16
17
18
# File 'lib/manifold/api/workspace.rb', line 13

def initialize(name, template_path: DEFAULT_TEMPLATE_PATH, logger: Logger.new($stdout))
  @name = name
  @template_path = template_path
  @logger = logger
  @vector_service = Services::VectorService.new(logger)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/manifold/api/workspace.rb', line 7

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/manifold/api/workspace.rb', line 7

def name
  @name
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



7
8
9
# File 'lib/manifold/api/workspace.rb', line 7

def template_path
  @template_path
end

Class Method Details

.from_directory(directory, logger: Logger.new($stdout)) ⇒ Object



20
21
22
# File 'lib/manifold/api/workspace.rb', line 20

def self.from_directory(directory, logger: Logger.new($stdout))
  new(directory.basename.to_s, logger:)
end

Instance Method Details

#addObject



24
25
26
27
# File 'lib/manifold/api/workspace.rb', line 24

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

#generateObject



29
30
31
32
33
34
# File 'lib/manifold/api/workspace.rb', line 29

def generate
  return unless manifold_exists? && any_vectors?

  generate_dimensions
  logger.info("Generated BigQuery dimensions table schema for workspace '#{name}'.")
end

#manifold_exists?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/manifold/api/workspace.rb', line 50

def manifold_exists?
  manifold_path.file?
end

#manifold_fileObject



44
45
46
47
48
# File 'lib/manifold/api/workspace.rb', line 44

def manifold_file
  return nil unless manifold_exists?

  File.new(manifold_path)
end

#manifold_pathObject



54
55
56
# File 'lib/manifold/api/workspace.rb', line 54

def manifold_path
  directory.join("manifold.yml")
end

#routines_directoryObject



40
41
42
# File 'lib/manifold/api/workspace.rb', line 40

def routines_directory
  directory.join("routines")
end

#tables_directoryObject



36
37
38
# File 'lib/manifold/api/workspace.rb', line 36

def tables_directory
  directory.join("tables")
end