Class: NYNY::Base

Inherits:
Object
  • Object
show all
Includes:
Inheritable
Defined in:
lib/nyny/base.rb

Direct Known Subclasses

App

Constant Summary collapse

HTTP_VERBS =
[:delete, :get, :head, :options, :patch, :post, :put, :trace]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inheritable

included

Constructor Details

#initialize(app = nil) ⇒ Base

Returns a new instance of Base.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nyny/base.rb', line 19

def initialize app=nil
  self.class.before_init_hooks.each {|h| h.call(self)}

  self.class.builder.run Router.new({
    :scope_class    => self.class.scope_class,
    :route_defs     => self.class.route_defs,
    :before_hooks   => self.class.before_hooks,
    :after_hooks    => self.class.after_hooks,
    :fallback       => app
  })

  @app = self.class.builder.to_app
  self.class.after_init_hooks.each {|h| h.call(self, @app)}
end

Class Method Details

.after(&blk) ⇒ Object



56
57
58
# File 'lib/nyny/base.rb', line 56

def after &blk
  after_hooks << Proc.new(&blk)
end

.after_initialize(&blk) ⇒ Object



64
65
66
# File 'lib/nyny/base.rb', line 64

def after_initialize &blk
  after_init_hooks << Proc.new(&blk)
end

.before(&blk) ⇒ Object



52
53
54
# File 'lib/nyny/base.rb', line 52

def before &blk
  before_hooks << Proc.new(&blk)
end

.before_initialize(&blk) ⇒ Object



60
61
62
# File 'lib/nyny/base.rb', line 60

def before_initialize &blk
  before_init_hooks << Proc.new(&blk)
end

.define_route(path, options, &block) ⇒ Object



48
49
50
# File 'lib/nyny/base.rb', line 48

def define_route path, options, &block
  self.route_defs << [path, options, Proc.new(&block)]
end

.helpers(*args, &block) ⇒ Object



79
80
81
82
# File 'lib/nyny/base.rb', line 79

def helpers *args, &block
  args << Module.new(&block) if block_given?
  args.each {|m| scope_class.send :include, m }
end

.register(*extensions) ⇒ Object



72
73
74
75
76
77
# File 'lib/nyny/base.rb', line 72

def register *extensions
  extensions.each do |ext|
    extend ext
    ext.registered(self) if ext.respond_to?(:registered)
  end
end

.use(middleware, *args, &block) ⇒ Object



68
69
70
# File 'lib/nyny/base.rb', line 68

def use middleware, *args, &block
  builder.use middleware, *args, &block
end

Instance Method Details

#call(env) ⇒ Object



34
35
36
# File 'lib/nyny/base.rb', line 34

def call env
  @app.call env
end