Class: SourceCodesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SourceCodesController
- Defined in:
- app/controllers/source_codes_controller.rb
Instance Method Summary collapse
- #check ⇒ Object
- #create ⇒ Object
- #download ⇒ Object
- #load ⇒ Object
- #run ⇒ Object
- #to_blocks ⇒ Object
- #write ⇒ Object
Instance Method Details
#check ⇒ Object
7 8 9 |
# File 'app/controllers/source_codes_controller.rb', line 7 def check render json: SourceCode.new(source_code_params).check_syntax end |
#create ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'app/controllers/source_codes_controller.rb', line 11 def create sc = SourceCode.create!(source_code_params) session[:source_code] = { id: sc.id, digest: sc.digest, } render json: { source_code: { id: sc.id } } end |
#download ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/controllers/source_codes_controller.rb', line 20 def download send_data(source_code.data, filename: url_encode_filename(source_code.filename), disposition: 'attachment', type: 'text/plain; charset=utf-8') destroy_source_code_and_delete_session(source_code) end |
#load ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/source_codes_controller.rb', line 42 def load f = params[:source_code][:file] info = get_file_info(f) if /\Atext\/plain/ =~ info[:type] info[:data] = NKF.nkf('-w', f.read) else info[:error] = 'Rubyのプログラムではありません' end render json: { source_code: info }, content_type: request.format end |
#run ⇒ Object
54 55 56 57 58 |
# File 'app/controllers/source_codes_controller.rb', line 54 def run source_code = SourceCode.new(source_code_params) path = Pathname("~/#{source_code.filename}"). render json: source_code.run(path) end |
#to_blocks ⇒ Object
60 61 62 63 64 65 |
# File 'app/controllers/source_codes_controller.rb', line 60 def to_blocks source_code = SourceCode.new(source_code_params) render text: source_code.to_blocks rescue head :bad_request end |
#write ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/source_codes_controller.rb', line 29 def write res = { source_code: { filename: source_code.filename } } write_source_code(source_code) destroy_source_code_and_delete_session(source_code) render json: res rescue => e res[:source_code][:error] = e. render json: res end |