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.
43
44
45
46
47
48
49
|
# File 'lib/autoforme/framework.rb', line 43
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.
21
22
23
|
# File 'lib/autoforme/framework.rb', line 21
def controller
@controller
end
|
#model_classes ⇒ Object
A map of underlying model classes to AutoForme::Model classes for this Framework.
27
28
29
|
# File 'lib/autoforme/framework.rb', line 27
def model_classes
@model_classes
end
|
#models ⇒ Object
A map of link names to AutoForme::Model classes for this Framework.
24
25
26
|
# File 'lib/autoforme/framework.rb', line 24
def models
@models
end
|
#opts ⇒ Object
The configuration options related to this framework.
30
31
32
|
# File 'lib/autoforme/framework.rb', line 30
def opts
@opts
end
|
#prefix ⇒ Object
The path prefix that this framework is mounted at
33
34
35
|
# File 'lib/autoforme/framework.rb', line 33
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
18
|
# File 'lib/autoforme/framework.rb', line 13
def self.setup(controller, opts, &block)
f = new(controller, opts)
f.model_type :sequel
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.
128
129
130
131
132
133
|
# File 'lib/autoforme/framework.rb', line 128
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
115
116
117
|
# File 'lib/autoforme/framework.rb', line 115
def association_links_for(model, type, request)
handle_proc(association_links, model, type, request)
end
|
#autocomplete_options_for(model, type, request) ⇒ Object
111
112
113
|
# File 'lib/autoforme/framework.rb', line 111
def autocomplete_options_for(model, type, request)
handle_proc(autocomplete_options, model, type, request)
end
|
#columns_for(model, type, request) ⇒ Object
63
64
65
|
# File 'lib/autoforme/framework.rb', line 63
def columns_for(model, type, request)
handle_proc(columns, model, type, request)
end
|
#display_name_for(model) ⇒ Object
87
88
89
|
# File 'lib/autoforme/framework.rb', line 87
def display_name_for(model)
handle_proc(display_name, model)
end
|
#filter_for(model) ⇒ Object
79
80
81
|
# File 'lib/autoforme/framework.rb', line 79
def filter_for(model)
handle_proc(filter, model)
end
|
91
92
93
|
# File 'lib/autoforme/framework.rb', line 91
def form_attributes_for(model, type, request)
handle_proc(form_attributes, model, type, request) || {}
end
|
95
96
97
|
# File 'lib/autoforme/framework.rb', line 95
def form_options_for(model, type, request)
handle_proc(form_options, model, type, request) || {}
end
|
#inline_mtm_associations_for(model, request) ⇒ Object
71
72
73
|
# File 'lib/autoforme/framework.rb', line 71
def inline_mtm_associations_for(model, request)
handle_proc(inline_mtm_associations, model, request)
end
|
#lazy_load_association_links?(model, type, request) ⇒ Boolean
107
108
109
|
# File 'lib/autoforme/framework.rb', line 107
def lazy_load_association_links?(model, type, request)
handle_proc(lazy_load_association_links, model, type, request)
end
|
#limit_for(model, type, request) ⇒ Object
59
60
61
|
# File 'lib/autoforme/framework.rb', line 59
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.
120
121
122
123
124
|
# File 'lib/autoforme/framework.rb', line 120
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
67
68
69
|
# File 'lib/autoforme/framework.rb', line 67
def mtm_associations_for(model, request)
handle_proc(mtm_associations, model, request)
end
|
#order_for(model, type, request) ⇒ Object
75
76
77
|
# File 'lib/autoforme/framework.rb', line 75
def order_for(model, type, request)
handle_proc(order, model, type, request)
end
|
99
100
101
|
# File 'lib/autoforme/framework.rb', line 99
def (model, type, request)
handle_proc(, model, type, request)
end
|
103
104
105
|
# File 'lib/autoforme/framework.rb', line 103
def (model, type, request)
handle_proc(, model, type, request)
end
|
#redirect_for(model) ⇒ Object
83
84
85
|
# File 'lib/autoforme/framework.rb', line 83
def redirect_for(model)
handle_proc(redirect, model)
end
|
#supported_actions_for(model, request) ⇒ Object
51
52
53
|
# File 'lib/autoforme/framework.rb', line 51
def supported_actions_for(model, request)
handle_proc(supported_actions, model, request)
end
|
#table_class_for(model, type, request) ⇒ Object
55
56
57
|
# File 'lib/autoforme/framework.rb', line 55
def table_class_for(model, type, request)
handle_proc(table_class, model, type, request)
end
|