Sha256: 18336266e7a58733d7c153b291541fb6865c3b6813ba8549bdfc03c620829886
Contents?: true
Size: 341 Bytes
Versions: 1
Compression:
Stored size: 341 Bytes
Contents
require 'active_support/concern' module ActiverecordLookupOrInitialize module Base extend ActiveSupport::Concern included do def lookup_or_initialize_by(attributes, &block) self.detect { |o| attributes.keys.map{ |k| o.send(k) } == attributes.values } || self.build(attributes, &block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord_lookup_or_initialize-0.1.0 | lib/activerecord_lookup_or_initialize/base.rb |