Class: Volt::ModelController
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Constructor Details
Returns a new instance of ModelController.
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/volt/controllers/model_controller.rb', line 54
def initialize(*args)
if args[0]
self.attrs = args[0]
if attrs.respond_to?(:model)
self.model = attrs.locals[:model]
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'lib/volt/controllers/model_controller.rb', line 124
def method_missing(method_name, *args, &block)
model = self.model
if model
model.send(method_name, *args, &block)
else
super
end
end
|
Instance Attribute Details
Returns the value of attribute attrs.
52
53
54
|
# File 'lib/volt/controllers/model_controller.rb', line 52
def attrs
@attrs
end
|
Class Method Details
.model(val) ⇒ Object
9
10
11
|
# File 'lib/volt/controllers/model_controller.rb', line 9
def self.model(val)
@default_model = val
end
|
.new(*args, &block) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/volt/controllers/model_controller.rb', line 41
def self.new(*args, &block)
inst = allocate
inst.model = @default_model if @default_model
inst.send(:initialize, *args, &block)
inst
end
|
Instance Method Details
99
100
101
|
# File 'lib/volt/controllers/model_controller.rb', line 99
def channel
$page.channel
end
|
#controller ⇒ Object
107
108
109
|
# File 'lib/volt/controllers/model_controller.rb', line 107
def controller
@controller ||= Model.new
end
|
91
92
93
|
# File 'lib/volt/controllers/model_controller.rb', line 91
def cookies
$page.cookies
end
|
79
80
81
|
# File 'lib/volt/controllers/model_controller.rb', line 79
def flash
$page.flash
end
|
Change the url params, similar to redirecting to a new url
67
68
69
|
# File 'lib/volt/controllers/model_controller.rb', line 67
def go(url)
self.url.parse(url)
end
|
111
112
113
|
# File 'lib/volt/controllers/model_controller.rb', line 111
def loaded?
respond_to?(:state) && state == :loaded
end
|
#local_store ⇒ Object
87
88
89
|
# File 'lib/volt/controllers/model_controller.rb', line 87
def local_store
$page.local_store
end
|
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/volt/controllers/model_controller.rb', line 30
def model
model = self.current_model
if model.is_a?(Proc)
model = model.call
end
model
end
|
#model=(val) ⇒ Object
Sets the current model on this controller
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/volt/controllers/model_controller.rb', line 14
def model=(val)
self.current_model ||= Model.new
if Symbol === val || String === val
collections = [:page, :store, :params, :controller]
if collections.include?(val.to_sym)
self.current_model = send(val)
else
fail "#{val} is not the name of a valid model, choose from: #{collections.join(', ')}"
end
else
self.current_model = val
end
end
|
71
72
73
|
# File 'lib/volt/controllers/model_controller.rb', line 71
def page
$page.page
end
|
83
84
85
|
# File 'lib/volt/controllers/model_controller.rb', line 83
def params
$page.params
end
|
#respond_to?(method_name) ⇒ Boolean
Check if this controller responds_to method, or the model
116
117
118
119
120
121
122
|
# File 'lib/volt/controllers/model_controller.rb', line 116
def respond_to?(method_name)
super || begin
model = self.model
model.respond_to?(method_name) if model
end
end
|
75
76
77
|
# File 'lib/volt/controllers/model_controller.rb', line 75
def store
$page.store
end
|
103
104
105
|
# File 'lib/volt/controllers/model_controller.rb', line 103
def tasks
$page.tasks
end
|
95
96
97
|
# File 'lib/volt/controllers/model_controller.rb', line 95
def url
$page.url
end
|