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.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rufus/sixjo.rb', line 92

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.



90
91
92
# File 'lib/rufus/sixjo.rb', line 90

def environment
  @environment
end

Instance Method Details

#applicationObject



112
113
114
# File 'lib/rufus/sixjo.rb', line 112

def application
  self
end

#call(env) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rufus/sixjo.rb', line 116

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