Class: Mosaic::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaic/module.rb

Overview

The master class for all modules Should be inhertied by any class that gets used in Mosaic::Aplication

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, path) ⇒ Module

Creates a new responder, called by Mosaic::Application for every request that uses a given module Takes the request object and the current path as input



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mosaic/module.rb', line 32

def initialize(request, path)
  @path = path
  @request = request
  @response = Mosaic::Response.new(request)
  @params = request.params
  chunks = path.split("/").collect { |x| x if x =~ /:/ }
  chunks.each do |chunk|
    if chunk
      key = chunk.gsub(/:/,'')
      key.gsub!(/(.*?)\./,'')
      key.gsub!(/\?/,'')
      @params[key.to_sym] = @request.path_info.split("/")[path.split("/").index(chunk)]
    end
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



28
29
30
# File 'lib/mosaic/module.rb', line 28

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



28
29
30
# File 'lib/mosaic/module.rb', line 28

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



28
29
30
# File 'lib/mosaic/module.rb', line 28

def response
  @response
end

Class Method Details

.provide_middleware(middleware) ⇒ Object

Class method for modules, adds the supplied class to the middleware array Called as:

provide_middleware Foo:Middleware


58
59
60
# File 'lib/mosaic/module.rb', line 58

def self.provide_middleware(middleware)
  Mosaic.add_middleware(middleware)
end

.respond_to(type, path) ⇒ Object

Class method for modules, if called the responder is declaring that it is capable of handling requests of the supplied type for the supplied path Called as:

respond_to :get, "/foo"


51
52
53
# File 'lib/mosaic/module.rb', line 51

def self.respond_to(type, path)
  Mosaic.add_response(type, path, self)
end