Class: Com::CommonController

Inherits:
BaseController show all
Defined in:
app/controllers/com/common_controller.rb

Constant Summary

Constants included from RailsCom::Application

RailsCom::Application::LOCALE_MAP

Instance Method Summary collapse

Methods included from RailsCom::Application

#current_title, #default_form_params, #default_params, #json_format?, #set_country, #set_flash, #set_locale, #set_timezone, #set_variant

Instance Method Details

#cache_listObject



17
18
19
# File 'app/controllers/com/common_controller.rb', line 17

def cache_list
  render json: CacheList.all.as_json(only: [:path, :key], methods: [:etag])
end

#cancelObject



14
15
# File 'app/controllers/com/common_controller.rb', line 14

def cancel
end

#deployObject

commit message end with ‘@deploy’



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/com/common_controller.rb', line 39

def deploy
  require 'deploy'
  digest = request.headers['X-Hub-Signature'].to_s
  digest.sub!('sha1=', '')
  payload = JSON.parse(params[:payload])

  if digest == Deploy.github_hmac(request.body.read) && payload.dig('head_commit', 'message').to_s.end_with?('@deploy')
    result = Deploy.exec_cmds Rails.env.to_s
  else
    result = ''
    logger.debug "==========> Deploy failed"
  end

  render plain: result
end

#enum_listObject



21
22
23
24
25
# File 'app/controllers/com/common_controller.rb', line 21

def enum_list
  r = I18n.backend.translations[I18n.locale][:activerecord][:enum]

  render json: { locale: I18n.locale, values: r }
end

#infoObject



7
8
9
10
11
12
# File 'app/controllers/com/common_controller.rb', line 7

def info
  q_params = {}
  q_params.merge! params.permit(:platform)

  @infos = Info.default_where(q_params)
end

#qrcodeObject



27
28
29
30
31
32
# File 'app/controllers/com/common_controller.rb', line 27

def qrcode
  options = qrcode_params.to_h.symbolize_keys
  buffer = QrcodeHelper.code_png(params[:url], **options)

  send_data buffer, filename: 'cert_file.png', disposition: 'inline', type: 'image/png'
end

#test_raiseObject



34
35
36
# File 'app/controllers/com/common_controller.rb', line 34

def test_raise
  raise 'error from test raise'
end