Class: Cnvrg::Flows

Inherits:
Object
  • Object
show all
Defined in:
lib/cnvrg/flow.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path, fullpath) ⇒ Flows

Returns a new instance of Flows.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/cnvrg/flow.rb', line 3

def initialize(project_path, fullpath)
  @project = Cnvrg::Project.new(project_path)
  @fullpath = fullpath
  @tasks = {}
  @relations = {}
  @title = nil
  @slug = nil
  @base_resource = @project.base_resource + "flows"

  self.reload_flow
end

Class Method Details

.create_flow(path, flow) ⇒ Object



15
16
17
# File 'lib/cnvrg/flow.rb', line 15

def self.create_flow(path, flow)
  File.open(path, "w"){|file| file.write flow.to_yaml}
end

Instance Method Details

#get_flowObject



19
20
21
22
23
24
# File 'lib/cnvrg/flow.rb', line 19

def get_flow
  unless File.exists? @fullpath
    raise StandardError.new("Cant find flow in #{@fullpath}")
  end
  YAML.load_file(@fullpath)
end

#reload_flowObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cnvrg/flow.rb', line 36

def reload_flow
  flow = self.get_flow
  @title = flow[:title]
  @slug = flow[:slug]
  @relations = flow[:relations]
  local_tasks = flow[:tasks] || {}
  @relations.each do |relation|
    relation.values.each do |task|
      if local_tasks[task].present?
        @tasks[task] = Cnvrg::Task.new(@project.local_path, content: local_tasks[task])
      else
        @tasks[task] = Cnvrg::Task.new(@project.local_path, path: task)
      end
    end
  end
end

#runObject



53
54
55
56
57
58
59
60
# File 'lib/cnvrg/flow.rb', line 53

def run
  resp = Cnvrg::API.request(@base_resource, 'POST', {data: to_api})
  Cnvrg::CLI.is_response_success(resp, true)
  flow_slug = resp['result']['flow']
  self.set_flow_slug(flow_slug)
  url = Cnvrg::Helpers.remote_url + resp['result']['url']
  return url
end

#set_flow(new_flow) ⇒ Object



26
27
28
# File 'lib/cnvrg/flow.rb', line 26

def set_flow(new_flow)
  File.open(@fullpath, "w"){|file| file.write new_flow.to_yaml}
end

#set_flow_slug(slug) ⇒ Object



30
31
32
33
34
# File 'lib/cnvrg/flow.rb', line 30

def set_flow_slug(slug)
  flow = self.get_flow
  flow[:slug] = slug
  self.set_flow(flow)
end