Class: ModelController
- Inherits:
-
Object
show all
- Defined in:
- lib/volt/controllers/model_controller.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ModelController.
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/volt/controllers/model_controller.rb', line 39
def initialize(*args)
if args.size > 0
args[0].each_pair do |key, value|
instance_variable_set(:"@#{key}", value)
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
91
92
93
|
# File 'lib/volt/controllers/model_controller.rb', line 91
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
29
30
31
32
33
34
35
36
37
|
# File 'lib/volt/controllers/model_controller.rb', line 29
def self.new(*args, &block)
inst = self.allocate
inst.model = (@default_model || :controller)
inst.initialize(*args, &block)
return inst
end
|
Instance Method Details
79
80
81
|
# File 'lib/volt/controllers/model_controller.rb', line 79
def channel
$page.channel
end
|
#controller ⇒ Object
87
88
89
|
# File 'lib/volt/controllers/model_controller.rb', line 87
def controller
@controller ||= ReactiveValue.new(Model.new)
end
|
67
68
69
|
# File 'lib/volt/controllers/model_controller.rb', line 67
def flash
$page.flash
end
|
Change the url params, similar to redirecting to a new url
51
52
53
|
# File 'lib/volt/controllers/model_controller.rb', line 51
def go(url)
self.url.parse(url)
end
|
25
26
27
|
# File 'lib/volt/controllers/model_controller.rb', line 25
def model
@model
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
21
22
23
|
# File 'lib/volt/controllers/model_controller.rb', line 7
def model=(val)
@model ||= ReactiveValue.new(Proc.new { nil })
if Symbol === val || String === val
collections = [:page, :store, :params, :controller]
if collections.include?(val.to_sym)
@model.cur = self.send(val).cur
else
raise "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
end
elsif val
@model.cur = val.cur
else
raise "model can not be #{val.inspect}"
end
end
|
55
56
57
|
# File 'lib/volt/controllers/model_controller.rb', line 55
def page
$page.page
end
|
59
60
61
|
# File 'lib/volt/controllers/model_controller.rb', line 59
def paged
$page.page
end
|
71
72
73
|
# File 'lib/volt/controllers/model_controller.rb', line 71
def params
$page.params
end
|
63
64
65
|
# File 'lib/volt/controllers/model_controller.rb', line 63
def store
$page.store
end
|
83
84
85
|
# File 'lib/volt/controllers/model_controller.rb', line 83
def tasks
$page.tasks
end
|
75
76
77
|
# File 'lib/volt/controllers/model_controller.rb', line 75
def url
$page.url
end
|