Module: Rear

Defined in:
lib/rear/rear.rb

Class Method Summary collapse

Class Method Details

.appObject Also known as: to_app, mount!



59
60
61
# File 'lib/rear/rear.rb', line 59

def app
  @app ||= E.new.mount(controllers)
end

.call(env) ⇒ Object



65
66
67
# File 'lib/rear/rear.rb', line 65

def call env
  app.call env
end

.controllersObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rear/rear.rb', line 21

def controllers
  @controllers ||= begin
    MODELS.each_pair do |model,procs|
      model = RearUtils.extract_constant(model)
      controller = RearUtils.initialize_model_controller(model)
      procs.compact.each {|proc| controller.class_exec(model, &proc)}
      CONTROLLERS << controller
    end
    CONTROLLERS.uniq.each do |controller|
      controller.model && controller.assocs.each_value do |assocs|
        assocs.each_value do |assoc|
          if remote_model = assoc[:remote_model]
            CONTROLLERS << RearUtils.associated_model_controller(remote_model)
          end
        end
      end
    end
    MODELS.clear.freeze
    CONTROLLERS.unshift RearHomeController
    CONTROLLERS.uniq!
    CONTROLLERS.freeze
  end
end

.included(base) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/rear/rear.rb', line 12

def included base
  if EUtils.is_app?(base)
    RearControllerSetup.init(base)
    CONTROLLERS << base
  else
    raise ArgumentError, '%s is not a Espresso controller' % base
  end
end


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rear/rear.rb', line 45

def menu
  @menu ||= begin
    containers  = {}
    controllers = Rear.controllers.reject {|c| c == RearHomeController}.
      select {|c| c.label}.inject({}) do |f,c|
        c.menu_group? ?
          ((containers[c.menu_group] ||= []).push(c); f) : f.merge(c=>[c])
    end
    controllers.merge(containers).sort do |a,b|
      b.last.inject(0) {|t,c| t += c.position} <=> a.last.inject(0) {|t,c| t += c.position}
    end
  end
end

.register(*models, &proc) ⇒ Object Also known as: setup



5
6
7
8
9
# File 'lib/rear/rear.rb', line 5

def register *models, &proc
  models.flatten.each do |model|
    (MODELS[model] ||= []).push(proc)
  end
end

.run(*args) ⇒ Object



69
70
71
# File 'lib/rear/rear.rb', line 69

def run *args
  app.run *args
end