Module: AbAdmin::Concerns::Fileuploads::ClassMethods

Defined in:
lib/ab_admin/concerns/fileuploads.rb

Instance Method Summary collapse

Instance Method Details

#fileupload_find(method, guid) ⇒ Object

Find asset(s) by guid


39
40
41
42
# File 'lib/ab_admin/concerns/fileuploads.rb', line 39

def fileupload_find(method, guid)
  query = fileupload_scope(method, guid)
  fileupload_multiple?(method) ? query.to_a : query.first
end

#fileupload_klass(method) ⇒ Object

Find class by reflection


51
52
53
# File 'lib/ab_admin/concerns/fileuploads.rb', line 51

def fileupload_klass(method)
  reflect_on_association(method.to_sym).klass
end

#fileupload_multiple?(method) ⇒ Boolean


55
56
57
# File 'lib/ab_admin/concerns/fileuploads.rb', line 55

def fileupload_multiple?(method)
  reflect_on_association(method.to_sym).try(:collection?)
end

#fileupload_scope(method, guid) ⇒ Object


44
45
46
47
48
# File 'lib/ab_admin/concerns/fileuploads.rb', line 44

def fileupload_scope(method, guid)
  assoc = reflect_on_association(method.to_sym)
  assoc_scope = assoc.scope ? assoc.klass.instance_exec(&assoc.scope) : assoc.klass
  assoc_scope.where(guid: guid, assetable_type: base_class.name.to_s)
end

#fileupload_update(record_id, guid, method) ⇒ Object

Update reflection klass by guid


34
35
36
# File 'lib/ab_admin/concerns/fileuploads.rb', line 34

def fileupload_update(record_id, guid, method)
  fileupload_scope(method, guid).update_all(assetable_id: record_id, guid: nil)
end