-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streamline Generate #15
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3d38ae1
Rename project to api to reflect app hierarchy
claytongentry 9840899
Factor out BigQueryService
claytongentry 71435c1
Break out vectors helpers
claytongentry 7ac49d6
Set up project.generate
claytongentry 95c7c13
Add a project.generate test
claytongentry 2520074
fix bugs
claytongentry 344cd94
some light segmentation
claytongentry c156354
OOP'ify workspace generation
claytongentry 8fcf9a8
tighten schema assertions
claytongentry 215cbaa
Set 3.1 minimum and enable new cops
claytongentry fbd896b
not sure why these got missed
claytongentry fdc2003
Fix name
claytongentry 9ebd87d
Slash attr_writers
claytongentry afbdd7f
attr_reader the :logger
claytongentry f1b027d
filter_map instead of shovel
claytongentry 95d26fe
Raise on no configuration
claytongentry 5521736
Capture invalid YAML
claytongentry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Manifold | ||
module API | ||
# Projects API | ||
class Project | ||
attr_reader :name, :logger, :directory | ||
|
||
def initialize(name, logger: Logger.new($stdout), directory: Pathname.pwd.join(name)) | ||
@name = name | ||
@logger = logger | ||
@directory = Pathname(directory) | ||
end | ||
|
||
def self.create(name, directory: Pathname.pwd.join(name)) | ||
new(name, directory:).tap do |project| | ||
[project.workspaces_directory, project.vectors_directory].each(&:mkpath) | ||
end | ||
end | ||
|
||
def workspaces | ||
@workspaces ||= workspace_directories.map { |dir| Workspace.from_directory(dir, logger:) } | ||
end | ||
|
||
def generate | ||
workspaces.each(&:generate) | ||
end | ||
|
||
def workspaces_directory | ||
directory.join("workspaces") | ||
end | ||
|
||
def vectors_directory | ||
directory.join("vectors") | ||
end | ||
|
||
private | ||
|
||
def workspace_directories | ||
workspaces_directory.children.select(&:directory?) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# frozen_string_literal: true | ||
|
||
module Manifold | ||
module API | ||
# Encapsulates a single manifold. | ||
class Workspace | ||
attr_reader :name, :template_path, :logger | ||
|
||
DEFAULT_TEMPLATE_PATH = File.expand_path( | ||
"../templates/workspace_template.yml", __dir__ | ||
).freeze | ||
|
||
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 | ||
|
||
def self.from_directory(directory, logger: Logger.new($stdout)) | ||
new(directory.basename.to_s, logger:) | ||
end | ||
|
||
def add | ||
[tables_directory, routines_directory].each(&:mkpath) | ||
FileUtils.cp(template_path, manifold_path) | ||
end | ||
|
||
def generate | ||
return unless manifold_exists? && any_vectors? | ||
|
||
generate_dimensions | ||
logger.info("Generated BigQuery dimensions table schema for workspace '#{name}'.") | ||
end | ||
|
||
def tables_directory | ||
directory.join("tables") | ||
end | ||
|
||
def routines_directory | ||
directory.join("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 | ||
directory.join("manifold.yml") | ||
end | ||
|
||
private | ||
|
||
def directory | ||
Pathname.pwd.join("workspaces", name) | ||
end | ||
|
||
def manifold_yaml | ||
@manifold_yaml ||= YAML.safe_load_file(manifold_path) | ||
end | ||
|
||
def generate_dimensions | ||
dimensions_path.write(dimensions_schema_json.concat("\n")) | ||
end | ||
|
||
def dimensions_schema | ||
[ | ||
{ "type" => "STRING", "name" => "id", "mode" => "REQUIRED" }, | ||
{ "type" => "RECORD", "name" => "dimensions", "mode" => "REQUIRED", | ||
"fields" => dimensions_fields } | ||
] | ||
end | ||
|
||
def dimensions_fields | ||
vectors.filter_map do |vector| | ||
logger.info("Loading vector schema for '#{vector}'.") | ||
@vector_service.load_vector_schema(vector) | ||
end | ||
end | ||
|
||
def dimensions_schema_json | ||
JSON.pretty_generate(dimensions_schema) | ||
end | ||
|
||
def dimensions_path | ||
tables_directory.join("dimensions.json") | ||
end | ||
|
||
def any_vectors? | ||
!(vectors.nil? || vectors.empty?) | ||
end | ||
|
||
def vectors | ||
manifold_yaml["vectors"] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A non-existent or non-file file are not the only possible failure modes here. It could also be an invalid YAML file. Consider replacing this with rescues for
Errno::ENOENT
,Errno::EISDIR
, andPsych::Exception
.