Class: Engine2::ForeignBlobStoreAction

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

Instance Attribute Summary collapse

Attributes inherited from Action

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

Instance Method Summary collapse

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 Attribute Details

#fieldObject

Returns the value of attribute field.



167
168
169
# File 'lib/engine2/action/infra.rb', line 167

def field
  @field
end

#modelObject

Returns the value of attribute model.



167
168
169
# File 'lib/engine2/action/infra.rb', line 167

def model
  @model
end

Instance Method Details

#invoke(handler) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/engine2/action/infra.rb', line 169

def invoke handler
    handler.permit id = handler.params[:owner]

    inf = model.type_info[field]
    assoc = model.association_reflections[inf[:assoc_name]]
    blob_model = assoc.associated_class

    rec = model.naked.select(assoc[:key]).where(model.primary_keys_hash(split_keys(id))).first
    handler.permit rec
    result = blob_model.naked.select(inf[:name_field], Sequel.char_length(inf[:bytes_field]).as(:length)).where(blob_model.primary_key => rec[assoc[:key]]).first

    # handler.permit result
    {file_name: result ? result[inf[:name_field]] : :empty, blob_length: result ? result[:length] : 0}
end