Class: Openlayer::Project

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/openlayer/objects/project.rb', line 20

def client
  @client
end

#commit_messageObject (readonly)

Returns the value of attribute commit_message.



20
21
22
# File 'lib/openlayer/objects/project.rb', line 20

def commit_message
  @commit_message
end

#data_tarfile_pathObject (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_pathObject (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_bodyObject (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_idObject (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

Raises:



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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:



72
73
74
75
76
77
78
79
80
81
# File 'lib/openlayer/objects/project.rb', line 72

def commit(message)
  raise CommitLengthError unless COMMIT_LENGTH.include? message.length

  @commit_message = message
  commit_hash = {
    "date": DateTime.now.strftime("%a %b %d %H:%M:%S %Y"),
    "message": message
  }
  write_hash_to_file(commit_hash, "staging/commit.yaml")
end

#pushObject



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

#statusObject



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