Class: ModelController

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModelController

Returns a new instance of ModelController.



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

def initialize
  self.model = @@default_model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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

Class Method Details

.model(val) ⇒ Object



6
7
8
# File 'lib/volt/controllers/model_controller.rb', line 6

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

Instance Method Details

#channelObject



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

def channel
  $page.channel
end

#controllerObject



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

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

#model=(val) ⇒ Object

Sets the current model on this controller



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/volt/controllers/model_controller.rb', line 11

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
  else
    @model = model
  end
end

#pageObject



24
25
26
# File 'lib/volt/controllers/model_controller.rb', line 24

def page
  $page.page
end

#paramsObject



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

def params
  $page.params 
end

#storeObject



28
29
30
# File 'lib/volt/controllers/model_controller.rb', line 28

def store
  $page.store
end

#tasksObject



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

def tasks
  $page.tasks
end

#urlObject



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

def url
  $page.url 
end