Class: ModelController

Inherits:
Object show all
Defined in:
lib/volt/controllers/model_controller.rb

Direct Known Subclasses

Volt::NoticesController

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



65
66
67
# File 'lib/volt/controllers/model_controller.rb', line 65

def method_missing(method_name, *args, &block)
  return @model.send(method_name, *args, &block)      
end

Class Method Details

.model(val) ⇒ Object



2
3
4
# File 'lib/volt/controllers/model_controller.rb', line 2

def self.model(val)
  @@default_model = val
end

.new(*args, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/volt/controllers/model_controller.rb', line 22

def self.new(*args, &block)
  inst = self.allocate
  if @@default_model
    inst.model(@@default_model || :page)
  end
  
  inst.initialize(*args, &block)
  
  return inst
end

Instance Method Details

#channelObject



53
54
55
# File 'lib/volt/controllers/model_controller.rb', line 53

def channel
  $page.channel
end

#controllerObject



61
62
63
# File 'lib/volt/controllers/model_controller.rb', line 61

def controller
  @controller ||= ReactiveValue.new(Model.new)
end

#flashObject



41
42
43
# File 'lib/volt/controllers/model_controller.rb', line 41

def flash
  $page.flash
end

#model(val) ⇒ Object

Sets the current model on this controller



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/volt/controllers/model_controller.rb', line 7

def model(val)
  if val.is_a?(Symbol) || val.is_a?(String)
    collections = [:page, :store, :params]
    if collections.include?(val.to_sym)
      @model = self.send(val)
    else
      raise "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
    end
  elsif model
    @model = model
  else
    raise "model can not be #{model.inspect}"
  end
end

#pageObject



33
34
35
# File 'lib/volt/controllers/model_controller.rb', line 33

def page
  $page.page
end

#paramsObject



45
46
47
# File 'lib/volt/controllers/model_controller.rb', line 45

def params
  $page.params 
end

#storeObject



37
38
39
# File 'lib/volt/controllers/model_controller.rb', line 37

def store
  $page.store
end

#tasksObject



57
58
59
# File 'lib/volt/controllers/model_controller.rb', line 57

def tasks
  $page.tasks
end

#urlObject



49
50
51
# File 'lib/volt/controllers/model_controller.rb', line 49

def url
  $page.url 
end