package demo
class User(map : Map<String, Any?>) {
val name: String by Delegates.mapVal(map)
val age: Int by Delegates.mapVal(map)
}
fun main(args : Array<String>) {
val user = User(mapOf(
"name" to "John Doe",
"age" to 25
))
println(user.name)
println(user.age)
}
# coding: utf-8
require 'pty'
class ImportsController < ApplicationController
authorize_resource class: false # Deviseでログインしていることを確認
layout :layout #
def index
end
def hoge
render_stream do |r|
# rake taskでimport:hogeを作ってたとする
# rake import:hogeで逐次表示される内容をstreamで出力する
PTY.spawn("rake import:hoge") do |stdin, stdout, pid|
begin
stdin.each do |line|
r << line
end
rescue Error::EIO
end
end
end
end
private
def render_stream(&block)
# streamingで出力するための処理をここでまとめてる。
headers["Cache-Control"] ||= "no-cache"
headers["Transfer-Encoding"] = "chunked"
self.response_body = Rack::Chunked::Body.new(Enumerator.new do |r|
block.call r
end)
end
def layout
if action_name == 'index'
'application'
else
false
end
end
end