class ActionFramework::Server

Attributes

routesklass[RW]

Public Class Methods

current() click to toggle source
# File lib/actionframework.rb, line 40
    def self.current
   if($runningserver.nil?)
            $runningserver = ActionFramework::Server.new
                             ActionFramework::Project.autoimport
     $runningserver
   else
     $runningserver
   end
end
current=(runningserver) click to toggle source
# File lib/actionframework.rb, line 50
def self.current=(runningserver)
  $runningserver = runningserver
end
new() click to toggle source
# File lib/actionframework.rb, line 32
def initialize
        require 'bundler'
        Bundler.require(:default)

        @routesklass = ActionFramework::Routes.new
        @settings = ActionFramework::Settings.new
end

Public Instance Methods

autoimport() click to toggle source

DEPRECATED This method will soon be removed in favor of ActionFramework::Project.autoimport

# File lib/actionframework.rb, line 55
def autoimport

 ActionFramework::Project.autoimport

end
call(env) click to toggle source
# File lib/actionframework.rb, line 61
def call env
        req = Rack::Request.new(env)
        res = Rack::Response.new

        # redirection
        redirect = @routesklass.redirect? req
        if(!redirect.nil?)
                res.redirect(redirect.to)
                return res.finish
        end


        # auto-api feature (only at path /api/*)
        reso = getModelResponse(req,res)
        if(!reso.nil?)
                return reso
        end

        controllerinfo = @routesklass.route(req.path,req.request_method)
        if(controllerinfo == nil)
                res.body = [ActionFramework::ErrorHandler.new(env,req,res,{}).send("error_404")]
                res.status = 404
                return res.finish
        end

        controller = controllerinfo[0]
        matcheddata = controllerinfo[1]

        result = ActionFramework::ControllerSupervisor.new.run(controller,env,req,res,matcheddata)
        if(result.class.to_s == "ActionFramework::ThisObject")
                result.response.finish
        else
                res.write result
                res.finish
        end
end
getModelResponse(req,res) click to toggle source
# File lib/actionframework.rb, line 113
def getModelResponse req,res
   if(matcheddata = req.path.match(Regexp.new("/api/(?<modelname>(.*))")))
                   return nil unless @routesklass.models.include?(matcheddata[:modelname])

                            res["Content-type"] = "application/json"
                            model = Object.const_get(matcheddata[:modelname].capitalize)
                            model.instance_variable_set("@req",req)

                            case req.request_method
                            when "POST"
                                    return ActionFramework::ModelHelper.post model,req,res
                            when "GET"
                                    return ActionFramework::ModelHelper.get model,res
                            when "UPDATE"
                                    return ActionFramework::ModelHelper.update model,res
                            when "DELETE"

                            else

                            end
            end
            nil
end
get_settings() click to toggle source
# File lib/actionframework.rb, line 105
def get_settings
        @settings
end
routes(&block) click to toggle source
# File lib/actionframework.rb, line 97
def routes &block
        @routesklass.instance_eval &block
end
settings() { |settings| ... } click to toggle source
# File lib/actionframework.rb, line 101
def settings
        yield @settings
end
start() click to toggle source
# File lib/actionframework.rb, line 109
    def start
  Rack::Server.new({:app => self,:server => @settings.server, :Port => @settings.port}).start
end