花月(Kagetsu) CircleCI

kagetsu is a library for create or update method on ActiveRecord.

Requirement

  • Rails 5.2 or upper

Usage

User.create!(name: 'kotoko', email: 'old@example.com')
user = User.create_or_update(key: { name: 'kotoko' }, update_attributes: { email: 'new@example.com' })

user.email #=> new@example.com

Available Methods

  • ActiveRecord::Base#create_or_update
  • ActiveRecord::Base#create_or_update!