Class: Engine2::ForeignBlobStoreMeta

Inherits:
Meta show all
Defined in:
lib/engine2/meta/infra_meta.rb

Instance Attribute Summary collapse

Attributes inherited from Meta

#action, #assets, #invokable, #static

Instance Method Summary collapse

Methods inherited from Meta

#action_defined, #check_static_meta, #dynamic?, #freeze_meta, #get, http_method, #http_method, inherited, #initialize, #invoke!, #lookup, #merge, #meta_type, meta_type, #post_process, #post_run, #pre_run, #request, #request_meta_proc_params, #response, #split_keys

Constructor Details

This class inherits a constructor from Engine2::Meta

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



184
185
186
# File 'lib/engine2/meta/infra_meta.rb', line 184

def field
  @field
end

#modelObject

Returns the value of attribute model.



184
185
186
# File 'lib/engine2/meta/infra_meta.rb', line 184

def model
  @model
end

Instance Method Details

#invoke(handler) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/engine2/meta/infra_meta.rb', line 186

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

    inf = model.type_info[field]
    assoc = model.association_reflections[inf[:assoc_name]]
    blob_model = Object.const_get(assoc[:class_name])

    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