punk 0.3.6 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +1 -1
  3. data/.rubocop.yml +1091 -93
  4. data/.standard.yml +2 -0
  5. data/Gemfile +60 -60
  6. data/Gemfile.lock +22 -17
  7. data/README.md +7 -3
  8. data/Rakefile +9 -7
  9. data/VERSION +1 -1
  10. data/app/migrations/001_lets_punk.rb +1 -1
  11. data/app/routes/hello.rb +1 -1
  12. data/bin/punk +5 -5
  13. data/lib/punk.rb +7 -7
  14. data/lib/punk/actions/sessions/create.rb +3 -3
  15. data/lib/punk/actions/sessions/verify.rb +2 -2
  16. data/lib/punk/commands/auth.rb +4 -4
  17. data/lib/punk/commands/generate.rb +5 -5
  18. data/lib/punk/commands/http.rb +4 -4
  19. data/lib/punk/commands/list.rb +10 -10
  20. data/lib/punk/core/app.rb +41 -41
  21. data/lib/punk/core/boot.rb +5 -5
  22. data/lib/punk/core/cli.rb +3 -3
  23. data/lib/punk/core/commander.rb +28 -28
  24. data/lib/punk/core/commands.rb +8 -8
  25. data/lib/punk/core/env.rb +27 -27
  26. data/lib/punk/core/exec.rb +8 -8
  27. data/lib/punk/core/interface.rb +19 -19
  28. data/lib/punk/core/load.rb +2 -2
  29. data/lib/punk/core/logger.rb +3 -3
  30. data/lib/punk/core/monkey.rb +1 -1
  31. data/lib/punk/core/pry.rb +2 -2
  32. data/lib/punk/core/settings.rb +4 -4
  33. data/lib/punk/core/version.rb +1 -1
  34. data/lib/punk/core/worker.rb +6 -6
  35. data/lib/punk/framework/all.rb +8 -8
  36. data/lib/punk/framework/model.rb +6 -5
  37. data/lib/punk/framework/plugins/all.rb +1 -1
  38. data/lib/punk/framework/plugins/validation.rb +8 -8
  39. data/lib/punk/framework/service.rb +5 -3
  40. data/lib/punk/framework/worker.rb +3 -3
  41. data/lib/punk/helpers/all.rb +5 -5
  42. data/lib/punk/helpers/loggable.rb +3 -3
  43. data/lib/punk/helpers/publishable.rb +1 -1
  44. data/lib/punk/helpers/renderable.rb +10 -10
  45. data/lib/punk/helpers/validatable.rb +7 -6
  46. data/lib/punk/migrations/001_punk.rb +12 -12
  47. data/lib/punk/models/group.rb +1 -1
  48. data/lib/punk/models/identity.rb +1 -1
  49. data/lib/punk/models/session.rb +7 -7
  50. data/lib/punk/models/tenant.rb +1 -1
  51. data/lib/punk/models/user.rb +2 -2
  52. data/lib/punk/plugins/all.rb +2 -2
  53. data/lib/punk/plugins/cors.rb +2 -2
  54. data/lib/punk/plugins/ssl.rb +1 -1
  55. data/lib/punk/routes/groups.rb +1 -1
  56. data/lib/punk/routes/plivo.rb +1 -1
  57. data/lib/punk/routes/sessions.rb +2 -2
  58. data/lib/punk/routes/swagger.rb +2 -2
  59. data/lib/punk/routes/tenants.rb +1 -1
  60. data/lib/punk/routes/users.rb +1 -1
  61. data/lib/punk/services/challenge_claim.rb +5 -5
  62. data/lib/punk/services/generate_swagger.rb +6 -6
  63. data/lib/punk/services/prove_claim.rb +1 -1
  64. data/lib/punk/startup/cache.rb +3 -3
  65. data/lib/punk/startup/database.rb +4 -4
  66. data/lib/punk/startup/environment.rb +6 -6
  67. data/lib/punk/startup/logger.rb +2 -2
  68. data/lib/punk/startup/task.rb +5 -5
  69. data/lib/punk/views/fail.rb +2 -2
  70. data/lib/punk/views/groups/list.rb +2 -2
  71. data/lib/punk/views/info.rb +2 -2
  72. data/lib/punk/views/plivo_store.rb +2 -2
  73. data/lib/punk/views/sessions/list.rb +2 -2
  74. data/lib/punk/views/sessions/pending.rb +2 -2
  75. data/lib/punk/views/tenants/list.rb +2 -2
  76. data/lib/punk/views/users/list.rb +2 -2
  77. data/lib/punk/views/users/show.rb +2 -2
  78. data/lib/punk/workers/geocode_session_worker.rb +3 -3
  79. data/lib/punk/workers/identify_session_worker.rb +1 -1
  80. data/lib/punk/workers/send_email_worker.rb +3 -3
  81. data/lib/punk/workers/send_sms_worker.rb +3 -3
  82. data/punk.gemspec +8 -4
  83. data/spec/actions/groups/punk/list_groups_action_spec.rb +9 -9
  84. data/spec/actions/sessions/punk/clear_session_action_spec.rb +11 -11
  85. data/spec/actions/sessions/punk/create_session_action_spec.rb +9 -9
  86. data/spec/actions/sessions/punk/list_sessions_action_spec.rb +8 -8
  87. data/spec/actions/sessions/punk/verify_session_action_spec.rb +24 -24
  88. data/spec/actions/tenants/punk/list_tenants_action_spec.rb +6 -6
  89. data/spec/actions/users/punk/list_group_users_action_spec.rb +6 -6
  90. data/spec/actions/users/punk/list_tenant_users_action_spec.rb +6 -6
  91. data/spec/factories/group.rb +1 -1
  92. data/spec/factories/group_user_metadata.rb +1 -1
  93. data/spec/factories/identity.rb +4 -4
  94. data/spec/factories/session.rb +1 -1
  95. data/spec/factories/tenant.rb +1 -1
  96. data/spec/factories/tenant_user_metadata.rb +1 -1
  97. data/spec/factories/user.rb +1 -1
  98. data/spec/lib/commands/generate_spec.rb +2 -2
  99. data/spec/lib/commands/list_spec.rb +2 -2
  100. data/spec/lib/commands/swagger_spec.rb +2 -2
  101. data/spec/lib/engine/punk_env_spec.rb +4 -4
  102. data/spec/lib/engine/punk_exec_spec.rb +2 -2
  103. data/spec/lib/engine/punk_init_spec.rb +2 -2
  104. data/spec/lib/engine/punk_store_spec.rb +2 -2
  105. data/spec/models/punk/group_spec.rb +4 -4
  106. data/spec/models/punk/group_user_metadata_spec.rb +2 -2
  107. data/spec/models/punk/identity_spec.rb +17 -17
  108. data/spec/models/punk/session_spec.rb +4 -4
  109. data/spec/models/punk/tenant_spec.rb +3 -3
  110. data/spec/models/punk/tenant_user_metadata_spec.rb +2 -2
  111. data/spec/models/punk/user_spec.rb +9 -9
  112. data/spec/routes/groups/get_groups_spec.rb +4 -4
  113. data/spec/routes/plivo/get_plivo_spec.rb +1 -1
  114. data/spec/routes/sessions/delete_session_spec.rb +1 -1
  115. data/spec/routes/sessions/get_sessions_spec.rb +5 -5
  116. data/spec/routes/sessions/patch_session_spec.rb +1 -1
  117. data/spec/routes/sessions/post_session_spec.rb +1 -1
  118. data/spec/routes/swagger/get_swagger_spec.rb +1 -1
  119. data/spec/routes/tenants/get_tenants_spec.rb +5 -5
  120. data/spec/routes/users/get_users_spec.rb +6 -6
  121. data/spec/services/punk/challenge_claim_service_spec.rb +2 -2
  122. data/spec/services/punk/create_identities_service_spec.rb +1 -1
  123. data/spec/services/punk/generate_swagger_service_spec.rb +2 -2
  124. data/spec/services/punk/prove_claim_service_spec.rb +2 -2
  125. data/spec/services/punk/secret_service_spec.rb +2 -2
  126. data/spec/spec_helper.rb +27 -27
  127. data/spec/views/punk/plivo_store_spec.rb +2 -2
  128. data/spec/views/sessions/punk/list_sessions_view_spec.rb +2 -2
  129. data/spec/views/sessions/punk/pending_session_view_spec.rb +2 -2
  130. data/spec/views/tenants/punk/list_tenants_view_spec.rb +2 -2
  131. data/spec/views/users/punk/list_groups_view_spec.rb +2 -2
  132. data/spec/views/users/punk/list_users_view_spec.rb +2 -2
  133. data/spec/workers/punk/geocode_session_worker_spec.rb +2 -2
  134. data/spec/workers/punk/identify_session_worker_spec.rb +3 -3
  135. data/spec/workers/punk/send_email_worker_spec.rb +1 -1
  136. metadata +18 -3
@@ -17,8 +17,8 @@ module PUNK
17
17
 
18
18
  def process
19
19
  verify = ProveClaimService.run(session: session, secret: secret)
20
- raise BadRequest, 'Secret is incorrect' unless verify.result == true
21
- present Info, message: 'We have succesfully verified your identity. Welcome to GroupFire!'
20
+ raise BadRequest, "Secret is incorrect" unless verify.result == true
21
+ present Info, message: "We have succesfully verified your identity. Welcome to GroupFire!"
22
22
  end
23
23
  end
24
24
  end
@@ -15,7 +15,7 @@ PUNK::Command.create "login" do
15
15
  "PATH_INFO" => "/sessions",
16
16
  "CONTENT_TYPE" => "text/json",
17
17
  "SCRIPT_NAME" => "",
18
- "rack.input" => StringIO.new({ claim: claim }.to_json)
18
+ "rack.input" => StringIO.new({claim: claim}.to_json)
19
19
  )
20
20
  response = ActiveSupport::JSON.decode(response[-1].first).deep_symbolize_keys
21
21
  return if response[:errors].present?
@@ -23,17 +23,17 @@ PUNK::Command.create "login" do
23
23
  authenticated = false
24
24
  while authenticated == false
25
25
  SemanticLogger.flush
26
- secret = ask("Secret: ") { |q| q.echo = '*' }
26
+ secret = ask("Secret: ") { |q| q.echo = "*" }
27
27
  response =
28
28
  PUNK.app.call(
29
29
  "REQUEST_METHOD" => "PATCH",
30
30
  "PATH_INFO" => "/sessions/#{slug}",
31
31
  "CONTENT_TYPE" => "text/json",
32
32
  "SCRIPT_NAME" => "",
33
- "rack.input" => StringIO.new({ secret: secret }.to_json)
33
+ "rack.input" => StringIO.new({secret: secret}.to_json)
34
34
  )
35
35
  response = ActiveSupport::JSON.decode(response[-1].first).deep_symbolize_keys
36
- break if response[:errors].present? && response[:errors].first != 'Secret is incorrect'
36
+ break if response[:errors].present? && response[:errors].first != "Secret is incorrect"
37
37
  authenticated = response[:message].present?
38
38
  end
39
39
  response[:message]
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  PUNK::Command.create "generate" do
4
- shortcut 'g'
4
+ shortcut "g"
5
5
  description "Generate routes, actions, models, views, services or workers"
6
6
 
7
7
  def process
8
- case args.join(' ')
9
- when 'route', 'action', 'model', 'view', 'service', 'worker', 'scaffold'
8
+ case args.join(" ")
9
+ when "route", "action", "model", "view", "service", "worker", "scaffold"
10
10
  "TBD"
11
- when '', 'help'
11
+ when "", "help"
12
12
  "? specify one of: routes, actions, models, views, services, scaffold"
13
13
  else
14
- "? unkown arguments: #{args.join(',')}"
14
+ "? unkown arguments: #{args.join(",")}"
15
15
  end
16
16
  end
17
17
  end
@@ -4,7 +4,7 @@ PUNK::Command.create "GET" do
4
4
  description "Perform a HTTP GET request"
5
5
 
6
6
  def process
7
- path, query = args[0].split('?')
7
+ path, query = args[0].split("?")
8
8
  PUNK.app.call(
9
9
  "REQUEST_METHOD" => "GET",
10
10
  "PATH_INFO" => path,
@@ -24,7 +24,7 @@ PUNK::Command.create "PATCH" do
24
24
  "PATH_INFO" => args[0],
25
25
  "CONTENT_TYPE" => "text/json",
26
26
  "SCRIPT_NAME" => "",
27
- "rack.input" => StringIO.new(args[1..-1].join)
27
+ "rack.input" => StringIO.new(args[1..].join)
28
28
  )
29
29
  end
30
30
  end
@@ -38,7 +38,7 @@ PUNK::Command.create "POST" do
38
38
  "PATH_INFO" => args[0],
39
39
  "CONTENT_TYPE" => "text/json",
40
40
  "SCRIPT_NAME" => "",
41
- "rack.input" => StringIO.new(args[1..-1].join)
41
+ "rack.input" => StringIO.new(args[1..].join)
42
42
  )
43
43
  end
44
44
  end
@@ -52,7 +52,7 @@ PUNK::Command.create "PUT" do
52
52
  "PATH_INFO" => args[0],
53
53
  "CONTENT_TYPE" => "text/json",
54
54
  "SCRIPT_NAME" => "",
55
- "rack.input" => StringIO.new(args[1..-1].join)
55
+ "rack.input" => StringIO.new(args[1..].join)
56
56
  )
57
57
  end
58
58
  end
@@ -1,30 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  PUNK::Command.create "list" do
4
- shortcut 'l'
4
+ shortcut "l"
5
5
  description "List routes, actions, models, views, services or workers"
6
6
 
7
7
  option shortcut: :a, name: :all, description: "Include Punk!", type: nil
8
8
 
9
9
  def process
10
- case args.join(' ')
11
- when 'routes'
10
+ case args.join(" ")
11
+ when "routes"
12
12
  PUNK.app
13
13
  PUNK::App.route_list # TODO: exclude PUNK routes by default
14
- when 'actions'
14
+ when "actions"
15
15
  ObjectSpace.each_object(PUNK::Action.singleton_class).map(&:name).reject { |name| _hide?(name) }
16
- when 'models'
16
+ when "models"
17
17
  ObjectSpace.each_object(PUNK::Model.singleton_class).map(&:name).reject { |name| _hide?(name) }
18
- when 'views'
18
+ when "views"
19
19
  ObjectSpace.each_object(PUNK::View.singleton_class).map(&:name).reject { |name| _hide?(name) }
20
- when 'services'
20
+ when "services"
21
21
  ObjectSpace.each_object(PUNK::Service.singleton_class).select { |klass| klass.superclass == PUNK::Service }.map(&:name).reject { |name| _hide?(name) }
22
- when 'workers'
22
+ when "workers"
23
23
  ObjectSpace.each_object(PUNK::Worker.singleton_class).select { |klass| klass.superclass == PUNK::Worker }.map(&:name).reject { |name| _hide?(name) }
24
- when '', 'help'
24
+ when "", "help"
25
25
  "? specify one of: routes, actions, models, views, services, workers"
26
26
  else
27
- "? unkown arguments: #{args.join(',')}"
27
+ "? unkown arguments: #{args.join(",")}"
28
28
  end
29
29
  end
30
30
 
data/lib/punk/core/app.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'roda'
4
- require 'sidekiq/web'
5
- require 'sidekiq/cron/web'
6
- require 'rack/protection'
3
+ require "roda"
4
+ require "sidekiq/web"
5
+ require "sidekiq/cron/web"
6
+ require "rack/protection"
7
7
 
8
- require_relative '../plugins/all'
8
+ require_relative "../plugins/all"
9
9
 
10
10
  # don't use rack session for sidekiq (we do our own auth when routing)
11
11
  Sidekiq::Web.set(:sessions, false)
12
12
  # TODO: need custom roda route csrf in sidekiq web forms
13
- Sidekiq::Web.use(::Rack::Protection, use: :none, logging: true, logger: SemanticLogger['PUNK::RPT'])
13
+ Sidekiq::Web.use(::Rack::Protection, use: :none, logging: true, logger: SemanticLogger["PUNK::RPT"])
14
14
 
15
15
  module PUNK
16
16
  def self.route(name, &block)
@@ -23,15 +23,15 @@ module PUNK
23
23
 
24
24
  ROUTES = Tempfile.new("routes.json").path
25
25
  PUNK.profile_info("generate", path: ROUTES) do
26
- system "roda-parse_routes -f #{ROUTES} #{File.expand_path(File.join(PUNK.get.app.path, 'routes', '*'))} #{File.expand_path(File.join(__dir__, '..', 'routes', '*'))}"
26
+ system "roda-parse_routes -f #{ROUTES} #{File.expand_path(File.join(PUNK.get.app.path, "routes", "*"))} #{File.expand_path(File.join(__dir__, "..", "routes", "*"))}"
27
27
  end
28
28
 
29
29
  class App < Roda
30
30
  include Loggable
31
31
 
32
32
  REMOTE = PUNK.env.staging? || PUNK.env.production?
33
- PUBLIC = File.join(PUNK.get.app.path, '..', 'www')
34
- index_path = File.join(PUBLIC, 'index.html')
33
+ PUBLIC = File.join(PUNK.get.app.path, "..", "www")
34
+ index_path = File.join(PUBLIC, "index.html")
35
35
  INDEX =
36
36
  if File.exist?(index_path)
37
37
  File.read(index_path)
@@ -50,7 +50,7 @@ module PUNK
50
50
  INDEX_HTML
51
51
  end
52
52
 
53
- plugin :sessions, secret: [PUNK.get.cookie.secret].pack('H*'),
53
+ plugin :sessions, secret: [PUNK.get.cookie.secret].pack("H*"),
54
54
  key: PUNK.get.cookie.key,
55
55
  max_seconds: 1.year.to_i,
56
56
  max_idle_sessions: 1.month.to_i,
@@ -70,12 +70,12 @@ module PUNK
70
70
  plugin :path_rewriter
71
71
  plugin :slash_path_empty
72
72
  plugin :multi_route
73
- plugin :type_routing, types: { csv: 'text/csv' }, default_type: :json
73
+ plugin :type_routing, types: {csv: "text/csv"}, default_type: :json
74
74
  plugin :route_list, file: ROUTES
75
75
  plugin :disallow_file_uploads
76
76
  plugin :public, root: PUBLIC
77
77
 
78
- plugin :default_headers, 'Content-Type' => 'text/html', 'Content-Security-Policy' => "default-src 'self';img-src *", 'Strict-Transport-Security' => 'max-age=16070400;', 'X-Frame-Options' => 'deny', 'X-Content-Type-Options' => 'nosniff', 'X-XSS-Protection' => '1; mode=block'
78
+ plugin :default_headers, "Content-Type" => "text/html", "Content-Security-Policy" => "default-src 'self';img-src *", "Strict-Transport-Security" => "max-age=16070400;", "X-Frame-Options" => "deny", "X-Content-Type-Options" => "nosniff", "X-XSS-Protection" => "1; mode=block"
79
79
 
80
80
  plugin :error_handler
81
81
  plugin :not_found
@@ -83,24 +83,24 @@ module PUNK
83
83
 
84
84
  request_delegate :root, :on, :is, :get, :post, :redirect, :patch, :delete
85
85
 
86
- rewrite_path(/\A\/?\z/, '/index.html')
87
- rewrite_path(/\A\/api\/?\z/, '/api/index.html')
86
+ rewrite_path(/\A\/?\z/, "/index.html")
87
+ rewrite_path(/\A\/api\/?\z/, "/api/index.html")
88
88
 
89
89
  def require_session!
90
90
  begin
91
- @_current_session = Session[request.session['session_id']]
91
+ @_current_session = Session[request.session["session_id"]]
92
92
  if @_current_session&.active?
93
93
  @_current_session.touch
94
94
  else
95
95
  clear_session
96
96
  @_current_session = nil
97
97
  end
98
- rescue StandardError => e
98
+ rescue => e
99
99
  exception(e)
100
100
  raise Unauthorized, e.message
101
101
  end
102
- raise Unauthorized, 'Session does not exist' if @_current_session.nil?
103
- PUNK.logger.info "require_session!", { current_session: current_session.inspect, current_identity: current_identity.inspect, current_user: current_user.inspect }.inspect
102
+ raise Unauthorized, "Session does not exist" if @_current_session.nil?
103
+ PUNK.logger.info "require_session!", {current_session: current_session.inspect, current_identity: current_identity.inspect, current_user: current_user.inspect}.inspect
104
104
  end
105
105
 
106
106
  def require_anonymous!
@@ -109,9 +109,9 @@ module PUNK
109
109
  end
110
110
 
111
111
  def require_tenant!
112
- raise Unauthorized, 'Session does not exist' if @_current_session.nil?
112
+ raise Unauthorized, "Session does not exist" if @_current_session.nil?
113
113
  @_current_tenant = current_user.tenants_dataset[id: params[:tenant_id]]
114
- PUNK.logger.info "require_tenant!", { current_tenant: @_current_tenant.inspect }.inspect
114
+ PUNK.logger.info "require_tenant!", {current_tenant: @_current_tenant.inspect}.inspect
115
115
  end
116
116
 
117
117
  def args
@@ -145,17 +145,17 @@ module PUNK
145
145
  end
146
146
 
147
147
  PUNK_CONTENT_TYPE_LOOKUP = {
148
- csv: 'text/csv',
149
- html: 'text/html',
150
- json: 'application/json',
151
- xml: 'application/xml'
148
+ csv: "text/csv",
149
+ html: "text/html",
150
+ json: "application/json",
151
+ xml: "application/xml"
152
152
  }.freeze
153
153
  def render(view)
154
154
  raise InternalServerError, "Not a view: #{view}" unless view.is_a?(View)
155
155
  format = request.requested_type
156
156
  view.profile_info("render", format: format) do
157
157
  response.status = view.status if view.is_a?(Fail)
158
- response['Content-Type'] = PUNK_CONTENT_TYPE_LOOKUP[format]
158
+ response["Content-Type"] = PUNK_CONTENT_TYPE_LOOKUP[format]
159
159
  view.render(format)
160
160
  end
161
161
  end
@@ -164,7 +164,7 @@ module PUNK
164
164
  exception(e, current_user: current_user)
165
165
  case e
166
166
  when BadRequest
167
- present Fail, message: 'Bad Request', error_messages: [e.message], status: 400
167
+ present Fail, message: "Bad Request", error_messages: [e.message], status: 400
168
168
  when Unauthorized
169
169
  present Fail, message: "Unauthorized", error_messages: [e.message], status: 401
170
170
  when Forbidden
@@ -190,10 +190,10 @@ module PUNK
190
190
  @_started = Time.now.utc
191
191
  name = "#{request.request_method} #{request.path}"
192
192
  logger.info "Started #{name} for #{request.ip}", params.deep_symbolize_keys.sanitize.inspect
193
- logger.trace request.env['HTTP_USER_AGENT']
193
+ logger.trace request.env["HTTP_USER_AGENT"]
194
194
  logger.info "Started #{name} for #{request.ip || Session.default_values[:remote_addr].to_s}", params.deep_symbolize_keys.sanitize.inspect
195
- logger.trace request.env['HTTP_USER_AGENT'] || Session.default_values[:user_agent]
196
- logger.trace request.env['HTTP_COOKIE']
195
+ logger.trace request.env["HTTP_USER_AGENT"] || Session.default_values[:user_agent]
196
+ logger.trace request.env["HTTP_COOKIE"]
197
197
  logger.push_tags(name)
198
198
  _set_cookie(request.env)
199
199
  end
@@ -203,14 +203,14 @@ module PUNK
203
203
  name = logger.pop_tags(1).join
204
204
  duration = 1000.0 * (Time.now.utc - @_started)
205
205
  logger.pop_tags
206
- logger.trace((headers.present? ? headers['Set-Cookie'] : nil) || "(no cookie set)")
206
+ logger.trace((headers.present? ? headers["Set-Cookie"] : nil) || "(no cookie set)")
207
207
  logger.info message: "Completed #{name} status #{status}", duration: duration
208
208
  _store_cookie(headers)
209
209
  end
210
210
 
211
211
  route do |r|
212
212
  r.public
213
- r.on 'jobs' do
213
+ r.on "jobs" do
214
214
  require_session!
215
215
  r.run Sidekiq::Web
216
216
  end
@@ -222,26 +222,26 @@ module PUNK
222
222
  def _set_cookie(headers)
223
223
  return if REMOTE
224
224
  return if headers.blank?
225
- return if headers['HTTP_USER_AGENT'].present?
226
- return if headers['HTTP_COOKIE'].present?
227
- cookie_file = 'tmp/.cookie-jar'
228
- cookie_file += '-test' if PUNK.env.test?
225
+ return if headers["HTTP_USER_AGENT"].present?
226
+ return if headers["HTTP_COOKIE"].present?
227
+ cookie_file = "tmp/.cookie-jar"
228
+ cookie_file += "-test" if PUNK.env.test?
229
229
  cookie = File.read(cookie_file) if File.exist?(cookie_file)
230
230
  return if cookie.blank?
231
- headers['HTTP_COOKIE'] = cookie
231
+ headers["HTTP_COOKIE"] = cookie
232
232
  end
233
233
 
234
234
  def _store_cookie(headers)
235
235
  return if REMOTE
236
236
  return if headers.blank?
237
- cookie = headers['Set-Cookie']
237
+ cookie = headers["Set-Cookie"]
238
238
  return if cookie.blank?
239
- cookie_file = 'tmp/.cookie-jar'
240
- cookie_file += '-test' if PUNK.env.test?
241
- if cookie =~ /max-age=0/
239
+ cookie_file = "tmp/.cookie-jar"
240
+ cookie_file += "-test" if PUNK.env.test?
241
+ if /max-age=0/.match?(cookie)
242
242
  File.delete(cookie_file)
243
243
  else
244
- File.open(cookie_file, 'w') { |file| file << cookie }
244
+ File.open(cookie_file, "w") { |file| file << cookie }
245
245
  end
246
246
  end
247
247
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../startup/logger'
4
- require_relative '../startup/environment'
5
- require_relative '../startup/task'
6
- require_relative '../startup/database'
7
- require_relative '../startup/cache'
3
+ require_relative "../startup/logger"
4
+ require_relative "../startup/environment"
5
+ require_relative "../startup/task"
6
+ require_relative "../startup/database"
7
+ require_relative "../startup/cache"
8
8
 
9
9
  PUNK.store[:state] = :booted
data/lib/punk/core/cli.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../punk'
3
+ require_relative "../../punk"
4
4
 
5
- require 'highline/import'
5
+ require "highline/import"
6
6
 
7
- PUNK.init(task: 'console', config: { app: { name: 'Punk!' } }).exec
7
+ PUNK.init(task: "console", config: {app: {name: "Punk!"}}).exec
8
8
 
9
9
  PUNK.commands(:pry)
10
10
 
@@ -1,65 +1,65 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  command :test do |c|
4
- c.description = 'Run rubocop and rspec'
4
+ c.description = "Run rubocop and rspec"
5
5
  c.action do
6
- say('Running tests...')
7
- unless ENV['PUNK_ENV'] == 'test'
8
- error('!!! PUNK_ENV should be test !!!')
6
+ say("Running tests...")
7
+ unless ENV["PUNK_ENV"] == "test"
8
+ error("!!! PUNK_ENV should be test !!!")
9
9
  exit 1 # rubocop:disable Rails/Exit
10
10
  end
11
11
  ENV.delete_if { |name, _value| name =~ /^PUNK_/ }
12
- system('rubocop') &&
12
+ system("rubocop") &&
13
13
  # system('quasar build -m pwa') &&
14
- system('PUNK_ENV=test rspec')
14
+ system("PUNK_ENV=test rspec")
15
15
  exit $CHILD_STATUS.exitstatus # rubocop:disable Rails/Exit
16
16
  end
17
17
  end
18
18
 
19
19
  command :console do |c|
20
- c.description = 'Launch the console'
20
+ c.description = "Launch the console"
21
21
  c.action do
22
- say(HighLine.color('🤘 Are you ready to rock?', :green, :bold))
23
- path = File.join(__dir__, 'cli.rb')
22
+ say(HighLine.color("🤘 Are you ready to rock?", :green, :bold))
23
+ path = File.join(__dir__, "cli.rb")
24
24
  exec "pry -r #{path}"
25
25
  end
26
26
  end
27
27
  alias_command :c, :console
28
28
 
29
29
  command :server do |c|
30
- c.description = 'Start the server'
30
+ c.description = "Start the server"
31
31
  c.action do
32
- say('Starting server...')
33
- exec 'puma -C ./config/puma.rb'
32
+ say("Starting server...")
33
+ exec "puma -C ./config/puma.rb"
34
34
  end
35
35
  end
36
36
  alias_command :s, :server
37
37
 
38
38
  command :worker do |c|
39
- c.description = 'Start the worker'
39
+ c.description = "Start the worker"
40
40
  c.action do
41
- say('Starting worker...')
42
- path = File.join(__dir__, 'worker.rb')
41
+ say("Starting worker...")
42
+ path = File.join(__dir__, "worker.rb")
43
43
  exec "sidekiq -r #{path} -C ./config/sidekiq.yml"
44
44
  end
45
45
  end
46
46
  alias_command :w, :worker
47
47
 
48
- command 'env dump' do |c|
49
- c.description = 'Display the environment'
48
+ command "env dump" do |c|
49
+ c.description = "Display the environment"
50
50
  c.action do
51
- say('Dumping env...')
51
+ say("Dumping env...")
52
52
  ap PUNK.get # rubocop:disable Rails/Output
53
53
  end
54
54
  end
55
55
 
56
- command 'db create' do |c|
57
- c.description = 'Create the database (dropping it first if necessary)'
56
+ command "db create" do |c|
57
+ c.description = "Create the database (dropping it first if necessary)"
58
58
  c.action do
59
- say('Creating db...')
60
- require 'sequel'
59
+ say("Creating db...")
60
+ require "sequel"
61
61
  database = File.basename(PUNK.get.db.url)
62
- server = PUNK.get.db.url.gsub(/[^\/]+$/, 'postgres')
62
+ server = PUNK.get.db.url.gsub(/[^\/]+$/, "postgres")
63
63
  pg = Sequel.connect(server)
64
64
  pg.execute "DROP DATABASE IF EXISTS #{database}"
65
65
  pg.execute "CREATE DATABASE #{database}"
@@ -67,14 +67,14 @@ command 'db create' do |c|
67
67
  end
68
68
  end
69
69
 
70
- command 'db migrate' do |c|
71
- c.description = 'Run database migrations'
72
- c.option '-r', 'Number of versions to migrate, +ve for up and -ve for down', '--relative NUMBER', Integer
70
+ command "db migrate" do |c|
71
+ c.description = "Run database migrations"
72
+ c.option "-r", "Number of versions to migrate, +ve for up and -ve for down", "--relative NUMBER", Integer
73
73
  c.action do |_args, options|
74
- say('Migrating db...')
74
+ say("Migrating db...")
75
75
  PUNK.boot
76
76
  Sequel.extension :migration
77
- migrations_path = File.join(PUNK.get.app.path, 'migrations')
77
+ migrations_path = File.join(PUNK.get.app.path, "migrations")
78
78
  if File.exist?(migrations_path)
79
79
  if options.relative.nil?
80
80
  Sequel::Migrator.run(PUNK.db, migrations_path)