Class: Pione::Front::InteractiveFront

Inherits:
BasicFront
  • Object
show all
Defined in:
lib/pione/front/interactive-front.rb

Overview

InteractiveFront is a front interface for +pione-interactive+ command.

Instance Attribute Summary

Attributes inherited from BasicFront

#uri

Instance Method Summary collapse

Methods inherited from BasicFront

#[], #[]=, #child_front_uri, #child_pids, #pid, #register_child, #system_logger, #terminate, #terminate_command, #unregister_child

Constructor Details

#initialize(cmd) ⇒ InteractiveFront

Returns a new instance of InteractiveFront.



5
6
7
# File 'lib/pione/front/interactive-front.rb', line 5

def initialize(cmd)
  super(cmd, Global.interactive_front_port_range)
end

Instance Method Details

#create(path, content) ⇒ Object

Create a file with the content. Thie operation returns true only if the file creation has succeeded.



31
32
33
34
35
36
37
38
# File 'lib/pione/front/interactive-front.rb', line 31

def create(path, content)
  begin
    (@cmd.model[:public] + path).write(content)
    return true
  rescue => e
    return false
  end
end

#delete(path) ⇒ Object

Delete the file. Thie operation returns true only if the file deletion has succeeded.



42
43
44
45
46
47
48
49
# File 'lib/pione/front/interactive-front.rb', line 42

def delete(path)
  begin
    (@cmd.model[:public] + path).delete
    return true
  rescue => e
    return false
  end
end

#get(path, cgi_info) ⇒ Object

Read data string from the path. This path should be relative from public directory of pione-interactive.

Parameters:

  • path (String)

    relative path from public directory

  • params (Hash)

    parameters to pass to the CGI program



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pione/front/interactive-front.rb', line 16

def get(path, cgi_info)
  local_file = (@cmd.model[:public] + path)
  if local_file.path.executable?
    return Util::CGIExecutor.new(local_file.path, cgi_info, @cmd.model[:public], @cmd.model[:timeout]).exec
  else
    begin
      local_file.read
    rescue
      return nil
    end
  end
end

#list(path, show_all) ⇒ Object

Return entry informations in the directory. When the operation returns nil, the file listing has failed. When this returns false, the path is file.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pione/front/interactive-front.rb', line 54

def list(path, show_all)
  begin
    unless (@cmd.model[:public] + path).directory?
      return false
    end

    (@cmd.model[:public] + path).entries.each_with_object([]) do |entry, list|
      if show_all or not(entry.basename.start_with?("."))
        list << {
          "name"  => entry.basename,
          "type"  => entry.directory? ? "dir" : "file",
          "mtime" => entry.mtime.iso8601,
          "size"  => entry.size
        }
      end
    end
  rescue => e
    return nil
  end
end