Class: Engine2::DownloadForeignBlobStoreAction

Inherits:
Action show all
Includes:
BlobSupportAction
Defined in:
lib/engine2/action/infra.rb

Instance Attribute Summary

Attributes inherited from Action

#assets, #invokable, #meta, #node, #static

Instance Method Summary collapse

Methods included from BlobSupportAction

#serve_blob

Methods inherited from Action

action_type, #action_type, #arguments, #check_anonymous_action_class, #check_static_action, #define_invoke, #define_method, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #join_keys, #lookup, #merge, #node_defined, #post_process, #post_run, #pre_run, #repeat, #request, #request_action_proc_params, #split_keys

Constructor Details

This class inherits a constructor from Engine2::Action

Instance Method Details

#invoke(handler) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/engine2/action/infra.rb', line 189

def invoke handler
    model = node.parent.*.model
    inf = model.type_info[node.parent.*.field]
    assoc = model.association_reflections[inf[:assoc_name]]
    blob_model = assoc.associated_class
    handler.permit id = handler.params[:id]
    rec = model.naked.select(assoc[:key]).where(model.primary_keys_hash(split_keys(id))).first
    handler.permit rec

    entry = blob_model.naked.select(inf[:bytes_field], inf[:name_field], inf[:mime_field]).where(blob_model.primary_key => rec[assoc[:key]]).first
    serve_blob(handler, entry, inf)
end