Method: Persisted::ClassMethods#persist_with
- Defined in:
- lib/persisted.rb
#persist_with(model_name, options = {}) ⇒ Object
Instructs the persistence layer which ORM-backed class to use to persist the model.
Usage:
persist_with :user, attributes: %w{username password}
Configuration options: attributes: An array of shared attributes between models used for DB
interactions. Basically, use this to find the appropriate record.
Defaults to ['id']
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/persisted.rb', line 43 def persist_with( model_name, = {} ) self.persisted_record_class = model_name.to_s.camelize.constantize if && .is_a?( Hash ) .symbolize_keys! if [:attributes].is_a?( Array ) [:attributes] ||= ['id'] @shared_attributes = [:attributes] end else raise ArgumentError, 'An array of shared attributes must be supplied as the :attributes option of the configuration hash' end end |