Class: Fir::AdminInterface
- Inherits:
-
Object
- Object
- Fir::AdminInterface
- Includes:
- AdminMiddleware
- Defined in:
- lib/fir/admin.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ AdminInterface
constructor
A new instance of AdminInterface.
Methods included from AdminMiddleware
Constructor Details
#initialize(app) ⇒ AdminInterface
Returns a new instance of AdminInterface.
43 44 45 46 |
# File 'lib/fir/admin.rb', line 43 def initialize(app) @app = app @file_server = ::Rack::File.new(File.join(FIR_ROOT, 'public')) end |
Instance Method Details
#call(env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fir/admin.rb', line 48 def call(env) session = env['rack.session'] path = env['PATH_INFO'].chomp('/') if admin_path?(env) match = path.match(/^\/?-admin\/pages\/(.+)/) if match page = Fir.sanitize_page(match[1]) page_path = File.join(FIR_ROOT, 'pages', page) if env['REQUEST_METHOD'].downcase == 'post' update_page(page_path, env) elsif File.exists?(page_path) case env['REQUEST_METHOD'].downcase when 'get' return retrieve_page(page_path) when 'delete' return delete_page(page_path) else return method_not_allowed('Only GET and POST are allowed') end else return not_found end elsif path.match(/^\/?-admin\/pages$/) return page_index else return not_found end else return @app.call(env) end end |