Class: MainController

Inherits:
Nephos::Controller show all
Defined in:
app/main.rb

Constant Summary collapse

AUTH_IMG_EXT =
%w(.jpg .jpeg .png .gif)

Instance Attribute Summary

Attributes inherited from Nephos::Controller

#callpath, #cookies, #extension, #params, #req

Instance Method Summary collapse

Methods inherited from Nephos::Controller

after_action, before_action, #execute_after_action, #execute_before_action, #html?, #initialize, #json?, #log, parse_action_opts, #plain?, #url_for

Constructor Details

This class inherits a constructor from Nephos::Controller

Instance Method Details



70
71
72
73
# File 'app/main.rb', line 70

def add_cookie
  cookies["UN_COOKIE_VAUT:"] = "UN BON MOMENT !"
  {plain: "cookie set"}
end

#add_urlObject



33
34
35
36
37
38
39
40
41
# File 'app/main.rb', line 33

def add_url
  url = params["url"]
  if url
    Dataset << url
    return {plain: "#{url} added"}
  else
    return {plain: "url argument required"}
  end
end

#debugObject



79
80
81
82
83
# File 'app/main.rb', line 79

def debug
  #require 'pry'
  #binding.pry
  {}
end

#err500Object



90
91
92
# File 'app/main.rb', line 90

def err500
  tessssssssss
end

#fct_after_rootObject



15
16
17
# File 'app/main.rb', line 15

def fct_after_root
  # puts "AFTER"
end

#fct_before_allObject



7
8
9
# File 'app/main.rb', line 7

def fct_before_all
  # puts "BEFORE ALL"
end

#fct_before_rootObject



11
12
13
# File 'app/main.rb', line 11

def fct_before_root
  # puts "BEFORE"
end

#get_cookiesObject



75
76
77
# File 'app/main.rb', line 75

def get_cookies
  {json: cookies.to_h}
end

#helloObject



53
54
55
# File 'app/main.rb', line 53

def hello
  {html: "<html><body><h1>hello world</h1><p>lol</p></body></html>"}
end

#imageObject



58
59
60
61
62
63
64
65
66
67
68
# File 'app/main.rb', line 58

def image
  dir = File.expand_path('app/')
  file = File.expand_path(params["image"], dir)
  if not file[0..(dir.size-1)] == dir or not AUTH_IMG_EXT.include?(File.extname(file))
    return {status: 500, content: "invalid path #{params['image']}"}
  elsif not File.exist? file
    return {status: 404, content: "invalid path #{params['image']}"}
  else
    return {type: 'image/jpeg', content: File.read(file)}
  end
end

#log_param_xObject



85
86
87
88
# File 'app/main.rb', line 85

def log_param_x
  Logger.fd = File.open '/tmp/nephos_ftest.log', 'w'
  log "#{params[:x]}"
end

#rm_urlObject



43
44
45
46
47
48
49
50
51
# File 'app/main.rb', line 43

def rm_url
  url = params[:url]
  if url
    Dataset.rm url
    return {plain: "#{url} removed"}
  else
    return {plain: "url argument required"}
  end
end

#rootObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/main.rb', line 19

def root
  # puts "ROOT"
  cookies["a"] = "b"
  cookies.delete("b").to_h
  # puts "Cookies from the root:", cookies
  {
    json: {
      list: $dataset,
      add: '/add',
      rm: '/rm',
    }
  }
end