Class: Rufus::Sixjo::App

Inherits:
Object
  • Object
show all
Defined in:
lib/rufus/sixjo.rb

Overview

Sixjo’s Rack app

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(next_app, routes, helpers, configures, options) ⇒ App

Returns a new instance of App.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rufus/sixjo.rb', line 77

def initialize (next_app, routes, helpers, configures, options)

  @next_app = next_app
  @routes = routes || [] # the 'no route' case is rather useless...
  @helpers = helpers || []

  #@prefix = options[:prefix] || ''
  #@rprefix = Regexp.new(@prefix)

  @environment = options[:environment] || 'development'
  @environment = @environment.to_s

  #
  # run the configure blocks

  (configures || []).each do |envs, block|
    instance_eval(&block) if envs.empty? or envs.include?(@environment)
  end
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



75
76
77
# File 'lib/rufus/sixjo.rb', line 75

def environment
  @environment
end

Instance Method Details

#applicationObject



97
98
99
# File 'lib/rufus/sixjo.rb', line 97

def application
  self
end

#call(env) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rufus/sixjo.rb', line 101

def call (env)

  block = nil

  begin
    block = lookup_block(env)
  rescue => e
    #puts e
    #puts e.backtrace
    return [ 400, {}, e.to_s ]
  end

  if block
    Context.service(self, block, @helpers, env)
  elsif @next_app
    @next_app.call(env)
  else
    [ 404, {}, [ "not found #{env['PATH_INFO']}" ] ]
  end
end