Module: Engine2::ActionModelSupport

Instance Method Summary collapse

Instance Method Details

#hide_pkObject



335
336
337
# File 'lib/engine2/action.rb', line 335

def hide_pk
    hide_fields *assets[:model].primary_keys
end

#node_definedObject

while prnt && prnt.*.assets == model

    prnt = prnt.parent
end
m = prnt.*.assets[:model]
m ? m.name : nil

end



354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/engine2/action.rb', line 354

def node_defined
    super
    # p_model_name = parent_model_name
    model = @assets[:model]

    at = action_type
    case at
    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]
                node.run_scheme :decode, model, assoc_name, dc[:search]
            end
        end
    end

    case at
    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]
                node.run_scheme :decode, model, assoc_name, dc[:form]
            end
        end
    end

    case at
    when :list #, :star_to_many_list, :many_to_one_list # list dropdowns
        model.one_to_many_associations.merge(model.many_to_many_associations).each do |assoc_name, assoc|
            unless assoc[:propagate] == false
                node.run_scheme :star_to_many, :"#{assoc_name}!", assoc
            end
        end
    end

    case at
    when :modify, :create
        model.type_info.each do |field, info|
            case info[:type]
            when :blob_store
                node.run_scheme :blob_store, model, field
            when :foreign_blob_store
                node.run_scheme :foreign_blob_store, model, field
            when :file_store
                node.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
                node.run_scheme :star_to_many_field, assoc, field
            end
        end
    end
end

#pre_runObject



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/action.rb', line 310

def pre_run
    if !(mdl = @assets[:model])
        act = node
        begin
            act = act.parent
            raise E2Error.new("Model not found in tree for node: #{node.name}") unless act
            mdl = act.*.assets[:model]
        end until mdl

        if asc = @assets[:assoc]
            @assets[:model] = asc.associated_class
            # 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[:action_class!] = self.class
    super
end

#show_pkObject



339
340
341
# File 'lib/engine2/action.rb', line 339

def show_pk
    show_fields *assets[:model].primary_keys
end

#unsupported_association(assoc) ⇒ Object

Raises:



408
409
410
# File 'lib/engine2/action.rb', line 408

def unsupported_association assoc
    raise E2Error.new("Unsupported association: #{assoc}")
end