Class: Engine2::ForeignBlobStoreMeta
- Defined in:
- lib/engine2/meta/infra_meta.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#model ⇒ Object
Returns the value of attribute model.
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, #split_keys
Constructor Details
This class inherits a constructor from Engine2::Meta
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
185 186 187 |
# File 'lib/engine2/meta/infra_meta.rb', line 185 def field @field end |
#model ⇒ Object
Returns the value of attribute model.
185 186 187 |
# File 'lib/engine2/meta/infra_meta.rb', line 185 def model @model end |
Instance Method Details
#invoke(handler) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/engine2/meta/infra_meta.rb', line 187 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 |