Class: AutoForme::Framework

Inherits:
Object
  • Object
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptsAttributes

opts_attribute

Constructor Details

#initialize(controller, opts = {}) ⇒ Framework

Returns a new instance of Framework.



45
46
47
48
49
50
51
# File 'lib/autoforme/framework.rb', line 45

def initialize(controller, opts={})
  @controller = controller
  @opts = opts.dup
  @prefix = @opts[:prefix]
  @models = {}
  @model_classes = {}
end

Instance Attribute Details

#controllerObject (readonly)

The web framework controller tied to this framework.



23
24
25
# File 'lib/autoforme/framework.rb', line 23

def controller
  @controller
end

#model_classesObject (readonly)

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



29
30
31
# File 'lib/autoforme/framework.rb', line 29

def model_classes
  @model_classes
end

#modelsObject (readonly)

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



26
27
28
# File 'lib/autoforme/framework.rb', line 26

def models
  @models
end

#optsObject (readonly)

The configuration options related to this framework.



32
33
34
# File 'lib/autoforme/framework.rb', line 32

def opts
  @opts
end

#prefixObject (readonly)

The path prefix that this framework is mounted at



35
36
37
# File 'lib/autoforme/framework.rb', line 35

def prefix
  @prefix
end

Class Method Details

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

See Autoforme.for.



10
11
12
# File 'lib/autoforme/framework.rb', line 10

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.



15
16
17
18
19
20
# File 'lib/autoforme/framework.rb', line 15

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.



158
159
160
161
162
163
# File 'lib/autoforme/framework.rb', line 158

def action_for(request)
  if model = @models[request.model]
    action = Action.new(model, request)
    action if action.supported?
  end
end


117
118
119
# File 'lib/autoforme/framework.rb', line 117

def association_links_for(model, type, request)
  handle_proc(association_links, model, type, request)
end

#autocomplete_options_for(model, type, request) ⇒ Object



113
114
115
# File 'lib/autoforme/framework.rb', line 113

def autocomplete_options_for(model, type, request)
  handle_proc(autocomplete_options, model, type, request)
end

#columns_for(model, type, request) ⇒ Object



65
66
67
# File 'lib/autoforme/framework.rb', line 65

def columns_for(model, type, request)
  handle_proc(columns, model, type, request)
end

#display_name_for(model) ⇒ Object



89
90
91
# File 'lib/autoforme/framework.rb', line 89

def display_name_for(model)
  handle_proc(display_name, model)
end

#edit_html_for(obj, column, type, request) ⇒ Object



125
126
127
# File 'lib/autoforme/framework.rb', line 125

def edit_html_for(obj, column, type, request)
  handle_proc(edit_html, obj, column, type, request)
end

#filter_for(model) ⇒ Object



81
82
83
# File 'lib/autoforme/framework.rb', line 81

def filter_for(model)
  handle_proc(filter, model)
end

#form_attributes_for(model, type, request) ⇒ Object



93
94
95
# File 'lib/autoforme/framework.rb', line 93

def form_attributes_for(model, type, request)
  handle_proc(form_attributes, model, type, request) || {}
end

#form_options_for(model, type, request) ⇒ Object



97
98
99
# File 'lib/autoforme/framework.rb', line 97

def form_options_for(model, type, request)
  handle_proc(form_options, model, type, request) || {}
end

#inline_mtm_associations_for(model, request) ⇒ Object



73
74
75
# File 'lib/autoforme/framework.rb', line 73

def inline_mtm_associations_for(model, request)
  handle_proc(inline_mtm_associations, model, request)
end

#lazy_load_association_links?(model, type, request) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/autoforme/framework.rb', line 109

def lazy_load_association_links?(model, type, request)
  handle_proc(lazy_load_association_links, model, type, request)
end

#limit_for(model, type, request) ⇒ Object



61
62
63
# File 'lib/autoforme/framework.rb', line 61

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.



148
149
150
151
152
153
154
# File 'lib/autoforme/framework.rb', line 148

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) ⇒ Object

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



140
141
142
143
144
145
# File 'lib/autoforme/framework.rb', line 140

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) ⇒ Object



69
70
71
# File 'lib/autoforme/framework.rb', line 69

def mtm_associations_for(model, request)
  handle_proc(mtm_associations, model, request)
end

#order_for(model, type, request) ⇒ Object



77
78
79
# File 'lib/autoforme/framework.rb', line 77

def order_for(model, type, request)
  handle_proc(order, model, type, request)
end


101
102
103
# File 'lib/autoforme/framework.rb', line 101

def page_footer_for(model, type, request)
  handle_proc(page_footer, model, type, request)
end

#page_header_for(model, type, request) ⇒ Object



105
106
107
# File 'lib/autoforme/framework.rb', line 105

def page_header_for(model, type, request)
  handle_proc(page_header, model, type, request)
end

#redirect_for(model) ⇒ Object



85
86
87
# File 'lib/autoforme/framework.rb', line 85

def redirect_for(model)
  handle_proc(redirect, model)
end

#register_by_name(register = true) ⇒ Object

Set whether to register classes by name instead of by reference



130
131
132
# File 'lib/autoforme/framework.rb', line 130

def register_by_name(register=true)
  opts[:register_by_name] = register
end

#register_by_name?Boolean

Whether to register classes by name instead of by reference

Returns:

  • (Boolean)


135
136
137
# File 'lib/autoforme/framework.rb', line 135

def register_by_name?
  opts[:register_by_name]
end

#show_html_for(obj, column, type, request) ⇒ Object



121
122
123
# File 'lib/autoforme/framework.rb', line 121

def show_html_for(obj, column, type, request)
  handle_proc(show_html, obj, column, type, request)
end

#supported_actions_for(model, request) ⇒ Object



53
54
55
# File 'lib/autoforme/framework.rb', line 53

def supported_actions_for(model, request)
  handle_proc(supported_actions, model, request)
end

#table_class_for(model, type, request) ⇒ Object



57
58
59
# File 'lib/autoforme/framework.rb', line 57

def table_class_for(model, type, request)
  handle_proc(table_class, model, type, request)
end