Class: AutoForme::Framework
- Inherits:
-
Object
- Object
- AutoForme::Framework
show all
- Extended by:
- OptsAttributes
- Defined in:
- lib/autoforme/framework.rb
Overview
The Framework class contains forms for a set of models, tied to web
framework controller.
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
The web framework controller tied to this framework.
-
#model_classes ⇒ Object
readonly
A map of underlying model classes to AutoForme::Model classes for this Framework.
-
#models ⇒ Object
readonly
A map of link names to AutoForme::Model classes for this Framework.
-
#opts ⇒ Object
readonly
The configuration options related to this framework.
-
#prefix ⇒ Object
readonly
The path prefix that this framework is mounted at.
Class Method Summary
collapse
Instance Method Summary
collapse
-
#action_for(request) ⇒ Object
Return the action related to the given request, if such an action is supported.
-
#association_links_for(model, type, request) ⇒ Object
-
#autocomplete_options_for(model, type, request) ⇒ Object
-
#columns_for(model, type, request) ⇒ Object
-
#display_name_for(model) ⇒ Object
-
#filter_for(model) ⇒ Object
-
#form_attributes_for(model, type, request) ⇒ Object
-
#form_options_for(model, type, request) ⇒ Object
-
#initialize(controller, opts = {}) ⇒ Framework
constructor
A new instance of Framework.
-
#inline_mtm_associations_for(model, request) ⇒ Object
-
#lazy_load_association_links?(model, type, request) ⇒ Boolean
-
#limit_for(model, type, request) ⇒ Object
-
#model(model_class, &block) ⇒ Object
Add a new model to the existing framework.
-
#mtm_associations_for(model, request) ⇒ Object
-
#order_for(model, type, request) ⇒ Object
-
#page_footer_for(model, type, request) ⇒ Object
-
#page_header_for(model, type, request) ⇒ Object
-
#redirect_for(model) ⇒ Object
-
#supported_actions_for(model, request) ⇒ Object
-
#table_class_for(model, type, request) ⇒ Object
opts_attribute
Constructor Details
#initialize(controller, opts = {}) ⇒ Framework
Returns a new instance of Framework.
42
43
44
45
46
47
48
|
# File 'lib/autoforme/framework.rb', line 42
def initialize(controller, opts={})
@controller = controller
@opts = opts.dup
@prefix = @opts[:prefix]
@models = {}
@model_classes = {}
end
|
Instance Attribute Details
#controller ⇒ Object
The web framework controller tied to this framework.
20
21
22
|
# File 'lib/autoforme/framework.rb', line 20
def controller
@controller
end
|
#model_classes ⇒ Object
A map of underlying model classes to AutoForme::Model classes for this Framework.
26
27
28
|
# File 'lib/autoforme/framework.rb', line 26
def model_classes
@model_classes
end
|
#models ⇒ Object
A map of link names to AutoForme::Model classes for this Framework.
23
24
25
|
# File 'lib/autoforme/framework.rb', line 23
def models
@models
end
|
#opts ⇒ Object
The configuration options related to this framework.
29
30
31
|
# File 'lib/autoforme/framework.rb', line 29
def opts
@opts
end
|
#prefix ⇒ Object
The path prefix that this framework is mounted at
32
33
34
|
# File 'lib/autoforme/framework.rb', line 32
def prefix
@prefix
end
|
Class Method Details
.for(type, controller, opts = {}, &block) ⇒ Object
8
9
10
|
# File 'lib/autoforme/framework.rb', line 8
def self.for(type, controller, opts={}, &block)
AutoForme.framework_class_for(type).setup(controller, opts, &block)
end
|
.setup(controller, opts, &block) ⇒ Object
Setup a new framework class.
13
14
15
16
17
|
# File 'lib/autoforme/framework.rb', line 13
def self.setup(controller, opts, &block)
f = new(controller, opts)
f.instance_exec(&block)
f
end
|
Instance Method Details
#action_for(request) ⇒ Object
Return the action related to the given request, if such an
action is supported.
127
128
129
130
131
132
|
# File 'lib/autoforme/framework.rb', line 127
def action_for(request)
if model = @models[request.model]
action = Action.new(model, request)
action if action.supported?
end
end
|
#association_links_for(model, type, request) ⇒ Object
114
115
116
|
# File 'lib/autoforme/framework.rb', line 114
def association_links_for(model, type, request)
handle_proc(association_links, model, type, request)
end
|
#autocomplete_options_for(model, type, request) ⇒ Object
110
111
112
|
# File 'lib/autoforme/framework.rb', line 110
def autocomplete_options_for(model, type, request)
handle_proc(autocomplete_options, model, type, request)
end
|
#columns_for(model, type, request) ⇒ Object
62
63
64
|
# File 'lib/autoforme/framework.rb', line 62
def columns_for(model, type, request)
handle_proc(columns, model, type, request)
end
|
#display_name_for(model) ⇒ Object
86
87
88
|
# File 'lib/autoforme/framework.rb', line 86
def display_name_for(model)
handle_proc(display_name, model)
end
|
#filter_for(model) ⇒ Object
78
79
80
|
# File 'lib/autoforme/framework.rb', line 78
def filter_for(model)
handle_proc(filter, model)
end
|
90
91
92
|
# File 'lib/autoforme/framework.rb', line 90
def form_attributes_for(model, type, request)
handle_proc(form_attributes, model, type, request) || {}
end
|
94
95
96
|
# File 'lib/autoforme/framework.rb', line 94
def form_options_for(model, type, request)
handle_proc(form_options, model, type, request) || {}
end
|
#inline_mtm_associations_for(model, request) ⇒ Object
70
71
72
|
# File 'lib/autoforme/framework.rb', line 70
def inline_mtm_associations_for(model, request)
handle_proc(inline_mtm_associations, model, request)
end
|
#lazy_load_association_links?(model, type, request) ⇒ Boolean
106
107
108
|
# File 'lib/autoforme/framework.rb', line 106
def lazy_load_association_links?(model, type, request)
handle_proc(lazy_load_association_links, model, type, request)
end
|
#limit_for(model, type, request) ⇒ Object
58
59
60
|
# File 'lib/autoforme/framework.rb', line 58
def limit_for(model, type, request)
handle_proc(per_page, model, type, request)
end
|
#model(model_class, &block) ⇒ Object
Add a new model to the existing framework.
119
120
121
122
123
|
# File 'lib/autoforme/framework.rb', line 119
def model(model_class, &block)
model = Model.for(self, model_type, model_class, &block)
@model_classes[model.model] = model
@models[model.link] = model
end
|
#mtm_associations_for(model, request) ⇒ Object
66
67
68
|
# File 'lib/autoforme/framework.rb', line 66
def mtm_associations_for(model, request)
handle_proc(mtm_associations, model, request)
end
|
#order_for(model, type, request) ⇒ Object
74
75
76
|
# File 'lib/autoforme/framework.rb', line 74
def order_for(model, type, request)
handle_proc(order, model, type, request)
end
|
98
99
100
|
# File 'lib/autoforme/framework.rb', line 98
def (model, type, request)
handle_proc(, model, type, request)
end
|
102
103
104
|
# File 'lib/autoforme/framework.rb', line 102
def (model, type, request)
handle_proc(, model, type, request)
end
|
#redirect_for(model) ⇒ Object
82
83
84
|
# File 'lib/autoforme/framework.rb', line 82
def redirect_for(model)
handle_proc(redirect, model)
end
|
#supported_actions_for(model, request) ⇒ Object
50
51
52
|
# File 'lib/autoforme/framework.rb', line 50
def supported_actions_for(model, request)
handle_proc(supported_actions, model, request)
end
|
#table_class_for(model, type, request) ⇒ Object
54
55
56
|
# File 'lib/autoforme/framework.rb', line 54
def table_class_for(model, type, request)
handle_proc(table_class, model, type, request)
end
|