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



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

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



44
45
46
47
48
49
50
51
52
# File 'lib/souls/cli/gcloud/functions/index.rb', line 44

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.warning("Deleted #{name} functions!", "")
end

#deployObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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]
  runtime_lang = current_dir.match(/^cf-(\D+)\d+-/)[1]
  entry_point =
    case runtime_lang
    when "nodejs"
      current_dir.underscore.camelize(:lower)
    when "python"
      current_dir.underscore
    when "go"
      current_dir.underscore.camelize
    else
      system("bundle install")
      current_dir
    end
  system(
    "
      gcloud functions deploy #{current_dir} --entry-point='#{entry_point}' --project=#{project_id} \
      --runtime #{runtime} --trigger-http --allow-unauthenticated --env-vars-file .env.yaml
      "
  )
end

#describeObject



36
37
38
39
40
41
# File 'lib/souls/cli/gcloud/functions/index.rb', line 36

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



76
77
78
79
80
81
# File 'lib/souls/cli/gcloud/functions/index.rb', line 76

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



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

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