-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Entities * turn off rules * Rename to vectors and improve cli interface * fix vector writes * nest dimensions * update readme * add usage * snip extra docs * more bdd * logger spy * Generate rubocop todo * split tests * load yaml * more yaml parsing * clean up cops * rm empty todo * snip * squash test log output * absolute * more absolute * more absolute * more absolute * improve test legibility * Respect example length rule * Respect nesting rule * enforce docs * absolute * dry * api extraction * vector extraction * remove redundant FakeFS * cleaner * more assertion singularization * snip * further API extrapolation * Add spec persistence * pass tests again * snip * 3.0 is past EOL * fix coverage * refactor CLI spec * remove unnecessary context * more review feedback * more simplification * more reduction * safe load * one more * no need to manually activate / deactivate fakefs * Add more coverage to with-directory project specs * force pathname * more pathname * rename to fields * a million pathnames * use pathname methods * path not a file * improve test log * Implement Project.create as a class method * shorter line * pathname .freeze * turn back on * improve memoized helpers * Pass rubocops * delete unused * vectors do not create routines or tables directories * no todos * tighten * tighten * snip * abstract ugly template setup * nicen * read and write * more comments * bump version --------- Co-authored-by: tyler <tyler@tyler.love>
- Loading branch information
1 parent
8b636f0
commit b257a5d
Showing
26 changed files
with
617 additions
and
192 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/spec/examples.txt | ||
/tmp/ | ||
*.gem | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
inherit_from: .rubocop_todo.yml | ||
|
||
require: rubocop-rspec | ||
|
||
AllCops: | ||
|
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,7 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2024-11-09 13:21:19 UTC using RuboCop version 1.68.0. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. |
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
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Manifolds | ||
# API for interacting with project folders and file structures. | ||
module API | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require "thor" | ||
require "fileutils" | ||
require "logger" | ||
|
||
require_relative "services/big_query_service" | ||
|
||
module Manifolds | ||
# CLI provides command line interface functionality | ||
# for creating and managing umbrella projects for data management. | ||
class CLI < Thor | ||
attr_accessor :logger, :bq_service | ||
|
||
def initialize(*args, logger: Logger.new($stdout)) | ||
super(*args) | ||
@logger = logger | ||
@logger.level = Logger::INFO | ||
|
||
@bq_service = Services::BigQueryService.new(@logger) | ||
self.logger = logger | ||
logger.level = Logger::INFO | ||
|
||
self.bq_service = Services::BigQueryService.new(logger) | ||
end | ||
|
||
desc "init NAME", "Generate a new umbrella project for data management" | ||
def init(name) | ||
directory_path = "./#{name}/projects" | ||
FileUtils.mkdir_p(directory_path) | ||
@logger.info "Created umbrella project '#{name}' with a projects directory." | ||
Manifolds::API::Project.create(name) | ||
logger.info "Created umbrella project '#{name}' with projects and vectors directories." | ||
end | ||
|
||
desc "add PROJECT_NAME", "Add a new project within the current umbrella project" | ||
def add(project_name) | ||
project_path = "./projects/#{project_name}" | ||
unless Dir.exist?("./projects") | ||
@logger.error("Not inside a Manifolds umbrella project.") | ||
return | ||
desc "vectors SUBCOMMAND ...ARGS", "Manage vectors" | ||
subcommand "vectors", Class.new(Thor) { | ||
namespace :vectors | ||
|
||
attr_accessor :logger | ||
|
||
def initialize(*args, logger: Logger.new($stdout)) | ||
super(*args) | ||
self.logger = logger | ||
end | ||
|
||
FileUtils.mkdir_p("#{project_path}/tables") | ||
FileUtils.mkdir_p("#{project_path}/routines") | ||
copy_config_template(project_path) | ||
@logger.info "Added project '#{project_name}' with tables and routines directories." | ||
desc "add VECTOR_NAME", "Add a new vector configuration" | ||
def add(name, project: API::Project.new(File.basename(Dir.getwd))) | ||
vector = API::Vector.new(name, project: project) | ||
vector.add | ||
logger.info "Created vector configuration for '#{name}'." | ||
end | ||
} | ||
|
||
desc "add WORKSPACE_NAME", "Add a new workspace to a project" | ||
def add(name, project: API::Project.new(File.basename(Dir.getwd))) | ||
workspace = API::Workspace.new(name, project: project) | ||
workspace.add | ||
logger.info "Added workspace '#{name}' with tables and routines directories." | ||
end | ||
|
||
desc "generate PROJECT_NAME SERVICE", "Generate services for a project" | ||
def generate(project_name, service) | ||
case service | ||
when "bq" | ||
@bq_service.generate_dimensions_schema(project_name) | ||
bq_service.generate_dimensions_schema(project_name) | ||
else | ||
@logger.error("Unsupported service: #{service}") | ||
logger.error("Unsupported service: #{service}") | ||
end | ||
end | ||
|
||
private | ||
|
||
def copy_config_template(project_path) | ||
template_path = File.join(File.dirname(__FILE__), "templates", "config_template.yml") | ||
FileUtils.cp(template_path, "#{project_path}/manifold.yml") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Manifolds | ||
module API | ||
# Projects API | ||
class Project | ||
attr_reader :name, :directory | ||
|
||
def initialize(name, directory: Pathname.pwd.join(name)) | ||
self.name = name | ||
self.directory = Pathname(directory) | ||
end | ||
|
||
def self.create(name, directory: Pathname.pwd.join(name)) | ||
new(name, directory: directory).tap do |project| | ||
[project.workspaces_directory, project.vectors_directory].each(&:mkpath) | ||
end | ||
end | ||
|
||
def workspaces_directory | ||
directory.join("workspaces") | ||
end | ||
|
||
def vectors_directory | ||
directory.join("vectors") | ||
end | ||
|
||
private | ||
|
||
attr_writer :name, :directory | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module Manifolds | ||
module API | ||
# Describes the entities for whom metrics are calculated. | ||
class Vector | ||
attr_reader :name, :project, :template_path | ||
|
||
DEFAULT_TEMPLATE_PATH = Pathname.pwd.join( | ||
"lib", "manifolds", "templates", "vector_template.yml" | ||
).freeze | ||
|
||
def initialize(name, project:, template_path: DEFAULT_TEMPLATE_PATH) | ||
self.name = name | ||
self.project = project | ||
self.template_path = Pathname(template_path) | ||
end | ||
|
||
def add | ||
directory.mkpath | ||
FileUtils.cp(template_path, config_path) | ||
end | ||
|
||
private | ||
|
||
attr_writer :name, :project, :template_path | ||
|
||
def directory | ||
project.directory.join("vectors") | ||
end | ||
|
||
def config_path | ||
directory.join("#{name.downcase}.yml") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
module Manifolds | ||
module API | ||
# Encapsulates a single manifold. | ||
class Workspace | ||
attr_reader :name, :project, :template_path | ||
|
||
DEFAULT_TEMPLATE_PATH = Pathname.pwd.join( | ||
"lib", "manifolds", "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 |
Oops, something went wrong.