Class: Pretzel::Core
- Inherits:
-
Object
- Object
- Pretzel::Core
- Extended by:
- Forwardable, Extension, Routing::Methods
- Includes:
- Routing::Evaluation
- Defined in:
- lib/pretzel/core.rb
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
- .builder ⇒ Object
- .filters ⇒ Object
- .new(*args, &block) ⇒ Object
- .new! ⇒ Object
- .routes ⇒ Object
- .token ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
- #halt(*res) ⇒ Object
-
#initialize ⇒ Core
constructor
end self.
Methods included from Extension
Methods included from Routing::Methods
Methods included from Routing::Evaluation
Constructor Details
#initialize ⇒ Core
end self
51 52 53 54 |
# File 'lib/pretzel/core.rb', line 51 def initialize self.class.use Rack::Session::Cookie, secret: self.class.token self.class.use Rack::Static, :urls => ["/assets"] end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
22 23 24 |
# File 'lib/pretzel/core.rb', line 22 def parameters @parameters end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
22 23 24 |
# File 'lib/pretzel/core.rb', line 22 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
22 23 24 |
# File 'lib/pretzel/core.rb', line 22 def response @response end |
Class Method Details
.builder ⇒ Object
46 47 48 |
# File 'lib/pretzel/core.rb', line 46 def builder @builder ||= Rack::Builder.new end |
.filters ⇒ Object
36 37 38 |
# File 'lib/pretzel/core.rb', line 36 def filters @filters ||= Hash.new end |
.new(*args, &block) ⇒ Object
41 42 43 44 |
# File 'lib/pretzel/core.rb', line 41 def new(*args, &block) builder.run new!(*args, &block) builder end |
.new! ⇒ Object
40 |
# File 'lib/pretzel/core.rb', line 40 alias_method :new!, :new |
.routes ⇒ Object
32 33 34 |
# File 'lib/pretzel/core.rb', line 32 def routes @routes ||= Hash.new { |hash, key| hash[key] = [] } end |
.token ⇒ Object
28 29 30 |
# File 'lib/pretzel/core.rb', line 28 def token @token ||= SecureRandom.hex(32) end |
Instance Method Details
#call(env) ⇒ Object
56 57 58 |
# File 'lib/pretzel/core.rb', line 56 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pretzel/core.rb', line 60 def call!(env) @request = Rack::Request.new(env) @response = Rack::Response.new @parameters = request.params @response["Server"] = "Ruby/#{RUBY_VERSION}" @response["X-Generated-By"] = "Pretzel/#{Pretzel::VERSION}" evaluate_route @response.finish end |
#halt(*res) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pretzel/core.rb', line 73 def halt(*res) response.status = res.detect{|x| x.is_a?(Fixnum) } || 200 response.header.merge!(res.detect{|x| x.is_a?(Hash) } || {}) if self.class.routes[response.status].empty? response.body = [res.detect{|x| x.is_a?(String) } || ""] else self.class.routes[response.status].each do |route, block| response.write instance_eval(&block) end end throw :halt, response end |