Class: Snap::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/snap/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run!(options = {}) ⇒ Object

require ‘logger’ use Rack::CommonLogger, Logger.new(STDOUT) Add Rack::Cache



14
15
16
17
# File 'lib/snap/server.rb', line 14

def self.run!(options={})
  @@root_dir = options[:root]
  super.run! if super.respond_to?("run!")
end

Instance Method Details

#at_root?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/snap/server.rb', line 77

def at_root?
  File.expand_path(get_current_dir) == File.expand_path(get_root_dir)
end

#get_current_dirObject

TODO: Cattr?



24
25
26
# File 'lib/snap/server.rb', line 24

def get_current_dir
  @dir
end

#get_root_dirObject



19
20
21
# File 'lib/snap/server.rb', line 19

def get_root_dir
  @@root_dir ||= Dir.pwd
end

#get_snap_filesObject



71
72
73
74
75
# File 'lib/snap/server.rb', line 71

def get_snap_files
  files = Dir.glob("#{get_current_dir}/**").map{|f| SnapFile.new(f)}
  files.insert(0,SnapFile.new(File.join(get_current_dir, '..'))) unless at_root?      
  files
end

#set_current_dir(newdir) ⇒ Object



28
29
30
# File 'lib/snap/server.rb', line 28

def set_current_dir(newdir)
  @dir = newdir
end