Method: Cnvrg::Dataset.init

Defined in:
lib/cnvrg/dataset.rb

.init(owner, dataset_name, is_public = false) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/cnvrg/dataset.rb', line 96

def self.init(owner, dataset_name, is_public=false)
    list_dirs = [".cnvrg"
    ]
    list_files = [
        ".cnvrgignore",
        ".cnvrg/config.yml"
    ]

    cnvrgignore = Helpers.cnvrgignore_content
    begin
        response = Cnvrg::API.request("cli/create_dataset", 'POST', {title: dataset_name, owner: owner, is_public: is_public})

        Cnvrg::CLI.is_response_success(response)
      response = JSON.parse response["result"]
      dataset_slug = response["slug"]

      config = {dataset_name: dataset_name,
                dataset_slug: dataset_slug,
                owner: owner}
      FileUtils.mkdir_p list_dirs
      FileUtils.touch list_files
      File.open(".cnvrg/config.yml", "w+") { |f| f.write config.to_yaml }
      File.open(".cnvrgignore", "w+") { |f| f.write cnvrgignore } unless File.exist? ".cnvrgignore"
    rescue => e

      return false
    end
    return true
end