class AutoForme::Framework

  1. lib/autoforme/framework.rb
Superclass: Object

The Framework class contains forms for a set of models, tied to web framework controller.

Attributes

controller [R]

The web framework controller tied to this framework.

model_classes [R]

A map of underlying model classes to AutoForme::Model classes for this Framework.

models [R]

A map of link names to AutoForme::Model classes for this Framework.

opts [R]

The configuration options related to this framework.

prefix [R]

The path prefix that this framework is mounted at

Public Class methods

for (type, controller, opts={}, &block)

See Autoforme.for.

[show source]
# File lib/autoforme/framework.rb, line 9
def self.for(type, controller, opts={}, &block)
  AutoForme.framework_class_for(type).setup(controller, opts, &block)
end
new (controller, opts={})
[show source]
# File lib/autoforme/framework.rb, line 44
def initialize(controller, opts={})
  @controller = controller
  @opts = opts.dup
  @prefix = @opts[:prefix]
  @models = {}
  @model_classes = {}
end
setup (controller, opts, &block)

Setup a new framework class.

[show source]
# File lib/autoforme/framework.rb, line 14
def self.setup(controller, opts, &block)
  f = new(controller, opts)
  f.model_type :sequel
  f.instance_exec(&block)
  f
end

Public Instance methods

action_for (request)

Return the action related to the given request, if such an action is supported.

[show source]
# File lib/autoforme/framework.rb, line 157
def action_for(request)
  if model = @models[request.model]
    action = Action.new(model, request)
    action if action.supported?
  end
end
autocomplete_options_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 112
def autocomplete_options_for(model, type, request)
  handle_proc(autocomplete_options, model, type, request)
end
columns_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 64
def columns_for(model, type, request)
  handle_proc(columns, model, type, request)
end
display_name_for (model)
[show source]
# File lib/autoforme/framework.rb, line 88
def display_name_for(model)
  handle_proc(display_name, model)
end
edit_html_for (obj, column, type, request)
[show source]
# File lib/autoforme/framework.rb, line 124
def edit_html_for(obj, column, type, request)
  handle_proc(edit_html, obj, column, type, request)
end
filter_for (model)
[show source]
# File lib/autoforme/framework.rb, line 80
def filter_for(model)
  handle_proc(filter, model)
end
form_attributes_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 92
def form_attributes_for(model, type, request)
  handle_proc(form_attributes, model, type, request) || {}
end
form_options_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 96
def form_options_for(model, type, request)
  handle_proc(form_options, model, type, request) || {}
end
inline_mtm_associations_for (model, request)
[show source]
# File lib/autoforme/framework.rb, line 72
def inline_mtm_associations_for(model, request)
  handle_proc(inline_mtm_associations, model, request)
end
limit_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 60
def limit_for(model, type, request)
  handle_proc(per_page, model, type, request)
end
model (model_class, &block)

Add a new model to the existing framework.

[show source]
# File lib/autoforme/framework.rb, line 147
def model(model_class, &block)
  if register_by_name?
    model_class = model_class.name
  end
  model = @model_classes[model_class] = Model.for(self, model_type, model_class, &block)
  @models[model.link] = model
end
model_class (model_class)

Look up the Autoforme::Model class to use for the underlying model class instance.

[show source]
# File lib/autoforme/framework.rb, line 139
def model_class(model_class)
  if register_by_name?
    model_class = model_class.name
  end
  @model_classes[model_class]
end
mtm_associations_for (model, request)
[show source]
# File lib/autoforme/framework.rb, line 68
def mtm_associations_for(model, request)
  handle_proc(mtm_associations, model, request)
end
order_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 76
def order_for(model, type, request)
  handle_proc(order, model, type, request)
end
page_header_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 104
def page_header_for(model, type, request)
  handle_proc(page_header, model, type, request)
end
redirect_for (model)
[show source]
# File lib/autoforme/framework.rb, line 84
def redirect_for(model)
  handle_proc(redirect, model)
end
register_by_name (register=true)

Set whether to register classes by name instead of by reference

[show source]
# File lib/autoforme/framework.rb, line 129
def register_by_name(register=true)
  opts[:register_by_name] = register
end
register_by_name? ()

Whether to register classes by name instead of by reference

[show source]
# File lib/autoforme/framework.rb, line 134
def register_by_name?
  opts[:register_by_name]
end
show_html_for (obj, column, type, request)
[show source]
# File lib/autoforme/framework.rb, line 120
def show_html_for(obj, column, type, request)
  handle_proc(show_html, obj, column, type, request)
end
supported_actions_for (model, request)
[show source]
# File lib/autoforme/framework.rb, line 52
def supported_actions_for(model, request)
  handle_proc(supported_actions, model, request)
end
table_class_for (model, type, request)
[show source]
# File lib/autoforme/framework.rb, line 56
def table_class_for(model, type, request)
  handle_proc(table_class, model, type, request)
end