Sha256: 096cb367e4c99dd960207f4d00aa6e191009f6794e5c85d845c52731a60f3f44
Contents?: true
Size: 1.08 KB
Versions: 4
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true require "active_record" module Miteru class Record < ActiveRecord::Base class << self # # Check uniqueness of a record by a hash # # @param [String] hash # # @return [Boolean] true if it is unique. Otherwise false. # def unique_hash?(hash) record = find_by(hash: hash) return true if record.nil? false end # # Create a new record based on a kit # # @param [Miteru::Kit] kit # @param [String] hash # # @return [Miteru::Record] # def create_by_kit_and_hash(kit, hash) record = new( hash: hash, 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 ) record.save record rescue TypeError, ActiveRecord::RecordNotUnique => _e nil end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
miteru-1.2.2 | lib/miteru/record.rb |
miteru-1.2.1 | lib/miteru/record.rb |
miteru-1.2.0 | lib/miteru/record.rb |
miteru-1.1.0 | lib/miteru/record.rb |