Module: Engine2::MetaModelSupport
- Included in:
- DecodeMeta, FormMeta, MetaApproveSupport, MetaBulkDeleteSupport, MetaDeleteSupport, MetaListSupport, MetaViewSupport, StarToManyLinkMeta, StarToManyUnlinkMetaBase
- Defined in:
- lib/engine2/meta.rb
Instance Method Summary collapse
-
#action_defined ⇒ Object
while prnt && prnt.*.assets == model prnt = prnt.parent end m = prnt.*.assets m ? m.name : nil end.
- #get_type_info(name) ⇒ Object
- #hide_pk ⇒ Object
- #pre_run ⇒ Object
- #show_pk ⇒ Object
- #unsupported_association(assoc) ⇒ Object
Instance Method Details
#action_defined ⇒ Object
while prnt && prnt.*.assets == model
prnt = prnt.parent
end
m = prnt.*.assets[:model]
m ? m.name : nil
end
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/engine2/meta.rb', line 277 def action_defined super # p_model_name = parent_model_name model = @assets[:model] mt = case mt when :list, :star_to_many_list, :star_to_many_link_list, :star_to_many_field, :star_to_many_field_link_list # :many_to_one_list model.many_to_one_associations.each do |assoc_name, assoc| unless assoc[:propagate] == false # || p_model_name == assoc[:class_name] dc = model.type_info[assoc[:keys].first][:decode] action.run_scheme :decode, model, assoc_name, dc[:search] end end end case mt when :modify, :create model.many_to_one_associations.each do |assoc_name, assoc| unless assoc[:propagate] == false # || p_model_name == assoc[:class_name] dc = model.type_info[assoc[:keys].first][:decode] action.run_scheme :decode, model, assoc_name, dc[:form] end end end case mt when :list #, :star_to_many_list, :many_to_one_list # list dropdowns divider = false model.one_to_many_associations.merge(model.many_to_many_associations).each do |assoc_name, assoc| unless assoc[:propagate] == false (:item_menu).divider unless divider divider ||= true (:item_menu).option :"#{assoc_name}!", icon: "list" # , click: "action.show_assoc($index, \"#{assoc_name}!\")" action.run_scheme :star_to_many, :"#{assoc_name}!", assoc end end end case mt when :modify, :create model.type_info.each do |field, info| case info[:type] when :blob_store action.run_scheme :blob_store, model, field when :foreign_blob_store action.run_scheme :foreign_blob_store, model, field when :file_store action.run_scheme :file_store, model, field when :star_to_many_field assoc = model.association_reflections[info[:assoc_name]] # info[:name] ? raise E2Error.new("Association '#{info[:assoc_name]}' not found for model '#{model}'") unless assoc action.run_scheme :star_to_many_field, assoc, field end end end end |
#get_type_info(name) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/engine2/meta.rb', line 250 def get_type_info name model = assets[:model] info = model.type_info[name] unless info if name =~ /^(\w+)__(\w+?)$/ # (?:___\w+)? assoc = model.many_to_one_associations[$1.to_sym] || model.one_to_one_associations[$1.to_sym] raise E2Error.new("Association #{$1} not found for model #{model}") unless assoc m = Object.const_get(assoc[:class_name]) info = m.type_info.fetch($2.to_sym) else raise E2Error.new("Type info not found for '#{name}' in model '#{model}'") end end info end |
#hide_pk ⇒ Object
242 243 244 |
# File 'lib/engine2/meta.rb', line 242 def hide_pk hide_fields *assets[:model].primary_keys end |
#pre_run ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/engine2/meta.rb', line 217 def pre_run if !(mdl = @assets[:model]) act = action begin act = act.parent raise E2Error.new("Model not found in tree for action: #{action.name}") unless act mdl = act.*.assets[:model] end until mdl if asc = @assets[:assoc] @assets[:model] = Object.const_get(asc[:class_name]) # raise E2Error.new("Association '#{asc}' for model '#{asc[:class_name]}' not found") unless @assets[:model] else @assets[:model] = mdl asc = act.*.assets[:assoc] @assets[:assoc] = asc if asc end end # @meta[:model!] = assets[:model] # @meta[:assoc!] = assets[:assoc] ? assets[:assoc][:name] : nil # @meta[:meta_class!] = self.class super end |
#show_pk ⇒ Object
246 247 248 |
# File 'lib/engine2/meta.rb', line 246 def show_pk show_fields *assets[:model].primary_keys end |
#unsupported_association(assoc) ⇒ Object
335 336 337 |
# File 'lib/engine2/meta.rb', line 335 def unsupported_association assoc raise E2Error.new("Unsupported association: #{assoc}") end |