Class: Openlayer::Project
- Defined in:
- lib/openlayer/objects/project.rb
Defined Under Namespace
Classes: CommitLengthError, Error, NotFoundError, TarFileNotFoundError
Constant Summary collapse
- REQUIRED_TARFILE_STRUCTURE =
[ "staging/commit.yaml", "staging/validation/dataset_config.yaml", "staging/validation/dataset.csv", "staging/model/model_config.yaml" ].freeze
- COMMIT_LENGTH =
(1..140).freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#commit_message ⇒ Object
readonly
Returns the value of attribute commit_message.
-
#data_tarfile_path ⇒ Object
readonly
Returns the value of attribute data_tarfile_path.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
-
#s3_presigned_body ⇒ Object
readonly
Returns the value of attribute s3_presigned_body.
-
#workspace_id ⇒ Object
readonly
Returns the value of attribute workspace_id.
Class Method Summary collapse
Instance Method Summary collapse
- #add_dataset(file_path:, dataset_config: nil, dataset_config_file_path: nil) ⇒ Object
- #add_model(model_config: nil, model_config_file_path: nil) ⇒ Object
- #commit(message) ⇒ Object
-
#initialize(client, attributes) ⇒ Project
constructor
A new instance of Project.
- #push ⇒ Object
- #status ⇒ Object
Methods inherited from Object
#method_missing, #respond_to_missing?
Constructor Details
#initialize(client, attributes) ⇒ Project
Returns a new instance of Project.
40 41 42 43 44 45 46 |
# File 'lib/openlayer/objects/project.rb', line 40 def initialize(client, attributes) @client = client super(attributes) @data_tarfile_path = "#{Dir.home}/.openlayer/#{id}_staging.tar" @project_path = "#{Dir.home}/.openlayer/#{id}" init_staging_directories end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Openlayer::Object
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
20 21 22 |
# File 'lib/openlayer/objects/project.rb', line 20 def client @client end |
#commit_message ⇒ Object (readonly)
Returns the value of attribute commit_message.
20 21 22 |
# File 'lib/openlayer/objects/project.rb', line 20 def @commit_message end |
#data_tarfile_path ⇒ Object (readonly)
Returns the value of attribute data_tarfile_path.
20 21 22 |
# File 'lib/openlayer/objects/project.rb', line 20 def data_tarfile_path @data_tarfile_path end |
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
20 21 22 |
# File 'lib/openlayer/objects/project.rb', line 20 def project_path @project_path end |
#s3_presigned_body ⇒ Object (readonly)
Returns the value of attribute s3_presigned_body.
20 21 22 |
# File 'lib/openlayer/objects/project.rb', line 20 def s3_presigned_body @s3_presigned_body end |
#workspace_id ⇒ Object (readonly)
Returns the value of attribute workspace_id.
20 21 22 |
# File 'lib/openlayer/objects/project.rb', line 20 def workspace_id @workspace_id end |
Class Method Details
.from_response(client, response) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/openlayer/objects/project.rb', line 33 def self.from_response(client, response) attributes_first_project = handle_response(response)&.dig("items")&.first raise NotFoundError if attributes_first_project.nil? new(client, attributes_first_project) end |
Instance Method Details
#add_dataset(file_path:, dataset_config: nil, dataset_config_file_path: nil) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/openlayer/objects/project.rb', line 48 def add_dataset(file_path:, dataset_config: nil, dataset_config_file_path: nil) raise ArgumentError, "dataset config is required" if dataset_config.nil? && dataset_config_file_path.nil? copy_file(file_path, "staging/validation/dataset.csv") copy_or_create_config(dataset_config, dataset_config_file_path, "staging/validation/dataset_config.yaml") end |
#add_model(model_config: nil, model_config_file_path: nil) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/openlayer/objects/project.rb', line 57 def add_model(model_config: nil, model_config_file_path: nil) raise ArgumentError, "model config is required" if model_config.nil? && model_config_file_path.nil? copy_or_create_config(model_config, model_config_file_path, "staging/model/model_config.yaml") end |
#commit(message) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/openlayer/objects/project.rb', line 72 def commit() raise CommitLengthError unless COMMIT_LENGTH.include? .length @commit_message = commit_hash = { "date": DateTime.now.strftime("%a %b %d %H:%M:%S %Y"), "message": } write_hash_to_file(commit_hash, "staging/commit.yaml") end |
#push ⇒ Object
83 84 85 86 87 88 |
# File 'lib/openlayer/objects/project.rb', line 83 def push create_and_validate_tar_file s3_client = create_s3_client s3_client.post(s3_payload) client.load_project_version(id: id, payload: version_payload) end |
#status ⇒ Object
65 66 67 68 69 70 |
# File 'lib/openlayer/objects/project.rb', line 65 def status puts "Staging Area:" Find.find(File.join(project_path, "/staging")) do |path| puts path if File.file?(path) end end |