Class: Miteru::Record

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/miteru/record.rb

Class Method Summary collapse

Class Method Details

.create_by_kit_and_hash(kit, sha256:) ⇒ Miteru::Record

Create a new record based on a kit

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/miteru/record.rb', line 23

def create_by_kit_and_hash(kit, sha256:)
  record = new(
    source: kit.source,
    hostname: kit.hostname,
    url: kit.decoded_url,
    headers: kit.headers,
    filename: kit.filename,
    filesize: kit.filesize,
    mime_type: kit.mime_type,
    downloaded_as: kit.filepath_to_download,
    sha256:
  )
  record.save
  record
rescue TypeError, ActiveRecord::RecordNotUnique
  nil
end

.unique_sha256?(sha256) ⇒ Boolean

Returns true if it is unique. Otherwise false.

Parameters:

  • sha256 (String)

Returns:

  • (Boolean)

    true if it is unique. Otherwise false.



11
12
13
# File 'lib/miteru/record.rb', line 11

def unique_sha256?(sha256)
  !where(sha256:).exists?
end