Class: Bluff::Support::Persistence::ActiveRecordAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/bluff/support/persistence/active_record.rb

Class Method Summary collapse

Class Method Details

.persist(record) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/bluff/support/persistence/active_record.rb', line 13

def persist(record)
  ActiveRecord::Base.transaction do
    record.class.reflect_on_all_associations(:belongs_to).each do |reflection|
      association = record.send(reflection.name)
      association.save! if association && association.new_record?
    end

    record.save!
  end
end

.persists?(record) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/bluff/support/persistence/active_record.rb', line 9

def persists?(record)
  record.is_a?(ActiveRecord::Base)
end