class AutoForme::Framework
The Framework
class contains forms for a set of models, tied to web framework controller.
Attributes
The web framework controller tied to this framework.
A map of underlying model classes to AutoForme::Model
classes for this Framework
.
A map of link names to AutoForme::Model
classes for this Framework
.
The configuration options related to this framework.
The path prefix that this framework is mounted at
Public Class Methods
See Autoforme.for.
# File lib/autoforme/framework.rb 10 def self.for(type, controller, opts={}, &block) 11 AutoForme.framework_class_for(type).setup(controller, opts, &block) 12 end
# File lib/autoforme/framework.rb 45 def initialize(controller, opts={}) 46 @controller = controller 47 @opts = opts.dup 48 @prefix = @opts[:prefix] 49 @models = {} 50 @model_classes = {} 51 end
Setup a new framework class.
# File lib/autoforme/framework.rb 15 def self.setup(controller, opts, &block) 16 f = new(controller, opts) 17 f.model_type :sequel 18 f.instance_exec(&block) 19 f 20 end
Public Instance Methods
Return the action related to the given request, if such an action is supported.
# File lib/autoforme/framework.rb 158 def action_for(request) 159 if model = @models[request.model] 160 action = Action.new(model, request) 161 action if action.supported? 162 end 163 end
# File lib/autoforme/framework.rb 117 def association_links_for(model, type, request) 118 handle_proc(association_links, model, type, request) 119 end
# File lib/autoforme/framework.rb 113 def autocomplete_options_for(model, type, request) 114 handle_proc(autocomplete_options, model, type, request) 115 end
# File lib/autoforme/framework.rb 65 def columns_for(model, type, request) 66 handle_proc(columns, model, type, request) 67 end
# File lib/autoforme/framework.rb 89 def display_name_for(model) 90 handle_proc(display_name, model) 91 end
# File lib/autoforme/framework.rb 125 def edit_html_for(obj, column, type, request) 126 handle_proc(edit_html, obj, column, type, request) 127 end
# File lib/autoforme/framework.rb 81 def filter_for(model) 82 handle_proc(filter, model) 83 end
# File lib/autoforme/framework.rb 93 def form_attributes_for(model, type, request) 94 handle_proc(form_attributes, model, type, request) || {} 95 end
# File lib/autoforme/framework.rb 97 def form_options_for(model, type, request) 98 handle_proc(form_options, model, type, request) || {} 99 end
# File lib/autoforme/framework.rb 73 def inline_mtm_associations_for(model, request) 74 handle_proc(inline_mtm_associations, model, request) 75 end
# File lib/autoforme/framework.rb 109 def lazy_load_association_links?(model, type, request) 110 handle_proc(lazy_load_association_links, model, type, request) 111 end
# File lib/autoforme/framework.rb 61 def limit_for(model, type, request) 62 handle_proc(per_page, model, type, request) 63 end
Add a new model to the existing framework.
# File lib/autoforme/framework.rb 148 def model(model_class, &block) 149 if register_by_name? 150 model_class = model_class.name 151 end 152 model = @model_classes[model_class] = Model.for(self, model_type, model_class, &block) 153 @models[model.link] = model 154 end
Look up the Autoforme::Model class to use for the underlying model class instance.
# File lib/autoforme/framework.rb 140 def model_class(model_class) 141 if register_by_name? 142 model_class = model_class.name 143 end 144 @model_classes[model_class] 145 end
# File lib/autoforme/framework.rb 69 def mtm_associations_for(model, request) 70 handle_proc(mtm_associations, model, request) 71 end
# File lib/autoforme/framework.rb 77 def order_for(model, type, request) 78 handle_proc(order, model, type, request) 79 end
# File lib/autoforme/framework.rb 105 def page_header_for(model, type, request) 106 handle_proc(page_header, model, type, request) 107 end
# File lib/autoforme/framework.rb 85 def redirect_for(model) 86 handle_proc(redirect, model) 87 end
Set whether to register classes by name instead of by reference
# File lib/autoforme/framework.rb 130 def register_by_name(register=true) 131 opts[:register_by_name] = register 132 end
Whether to register classes by name instead of by reference
# File lib/autoforme/framework.rb 135 def register_by_name? 136 opts[:register_by_name] 137 end
# File lib/autoforme/framework.rb 121 def show_html_for(obj, column, type, request) 122 handle_proc(show_html, obj, column, type, request) 123 end
# File lib/autoforme/framework.rb 53 def supported_actions_for(model, request) 54 handle_proc(supported_actions, model, request) 55 end
# File lib/autoforme/framework.rb 57 def table_class_for(model, type, request) 58 handle_proc(table_class, model, type, request) 59 end
Private Instance Methods
# File lib/autoforme/framework.rb 167 def handle_proc(v, *a) 168 case v 169 when Proc, Method 170 v.call(*a) 171 else 172 v 173 end 174 end