Class: Druzy::Server::RestrictedFileServer
- Inherits:
-
OneInstanceByPort
- Object
- OneInstanceByPort
- Druzy::Server::RestrictedFileServer
- Defined in:
- lib/druzy/server/restricted_file_server.rb
Instance Method Summary collapse
- #add_file(file) ⇒ Object
- #get_address(file) ⇒ Object
-
#initialize(port) ⇒ RestrictedFileServer
constructor
A new instance of RestrictedFileServer.
- #remove_file(file) ⇒ Object
Methods inherited from OneInstanceByPort
Constructor Details
#initialize(port) ⇒ RestrictedFileServer
Returns a new instance of RestrictedFileServer.
14 15 16 17 18 19 |
# File 'lib/druzy/server/restricted_file_server.rb', line 14 def initialize(port) super(port) @files={} @id=0 end |
Instance Method Details
#add_file(file) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/druzy/server/restricted_file_server.rb', line 21 def add_file(file) @files[file]=@id @server.mount("/"+@id.to_s+"/"+I18n.transliterate(File.basename(file)),WEBrick::HTTPServlet::FileHandler,file) @id+=1 if @files.size == 1 start_server end end |
#get_address(file) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/druzy/server/restricted_file_server.rb', line 38 def get_address(file) if @files.include?(file) ip=Druzy::Utils.get_local_public_ipv4 return "http://"+ip+":"+@server.config[:Port].to_s+"/"+@files[file].to_s+"/"+I18n.transliterate(File.basename(file)) else return nil end end |
#remove_file(file) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/druzy/server/restricted_file_server.rb', line 31 def remove_file(file) @files.delete(file) if @files.size == 0 stop_server end end |