Module: Ronin::DB::Model::Importable::ClassMethods

Defined in:
lib/ronin/db/model/importable.rb

Overview

Class-methods which will be added to the model.

Instance Method Summary collapse

Instance Method Details

#find_or_import(value) ⇒ ActiveRecord::Base

Finds or imports a new record.

Parameters:

  • value (Object)

    The raw value that represents the record.

Returns:

  • (ActiveRecord::Base)

    The found or created record.



81
82
83
# File 'lib/ronin/db/model/importable.rb', line 81

def find_or_import(value)
  lookup(value) || import(value)
end

#import(value) ⇒ ActiveRecord::Base

This method is abstract.

Imports a record from the given value.

Parameters:

  • value (Object)

    The raw value that represents the record.

Returns:

  • (ActiveRecord::Base)

    The imported record.

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/ronin/db/model/importable.rb', line 68

def import(value)
  raise(NotImplementedError,"#{self} did not define a self.import method")
end

#lookup(value) ⇒ ActiveRecord::Base?

Looks up a record with the given value.

Parameters:

  • value (Object)

    The raw value to use for the query.

Returns:

  • (ActiveRecord::Base, nil)

    The found record.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/ronin/db/model/importable.rb', line 53

def lookup(value)
  raise(NotImplementedError,"#{self} did not define a self.lookup method")
end