Class: SOULs::Functions

Inherits:
Thor
  • Object
show all
Defined in:
lib/souls/cli/gcloud/functions/index.rb

Instance Method Summary collapse

Instance Method Details

#all_urlObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/souls/cli/gcloud/functions/index.rb', line 50

def all_url
  require(SOULs.get_mother_path.to_s + "/config/souls")
  project_id = SOULs.configuration.project_id
  Dir.chdir(SOULs.get_mother_path.to_s) do
    souls_functions = Dir["apps/cf-*"]
    cf_dir = souls_functions.map { |n| n.split("/").last }
    cf_dir.each do |dir|
      SOULs::Painter.success(`gcloud functions describe #{dir} --project=#{project_id}| grep url`)
    end
  end
end

#delete(name) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/souls/cli/gcloud/functions/index.rb', line 31

def delete(name)
  require(SOULs.get_mother_path.to_s + "/config/souls")
  project_id = SOULs.configuration.project_id
  system("gcloud functions delete #{name} --project=#{project_id}")
  Dir.chdir(SOULs.get_mother_path.to_s) do
    FileUtils.rm_rf("apps/#{name}")
  end
  SOULs::Painter.success("Deleted #{name} functions!")
end

#deployObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/souls/cli/gcloud/functions/index.rb', line 4

def deploy
  require(SOULs.get_mother_path.to_s + "/config/souls")
  project_id = SOULs.configuration.project_id
  current_dir = FileUtils.pwd.split("/").last
  unless current_dir.match?(/^cf-/)
    SOULs::Painter.error("You are at wrong dir!\nPlease go to `apps/functions` dir!")
    return false
  end

  runtime = current_dir.match(/cf-(\D+\d+)-/)[1]
  system(
    "
      gcloud functions deploy #{current_dir} --project=#{project_id} \
      --runtime #{runtime} --trigger-http --allow-unauthenticated --env-vars-file .env.yaml
      "
  )
end

#describeObject



23
24
25
26
27
28
# File 'lib/souls/cli/gcloud/functions/index.rb', line 23

def describe
  require(SOULs.get_mother_path.to_s + "/config/souls")
  current_dir = FileUtils.pwd.split("/").last
  project_id = SOULs.configuration.project_id
  system("gcloud functions describe #{current_dir} --project=#{project_id}")
end

#devObject



63
64
65
66
67
68
# File 'lib/souls/cli/gcloud/functions/index.rb', line 63

def dev
  Dir.chdir(SOULs.get_functions_path.to_s) do
    current_dir = FileUtils.pwd.split("/").last
    system("bundle exec functions-framework-ruby --target #{current_dir}")
  end
end

#urlObject



42
43
44
45
46
47
# File 'lib/souls/cli/gcloud/functions/index.rb', line 42

def url
  require(SOULs.get_mother_path.to_s + "/config/souls")
  project_id = SOULs.configuration.project_id
  current_dir = FileUtils.pwd.split("/").last
  SOULs::Painter.success(`gcloud functions describe #{current_dir} --project=#{project_id}| grep url`)
end