Module: ActiveRecordUpsert::ActiveRecord::PersistenceExtensions::ClassMethods
- Defined in:
- lib/active_record_upsert/active_record/persistence.rb
Instance Method Summary collapse
- #upsert(*args) ⇒ Object
- #upsert!(attributes, arel_condition: nil, &block) ⇒ Object
- #upsert_keys(*keys) ⇒ Object
Instance Method Details
#upsert(*args) ⇒ Object
53 54 55 56 57 |
# File 'lib/active_record_upsert/active_record/persistence.rb', line 53 def upsert(*args) upsert!(*args) rescue ::ActiveRecord::RecordInvalid false end |
#upsert!(attributes, arel_condition: nil, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/active_record_upsert/active_record/persistence.rb', line 43 def upsert!(attributes, arel_condition: nil, &block) if attributes.is_a?(Array) attributes.collect { |hash| upsert(hash, &block) } else new(attributes, &block).upsert!( attributes: attributes.keys, arel_condition: arel_condition, validate: true ) end end |
#upsert_keys(*keys) ⇒ Object
59 60 61 62 63 |
# File 'lib/active_record_upsert/active_record/persistence.rb', line 59 def upsert_keys(*keys) return @_upsert_keys if keys.empty? keys = keys.first if keys.size == 1 # support single string/symbol, multiple string/symbols, and array @_upsert_keys = Array(keys).map(&:to_s) end |