Class: ApiController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ApiController
- Defined in:
- app/controllers/api_controller.rb
Instance Method Summary collapse
- #empty_json ⇒ Object
- #file_preview ⇒ Object
- #grok_to_regexp ⇒ Object
- #regexp_preview ⇒ Object
- #tree ⇒ Object
Instance Method Details
#empty_json ⇒ Object
17 18 19 |
# File 'app/controllers/api_controller.rb', line 17 def empty_json render json: [] end |
#file_preview ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'app/controllers/api_controller.rb', line 6 def file_preview file = params[:file] unless File.exists?(file) return render json: [], status: 404 end unless File.file?(file) && File.readable?(file) return render json: [], status: 403 end render json: file_tail(file) end |
#grok_to_regexp ⇒ Object
31 32 33 34 35 |
# File 'app/controllers/api_controller.rb', line 31 def grok_to_regexp grok = GrokConverter.new grok.load_patterns render text: grok.convert_to_regexp(params[:grok_str]).source end |
#regexp_preview ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/api_controller.rb', line 21 def regexp_preview preview = RegexpPreview.new(params[:file], params[:format], regexp: params[:regexp], time_format: params[:time_format]) matches = preview.matches render json: { regexp: preview.regexp.try(:source), time_format: preview.time_format, matches: matches.compact, } end |
#tree ⇒ Object
2 3 4 |
# File 'app/controllers/api_controller.rb', line 2 def tree render json: Treeview.tree(params[:path]) end |