Class: Nested::App

Inherits:
Object
  • Object
show all
Extended by:
WithMany, WithSingleton
Defined in:
lib/nested/app.rb

Class Method Summary collapse

Methods included from WithSingleton

singleton, singleton_if

Methods included from WithMany

many, many_if

Class Method Details

.after(&block) ⇒ Object



38
39
40
41
# File 'lib/nested/app.rb', line 38

def self.after(&block)
  sinatra.after(&block)
  self
end

.before(&block) ⇒ Object



33
34
35
36
# File 'lib/nested/app.rb', line 33

def self.before(&block)
  sinatra.before(&block)
  self
end

.behavior(name, &block) ⇒ Object



13
14
15
16
# File 'lib/nested/app.rb', line 13

def self.behavior(name, &block)
  @behaviors[name] = block
  self
end

.child_resource(name, clazz, resource_if_block, model_block, &block) ⇒ Object



28
29
30
31
# File 'lib/nested/app.rb', line 28

def self.child_resource(name, clazz, resource_if_block, model_block, &block)
   clazz.new(self, sinatra, name, nil, resource_if_block, model_block)
        .tap{|r| r.instance_eval(&(block||Proc.new{ }))}
end

.condition(name, block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/nested/app.rb', line 18

def self.condition(name, block)
  @conditions[name] = block

  @sinatra.send(:define_method, :"#{name}?") do
    instance_exec(&block)
  end

  self
end

.config(opts = {}) ⇒ Object



43
44
45
# File 'lib/nested/app.rb', line 43

def self.config(opts={})
  @config.tap{|c| c.merge!(opts)}
end

.inherited(clazz) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/nested/app.rb', line 3

def self.inherited(clazz)
  (class << clazz; self; end).instance_eval do
    attr_accessor :sinatra, :behaviors, :conditions
  end
  clazz.sinatra = Class.new(Sinatra::Base)
  clazz.instance_variable_set("@config", {})
  clazz.instance_variable_set("@behaviors", {})
  clazz.instance_variable_set("@conditions", {})
end