Class: AbstractAnalyzer::View
- Inherits:
-
Object
- Object
- AbstractAnalyzer::View
- Defined in:
- lib/view.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
Class Method Summary collapse
- .get(uri, options = {}, &block) ⇒ Object
-
.inherited(klass) ⇒ Object
From Railsnatra Set @_routes on child classes.
- .to_app ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
- #db ⇒ Object
-
#initialize(app, collection = nil) ⇒ View
constructor
A new instance of View.
Constructor Details
#initialize(app, collection = nil) ⇒ View
Returns a new instance of View.
10 11 12 13 |
# File 'lib/view.rb', line 10 def initialize(app, collection = nil) @collection = collection.to_s @app = app end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
9 10 11 |
# File 'lib/view.rb', line 9 def collection @collection end |
Class Method Details
.get(uri, options = {}, &block) ⇒ Object
53 54 55 |
# File 'lib/view.rb', line 53 def get(uri, = {}, &block) route(:get, uri, , &block) end |
.inherited(klass) ⇒ Object
From Railsnatra Set @_routes on child classes
31 32 33 |
# File 'lib/view.rb', line 31 def inherited(klass) klass.class_eval { @_routes = [] } end |
.to_app ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/view.rb', line 35 def to_app routes, controller = @_routes, self # From Railsnatra ;) # We're using Usher as a router for this project. To # simplify things, we just used the rack interface to # router and it's DSL. app = Usher::Interface.for(:rack) do routes.each do |route| conditions = {:request_method => route[:method]} add(route[:uri], :conditions => conditions.merge(route[:options])). to(controller.action(route[:action])) end end app end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/view.rb', line 15 def call(env) method_name = "[#{env["REQUEST_METHOD"].to_s.downcase}] #{env["PATH_INFO"]}" # This has got to be not good for performance # Consider using the PATH_INFO var instead if self.respond_to?(method_name) content = self.__send__(method_name) [200, {"Content-Type" => "text/plain"}, content] else @app.call(env) end end |
#db ⇒ Object
5 6 7 |
# File 'lib/view.rb', line 5 def db AbstractAnalyzer.const_get("DB") end |