souls 0.23.8 → 0.24.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.irbrc +1 -0
  4. data/Gemfile.lock +1 -1
  5. data/README.md +34 -5
  6. data/apps/api/.env.sample +7 -0
  7. data/apps/api/.gitignore +32 -0
  8. data/apps/api/.irbrc +4 -0
  9. data/apps/api/.rspec +3 -0
  10. data/apps/api/.rubocop.yml +132 -0
  11. data/apps/api/.ruby-version +1 -0
  12. data/apps/api/CODE_OF_CONDUCT.md +74 -0
  13. data/apps/api/Dockerfile +16 -0
  14. data/apps/api/Dockerfile.dev +17 -0
  15. data/apps/api/Gemfile +50 -0
  16. data/apps/api/Gemfile.lock +412 -0
  17. data/apps/api/LICENSE.txt +67 -0
  18. data/apps/api/Procfile +2 -0
  19. data/apps/api/Procfile.dev +2 -0
  20. data/apps/api/README.md +37 -0
  21. data/apps/api/Rakefile +5 -0
  22. data/apps/api/app.rb +114 -0
  23. data/apps/api/app/engines/notification_engine.rb +5 -0
  24. data/apps/api/app/graphql/mutations/.keep +0 -0
  25. data/apps/api/app/graphql/mutations/base/article/create_article.rb +30 -0
  26. data/apps/api/app/graphql/mutations/base/article/delete_article.rb +17 -0
  27. data/apps/api/app/graphql/mutations/base/article/destroy_delete_article.rb +17 -0
  28. data/apps/api/app/graphql/mutations/base/article/update_article.rb +30 -0
  29. data/apps/api/app/graphql/mutations/base/article_category/create_article_category.rb +21 -0
  30. data/apps/api/app/graphql/mutations/base/article_category/delete_article_category.rb +17 -0
  31. data/apps/api/app/graphql/mutations/base/article_category/destroy_delete_article_category.rb +17 -0
  32. data/apps/api/app/graphql/mutations/base/article_category/update_article_category.rb +21 -0
  33. data/apps/api/app/graphql/mutations/base/user/create_user.rb +31 -0
  34. data/apps/api/app/graphql/mutations/base/user/delete_user.rb +17 -0
  35. data/apps/api/app/graphql/mutations/base/user/destroy_delete_user.rb +17 -0
  36. data/apps/api/app/graphql/mutations/base/user/update_user.rb +31 -0
  37. data/apps/api/app/graphql/mutations/base_mutation.rb +65 -0
  38. data/apps/api/app/graphql/mutations/managers/user_manager/add_user_role.rb +22 -0
  39. data/apps/api/app/graphql/mutations/managers/user_manager/remove_user_role.rb +22 -0
  40. data/apps/api/app/graphql/mutations/managers/user_manager/sign_in_user.rb +45 -0
  41. data/apps/api/app/graphql/queries/article.rb +13 -0
  42. data/apps/api/app/graphql/queries/article_categories.rb +11 -0
  43. data/apps/api/app/graphql/queries/article_category.rb +13 -0
  44. data/apps/api/app/graphql/queries/articles.rb +11 -0
  45. data/apps/api/app/graphql/queries/base_query.rb +12 -0
  46. data/apps/api/app/graphql/queries/me.rb +11 -0
  47. data/apps/api/app/graphql/queries/user.rb +13 -0
  48. data/apps/api/app/graphql/queries/users.rb +11 -0
  49. data/apps/api/app/graphql/resolvers/article_category_search.rb +41 -0
  50. data/apps/api/app/graphql/resolvers/article_search.rb +57 -0
  51. data/apps/api/app/graphql/resolvers/base.rb +17 -0
  52. data/apps/api/app/graphql/resolvers/user_search.rb +63 -0
  53. data/apps/api/app/graphql/souls_api_schema.rb +43 -0
  54. data/apps/api/app/graphql/types/.keep +0 -0
  55. data/apps/api/app/graphql/types/article_category_type.rb +12 -0
  56. data/apps/api/app/graphql/types/article_type.rb +30 -0
  57. data/apps/api/app/graphql/types/base/base_argument.rb +4 -0
  58. data/apps/api/app/graphql/types/base/base_enum.rb +4 -0
  59. data/apps/api/app/graphql/types/base/base_field.rb +5 -0
  60. data/apps/api/app/graphql/types/base/base_input_object.rb +5 -0
  61. data/apps/api/app/graphql/types/base/base_interface.rb +7 -0
  62. data/apps/api/app/graphql/types/base/base_object.rb +6 -0
  63. data/apps/api/app/graphql/types/base/base_scalar.rb +4 -0
  64. data/apps/api/app/graphql/types/base/base_union.rb +4 -0
  65. data/apps/api/app/graphql/types/base/mutation_type.rb +26 -0
  66. data/apps/api/app/graphql/types/base/query_type.rb +18 -0
  67. data/apps/api/app/graphql/types/connections/article_category_connection.rb +3 -0
  68. data/apps/api/app/graphql/types/connections/article_connection.rb +3 -0
  69. data/apps/api/app/graphql/types/connections/base_connection.rb +14 -0
  70. data/apps/api/app/graphql/types/connections/user_connection.rb +3 -0
  71. data/apps/api/app/graphql/types/edges/article_category_edge.rb +5 -0
  72. data/apps/api/app/graphql/types/edges/article_edge.rb +5 -0
  73. data/apps/api/app/graphql/types/edges/base_edge.rb +4 -0
  74. data/apps/api/app/graphql/types/edges/user_edge.rb +5 -0
  75. data/apps/api/app/graphql/types/user_type.rb +24 -0
  76. data/apps/api/app/models/article.rb +4 -0
  77. data/apps/api/app/models/article_category.rb +3 -0
  78. data/apps/api/app/models/user.rb +19 -0
  79. data/apps/api/app/policies/application_policy.rb +40 -0
  80. data/apps/api/app/policies/article_category_policy.rb +31 -0
  81. data/apps/api/app/policies/article_policy.rb +31 -0
  82. data/apps/api/app/policies/user_policy.rb +35 -0
  83. data/apps/api/app/utils/association_loader.rb +50 -0
  84. data/apps/api/app/utils/fire_store.rb +9 -0
  85. data/apps/api/app/utils/firebase_id_token.rb +4 -0
  86. data/apps/api/app/utils/json_web_token.rb +13 -0
  87. data/apps/api/app/utils/record_loader.rb +10 -0
  88. data/apps/api/app/utils/souls_helper.rb +18 -0
  89. data/apps/api/cloudbuild.yml +32 -0
  90. data/apps/api/config.ru +17 -0
  91. data/apps/api/config/database.yml +33 -0
  92. data/apps/api/config/souls.rb +10 -0
  93. data/apps/api/constants/areas.rb +71 -0
  94. data/apps/api/constants/column_name_ja.rb +27 -0
  95. data/apps/api/db/migrate/20200006095538_create_users.rb +30 -0
  96. data/apps/api/db/migrate/20200712180236_create_article_categories.rb +12 -0
  97. data/apps/api/db/migrate/20200714215521_create_articles.rb +22 -0
  98. data/apps/api/db/schema.rb +78 -0
  99. data/apps/api/db/seeds.rb +44 -0
  100. data/apps/api/github/workflows/delivery.yml +81 -0
  101. data/apps/api/log/.keep +0 -0
  102. data/apps/api/spec/factories/article_categories.rb +9 -0
  103. data/apps/api/spec/factories/articles.rb +17 -0
  104. data/apps/api/spec/factories/users.rb +23 -0
  105. data/apps/api/spec/models/article_category_spec.rb +7 -0
  106. data/apps/api/spec/models/article_spec.rb +7 -0
  107. data/apps/api/spec/models/user_spec.rb +7 -0
  108. data/apps/api/spec/mutations/base/article_category_spec.rb +46 -0
  109. data/apps/api/spec/mutations/base/article_spec.rb +70 -0
  110. data/apps/api/spec/mutations/base/user_spec.rb +76 -0
  111. data/apps/api/spec/policies/article_category_policy_spec.rb +24 -0
  112. data/apps/api/spec/policies/article_policy_spec.rb +24 -0
  113. data/apps/api/spec/policies/user_policy_spec.rb +24 -0
  114. data/apps/api/spec/queries/article_category_spec.rb +39 -0
  115. data/apps/api/spec/queries/article_spec.rb +53 -0
  116. data/apps/api/spec/queries/user_spec.rb +59 -0
  117. data/apps/api/spec/resolvers/article_category_search_spec.rb +54 -0
  118. data/apps/api/spec/resolvers/article_search_spec.rb +68 -0
  119. data/apps/api/spec/resolvers/user_search_spec.rb +74 -0
  120. data/apps/api/spec/spec_helper.rb +110 -0
  121. data/apps/api/tmp/.keep +0 -0
  122. data/apps/worker/.env.sample +9 -0
  123. data/apps/worker/.gitignore +32 -0
  124. data/apps/worker/.irbrc +4 -0
  125. data/apps/worker/.rspec +3 -0
  126. data/apps/worker/.rubocop.yml +132 -0
  127. data/apps/worker/.ruby-version +1 -0
  128. data/apps/worker/CODE_OF_CONDUCT.md +74 -0
  129. data/apps/worker/Dockerfile +16 -0
  130. data/apps/worker/Dockerfile.dev +17 -0
  131. data/apps/worker/Gemfile +49 -0
  132. data/apps/worker/Gemfile.lock +396 -0
  133. data/apps/worker/LICENSE.txt +67 -0
  134. data/apps/worker/Procfile +1 -0
  135. data/apps/worker/Procfile.dev +1 -0
  136. data/apps/worker/README.md +37 -0
  137. data/apps/worker/Rakefile +5 -0
  138. data/apps/worker/app.rb +101 -0
  139. data/apps/worker/app/engines/notification_engine.rb +5 -0
  140. data/apps/worker/app/graphql/mutations/.keep +0 -0
  141. data/apps/worker/app/graphql/mutations/base_mutation.rb +16 -0
  142. data/apps/worker/app/graphql/mutations/workers/send_user_mail_job.rb +31 -0
  143. data/apps/worker/app/graphql/souls_api_schema.rb +43 -0
  144. data/apps/worker/app/graphql/types/.keep +0 -0
  145. data/apps/worker/app/graphql/types/base/base_argument.rb +4 -0
  146. data/apps/worker/app/graphql/types/base/base_enum.rb +4 -0
  147. data/apps/worker/app/graphql/types/base/base_field.rb +5 -0
  148. data/apps/worker/app/graphql/types/base/base_input_object.rb +5 -0
  149. data/apps/worker/app/graphql/types/base/base_interface.rb +7 -0
  150. data/apps/worker/app/graphql/types/base/base_object.rb +5 -0
  151. data/apps/worker/app/graphql/types/base/base_scalar.rb +4 -0
  152. data/apps/worker/app/graphql/types/base/base_union.rb +4 -0
  153. data/apps/worker/app/graphql/types/base/mutation_type.rb +12 -0
  154. data/apps/worker/app/graphql/types/base/query_type.rb +6 -0
  155. data/apps/worker/app/models/article.rb +4 -0
  156. data/apps/worker/app/models/article_category.rb +3 -0
  157. data/apps/worker/app/models/user.rb +19 -0
  158. data/apps/worker/app/utils/fire_store.rb +9 -0
  159. data/apps/worker/app/utils/souls_helper.rb +96 -0
  160. data/apps/worker/cloudbuild.yml +32 -0
  161. data/apps/worker/config.ru +17 -0
  162. data/apps/worker/config/database.yml +33 -0
  163. data/apps/worker/config/souls.rb +10 -0
  164. data/apps/worker/db/migrate/20200006095538_create_users.rb +30 -0
  165. data/apps/worker/db/migrate/20200712180236_create_article_categories.rb +12 -0
  166. data/apps/worker/db/migrate/20200714215521_create_articles.rb +22 -0
  167. data/apps/worker/db/schema.rb +78 -0
  168. data/apps/worker/db/seeds.rb +44 -0
  169. data/apps/worker/github/workflows/delivery.yml +81 -0
  170. data/apps/worker/log/.keep +0 -0
  171. data/apps/worker/spec/factories/article_categories.rb +9 -0
  172. data/apps/worker/spec/factories/articles.rb +17 -0
  173. data/apps/worker/spec/factories/users.rb +23 -0
  174. data/apps/worker/spec/models/article_category_spec.rb +7 -0
  175. data/apps/worker/spec/models/article_spec.rb +7 -0
  176. data/apps/worker/spec/models/user_spec.rb +7 -0
  177. data/apps/worker/spec/spec_helper.rb +110 -0
  178. data/apps/worker/tmp/.keep +0 -0
  179. data/config/souls.rb +7 -3
  180. data/exe/souls +16 -3
  181. data/lib/souls.rb +129 -140
  182. data/lib/souls/gcloud.rb +1 -0
  183. data/lib/souls/gcloud/compute.rb +62 -60
  184. data/lib/souls/gcloud/iam.rb +38 -22
  185. data/lib/souls/gcloud/pubsub.rb +21 -0
  186. data/lib/souls/init.rb +1 -16
  187. data/lib/souls/version.rb +1 -1
  188. metadata +176 -2
File without changes
@@ -0,0 +1,9 @@
1
+ FactoryBot.define do
2
+ factory :article_category do
3
+ name { Faker::Books::CultureSeries.culture_ship_class }
4
+ tags { %w[tag1 tag2 tag3] }
5
+ is_deleted { false }
6
+ created_at { Time.now }
7
+ updated_at { Time.now }
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ FactoryBot.define do
2
+ factory :article do
3
+ association :user, factory: :user
4
+ title { Faker::Book.unique.title }
5
+ body { Faker::Quote.matz }
6
+ thumnail_url { Faker::Internet.url }
7
+ public_date { Time.now }
8
+ association :article_category, factory: :article_category
9
+ is_public { false }
10
+ just_created { false }
11
+ slag { Faker::Internet.password(min_length: 16) }
12
+ tags { %w[tag1 tag2 tag3] }
13
+ is_deleted { false }
14
+ created_at { Time.now }
15
+ updated_at { Time.now }
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require "gimei"
2
+ FactoryBot.define do
3
+ factory :user do
4
+ uid { Faker::Internet.password }
5
+ username { Gimei.kanji }
6
+ screen_name { Faker::Internet.unique.username }
7
+ last_name { Gimei.last.hiragana }
8
+ first_name { Gimei.first.hiragana }
9
+ last_name_kanji { Gimei.last.kanji }
10
+ first_name_kanji { Gimei.first.kanji }
11
+ last_name_kana { Gimei.last.katakana }
12
+ first_name_kana { Gimei.last.katakana }
13
+ email { Faker::Internet.unique.email }
14
+ tel { Faker::PhoneNumber.subscriber_number(length: 10) }
15
+ icon_url { "https://picsum.photos/200" }
16
+ birthday { Faker::Date.birthday(min_age: 18, max_age: 65) }
17
+ gender { Gimei.male }
18
+ lang { "ja" }
19
+ category { "user" }
20
+ roles_mask { :normal }
21
+ is_deleted { false }
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.describe("ArticleCategory Model テスト", type: :model) do
2
+ describe "ArticleCategory データを書き込む" do
3
+ it "valid ArticleCategory Model" do
4
+ expect(FactoryBot.build(:article_category)).to(be_valid)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.describe("Article Model テスト", type: :model) do
2
+ describe "Article データを書き込む" do
3
+ it "valid Article Model" do
4
+ expect(FactoryBot.build(:article)).to(be_valid)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.describe("User Model テスト", type: :model) do
2
+ describe "User データを書き込む" do
3
+ it "valid User Model" do
4
+ expect(FactoryBot.build(:user)).to(be_valid)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,110 @@
1
+ ENV["RACK_ENV"] = "test"
2
+ require "./app"
3
+ require "rspec"
4
+ # require "test/unit"
5
+ require "rack/test"
6
+ require "database_cleaner"
7
+ require "capybara/rspec"
8
+ require "webmock/rspec"
9
+ require "pundit/matchers"
10
+
11
+ if ENV["RACK_ENV"] == "production"
12
+ abort("The Souls environment is running in production mode!")
13
+ end
14
+
15
+ WebMock.disable_net_connect!(allow_localhost: true)
16
+
17
+ begin
18
+ ActiveRecord::Migration.maintain_test_schema!
19
+ rescue ActiveRecord::PendingMigrationError => e
20
+ puts e.to_s.strip
21
+ exit 1
22
+ end
23
+
24
+ def app
25
+ SoulsApi
26
+ end
27
+
28
+ Pundit::Matchers.configure do |config|
29
+ # config.user_alias = :user_role
30
+ end
31
+
32
+ RSpec.configure do |config|
33
+ config.order = :random
34
+
35
+ config.include Capybara::DSL
36
+ config.expect_with :rspec do |expectations|
37
+ # config.filter_run_excluding skip: true
38
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
+ end
40
+
41
+ # rspec-mocks config goes here. You can use an alternate test double
42
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
43
+ config.mock_with :rspec do |mocks|
44
+ mocks.verify_partial_doubles = true
45
+ end
46
+
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+ config.include FactoryBot::Syntax::Methods
49
+ config.include Rack::Test::Methods
50
+
51
+ config.before(:suite) do
52
+ FactoryBot.find_definitions
53
+ DatabaseCleaner.clean_with(:truncation)
54
+ end
55
+
56
+ config.before(:each) do |_example|
57
+ DatabaseCleaner.strategy = :transaction
58
+ DatabaseCleaner.start
59
+ end
60
+
61
+ config.append_after(:each) { |_example| DatabaseCleaner.clean }
62
+ config.filter_run_excluding long: true
63
+ config.filter_run_excluding uses_external_service: true
64
+ end
65
+
66
+ class ActiveRecord::Base
67
+ mattr_accessor :shared_connection
68
+ @@shared_connection = nil
69
+
70
+ def self.connection
71
+ @@shared_connection || retrieve_connection
72
+ end
73
+ end
74
+
75
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
76
+ def get_global_key class_name, id
77
+ Base64.strict_encode64("#{class_name}:#{id}")
78
+ end
79
+
80
+ class ActiveSupport::TestCase
81
+ setup :begin_gc_deferment
82
+ teardown :reconsider_gc_deferment
83
+ teardown :scrub_instance_variables
84
+
85
+ @@reserved_ivars = %w[@_implementation @_result @_proxy @_assigns_hash_proxy @_backtrace]
86
+ DEFERRED_GC_THRESHOLD = (ENV["DEFER_GC"] || 1.0).to_f
87
+
88
+ @@last_gc_run = Time.now
89
+
90
+ def begin_gc_deferment
91
+ GC.disable if DEFERRED_GC_THRESHOLD > 0
92
+ end
93
+
94
+ def reconsider_gc_deferment
95
+ if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD
96
+
97
+ GC.enable
98
+ GC.start
99
+ GC.disable
100
+
101
+ @@last_gc_run = Time.now
102
+ end
103
+ end
104
+
105
+ def scrub_instance_variables
106
+ (instance_variables - @@reserved_ivars).each do |ivar|
107
+ instance_variable_set(ivar, nil)
108
+ end
109
+ end
110
+ end
File without changes
data/config/souls.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  Souls.configure do |config|
2
- config.app = "souls-app"
3
- config.project_id = "souls-app"
4
- config.strain = "api"
2
+ config.app = "souls-api"
3
+ config.project_id = "souls-api"
4
+ config.strain = "worker"
5
+ config.api_repo = "elsoul/souls_api"
6
+ config.worker_repo = "elsoul/souls_worker"
7
+ config.worker_endpoint = "https://worker.com"
8
+ config.fixed_gems = []
5
9
  end
data/exe/souls CHANGED
@@ -42,8 +42,6 @@ begin
42
42
  case strain
43
43
  when "media", "admin", "console", "doc"
44
44
  system("yarn dev")
45
- when "worker"
46
- system("bundle exec puma -p 3000 -e development")
47
45
  else
48
46
  system("foreman start -f Procfile.dev")
49
47
  end
@@ -69,7 +67,22 @@ begin
69
67
  Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
70
68
  Whirly.status = status
71
69
  send_method = ARGV[1]
72
- Souls::Gcloud.public_send(send_method)
70
+
71
+ case send_method
72
+ when "create_pubsub_topic"
73
+ topic_name = ARGV[2]
74
+ args = { topic_name: topic_name }
75
+ Souls::Gcloud.public_send(send_method, args)
76
+ when "create_pubsub_subscription"
77
+ project_id = Souls.configuration.project_id
78
+ topic_name = ARGV[2]
79
+ service_account = "#{Souls.configuration.app}@#{project_id}iam.gserviceaccount.com"
80
+ endpoint = Souls.configuration.endpoint
81
+ args = { project_id: project_id, topic_name: topic_name, service_account: service_account, endpoint: endpoint }
82
+ Souls::Gcloud.public_send(send_method, args)
83
+ else
84
+ Souls::Gcloud.public_send(send_method)
85
+ end
73
86
  Whirly.status = "Done!"
74
87
  end
75
88
  when "-v", "--version"
data/lib/souls.rb CHANGED
@@ -28,171 +28,160 @@ module Souls
28
28
  class Error < StandardError; end
29
29
  class << self
30
30
  attr_accessor :configuration
31
- end
32
-
33
- def self.run_psql
34
- system(
35
- "docker run --rm -d \
36
- -p 5433:5432 \
37
- -v postgres-tmp:/var/lib/postgresql/data \
38
- -e POSTGRES_USER=postgres \
39
- -e POSTGRES_PASSWORD=postgres \
40
- -e POSTGRES_DB=souls_test \
41
- postgres:13-alpine"
42
- )
43
- system("docker ps")
44
- end
45
31
 
46
- def self.run_mysql
47
- system(
48
- "docker run --rm -d \
49
- -p 3306:3306 \
50
- -v mysql-tmp:/var/lib/mysql \
51
- -e MYSQL_USER=mysql \
52
- -e MYSQL_ROOT_PASSWORD=mysql \
53
- -e MYSQL_DB=souls_test \
54
- mysql:latest"
55
- )
56
- system("docker ps")
57
- end
32
+ def run_psql
33
+ system(
34
+ "docker run --rm -d \
35
+ -p 5433:5432 \
36
+ -v postgres-tmp:/var/lib/postgresql/data \
37
+ -e POSTGRES_USER=postgres \
38
+ -e POSTGRES_PASSWORD=postgres \
39
+ -e POSTGRES_DB=souls_test \
40
+ postgres:13-alpine"
41
+ )
42
+ system("docker ps")
43
+ end
58
44
 
59
- def self.run_awake(url)
60
- app = Souls.configuration.app
61
- system(
62
- "gcloud scheduler jobs create http #{app}-awake
63
- --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
64
- )
65
- end
45
+ def run_mysql
46
+ system(
47
+ "docker run --rm -d \
48
+ -p 3306:3306 \
49
+ -v mysql-tmp:/var/lib/mysql \
50
+ -e MYSQL_USER=mysql \
51
+ -e MYSQL_ROOT_PASSWORD=mysql \
52
+ -e MYSQL_DB=souls_test \
53
+ mysql:latest"
54
+ )
55
+ system("docker ps")
56
+ end
66
57
 
67
- def self.show_wait_spinner(fps = 10)
68
- chars = %w[| / - \\]
69
- delay = 1.0 / fps
70
- iter = 0
71
- spinner =
72
- Thread.new do
73
- while iter
74
- print(chars[(iter += 1) % chars.length])
75
- sleep(delay)
76
- print("\b")
77
- end
78
- end
79
- yield.tap do
80
- iter = false
81
- spinner.join
58
+ def run_awake(url)
59
+ app = Souls.configuration.app
60
+ system(
61
+ "gcloud scheduler jobs create http #{app}-awake
62
+ --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
63
+ )
82
64
  end
83
- end
84
65
 
85
- def self.gemfile_latest_version
86
- file_path = "./Gemfile"
87
- updated_gems = []
88
- updated_gem_versions = []
89
- updated_lines = []
90
- from_dev = false
91
- File.open(file_path, "r") do |f|
92
- f.each_line do |line|
93
- from_dev = true if line.include?("group")
94
- next unless line.include?("gem ")
66
+ def gemfile_latest_version
67
+ file_path = "./Gemfile"
68
+ updated_gems = []
69
+ updated_gem_versions = []
70
+ updated_lines = []
71
+ from_dev = false
72
+ File.open(file_path, "r") do |f|
73
+ f.each_line do |line|
74
+ from_dev = true if line.include?("group")
75
+ next unless line.include?("gem ")
95
76
 
96
- gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
97
- url = URI("https://rubygems.org/api/v1/versions/#{gem[0]}/latest.json")
98
- res = Net::HTTP.get_response(url)
99
- data = JSON.parse(res.body)
100
- next if data["version"].to_s == gem[1].to_s
77
+ gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
78
+ url = URI("https://rubygems.org/api/v1/versions/#{gem[0]}/latest.json")
79
+ res = Net::HTTP.get_response(url)
80
+ data = JSON.parse(res.body)
81
+ next if Souls.configuration.fixed_gems.include?(gem[0].to_s)
82
+ next if data["version"].to_s == gem[1].to_s
101
83
 
102
- updated_lines << if from_dev
103
- " gem \"#{gem[0]}\", \"#{data['version']}\""
104
- else
105
- "gem \"#{gem[0]}\", \"#{data['version']}\""
106
- end
107
- updated_gems << (gem[0]).to_s
108
- updated_gem_versions << data["version"]
109
- system("gem update #{gem[0]}")
84
+ updated_lines << if from_dev
85
+ " gem \"#{gem[0]}\", \"#{data['version']}\""
86
+ else
87
+ "gem \"#{gem[0]}\", \"#{data['version']}\""
88
+ end
89
+ updated_gems << (gem[0]).to_s
90
+ updated_gem_versions << data["version"]
91
+ system("gem update #{gem[0]}")
92
+ end
110
93
  end
94
+ {
95
+ gems: updated_gems,
96
+ lines: updated_lines,
97
+ updated_gem_versions: updated_gem_versions
98
+ }
111
99
  end
112
- {
113
- gems: updated_gems,
114
- lines: updated_lines,
115
- updated_gem_versions: updated_gem_versions
116
- }
117
- end
118
100
 
119
- def self.update_gemfile
120
- file_path = "./Gemfile"
121
- tmp_file = "./tmp/Gemfile"
122
- new_gems = gemfile_latest_version
123
- logs = []
124
- message = Paint["\nAlready Up to date!", :green]
125
- return "Already Up to date!" && puts(message) if new_gems[:gems].blank?
101
+ def update_gemfile
102
+ file_path = "./Gemfile"
103
+ tmp_file = "./tmp/Gemfile"
104
+ new_gems = gemfile_latest_version
105
+ logs = []
106
+ message = Paint["\nAlready Up to date!", :green]
107
+ return "Already Up to date!" && puts(message) if new_gems[:gems].blank?
126
108
 
127
- @i = 0
128
- File.open(file_path, "r") do |f|
129
- File.open(tmp_file, "w") do |new_line|
130
- f.each_line do |line|
131
- gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
132
- if new_gems[:gems].include?(gem[0])
133
- old_ver = gem[1].split(".")
134
- new_ver = new_gems[:updated_gem_versions][@i].split(".")
135
- if old_ver[0] < new_ver[0]
136
- logs << Paint % [
137
- "#{gem[0]} v#{gem[1]} → %{red_text}",
138
- :white,
139
- {
140
- red_text: ["v#{new_gems[:updated_gem_versions][@i]}", :red]
141
- }
142
- ]
143
- elsif old_ver[1] < new_ver[1]
144
- logs << Paint % [
145
- "#{gem[0]} v#{gem[1]} → v#{new_ver[0]}.%{yellow_text}",
146
- :white,
147
- {
148
- yellow_text: ["#{new_ver[1]}.#{new_ver[2]}", :yellow]
149
- }
150
- ]
151
- elsif old_ver[2] < new_ver[2]
152
- logs << Paint % [
153
- "#{gem[0]} v#{gem[1]} → v#{new_ver[0]}.#{new_ver[1]}.%{green_text}",
154
- :white,
155
- {
156
- green_text: [(new_ver[2]).to_s, :green]
157
- }
158
- ]
109
+ @i = 0
110
+ File.open(file_path, "r") do |f|
111
+ File.open(tmp_file, "w") do |new_line|
112
+ f.each_line do |line|
113
+ gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
114
+ if new_gems[:gems].include?(gem[0])
115
+ old_ver = gem[1].split(".")
116
+ new_ver = new_gems[:updated_gem_versions][@i].split(".")
117
+ if old_ver[0] < new_ver[0]
118
+ logs << Paint % [
119
+ "#{gem[0]} v#{gem[1]} → %{red_text}",
120
+ :white,
121
+ {
122
+ red_text: ["v#{new_gems[:updated_gem_versions][@i]}", :red]
123
+ }
124
+ ]
125
+ elsif old_ver[1] < new_ver[1]
126
+ logs << Paint % [
127
+ "#{gem[0]} v#{gem[1]} → v#{new_ver[0]}.%{yellow_text}",
128
+ :white,
129
+ {
130
+ yellow_text: ["#{new_ver[1]}.#{new_ver[2]}", :yellow]
131
+ }
132
+ ]
133
+ elsif old_ver[2] < new_ver[2]
134
+ logs << Paint % [
135
+ "#{gem[0]} v#{gem[1]} → v#{new_ver[0]}.#{new_ver[1]}.%{green_text}",
136
+ :white,
137
+ {
138
+ green_text: [(new_ver[2]).to_s, :green]
139
+ }
140
+ ]
141
+ end
142
+ if gem[0] == "souls"
143
+ logs << Paint % [
144
+ "\nSOULs Doc: %{cyan_text}",
145
+ :white,
146
+ { cyan_text: ["https://souls.elsoul.nl\n", :cyan] }
147
+ ]
148
+ end
149
+ new_line.write("#{new_gems[:lines][@i]}\n")
150
+ @i += 1
151
+ else
152
+ new_line.write(line)
159
153
  end
160
- if gem[0] == "souls"
161
- logs << Paint % ["\nSOULs Doc: %{cyan_text}", :white, { cyan_text: ["https://souls.elsoul.nl\n", :cyan] }]
162
- end
163
- new_line.write("#{new_gems[:lines][@i]}\n")
164
- @i += 1
165
- else
166
- new_line.write(line)
167
154
  end
168
155
  end
169
156
  end
157
+ FileUtils.rm("./Gemfile")
158
+ FileUtils.rm("./Gemfile.lock")
159
+ FileUtils.mv("./tmp/Gemfile", "./Gemfile")
160
+ system("bundle update")
161
+ success = Paint["\n\nSuccessfully Updated These Gems!\n", :green]
162
+ puts(success)
163
+ logs.each do |line|
164
+ puts(line)
165
+ end
170
166
  end
171
- FileUtils.rm("./Gemfile")
172
- FileUtils.rm("./Gemfile.lock")
173
- FileUtils.mv("./tmp/Gemfile", "./Gemfile")
174
- system("bundle update")
175
- success = Paint["\n\nSuccessfully Updated These Gems!\n", :green]
176
- puts(success)
177
- logs.each do |line|
178
- puts(line)
179
- end
180
- end
181
167
 
182
- def self.configure
183
- self.configuration ||= Configuration.new
184
- yield(configuration)
168
+ def configure
169
+ self.configuration ||= Configuration.new
170
+ yield(configuration)
171
+ end
185
172
  end
186
173
 
187
174
  class Configuration
188
- attr_accessor :app, :strain, :project_id, :worker_name, :api_name
175
+ attr_accessor :app, :strain, :project_id, :worker_repo, :api_repo, :worker_endpoint, :fixed_gems
189
176
 
190
177
  def initialize
191
178
  @app = nil
192
179
  @project_id = nil
193
180
  @strain = nil
194
- @worker_name = nil
195
- @api_name = nil
181
+ @worker_repo = nil
182
+ @api_repo = nil
183
+ @worker_endpoint = nil
184
+ @fixed_gems = nil
196
185
  end
197
186
  end
198
187
  end