Sha256: 83b4f1d97546f68441d0e442ef1de24fd16a9f6614ced4d791f84775ecd931e2

Contents?: true

Size: 452 Bytes

Versions: 14

Compression:

Stored size: 452 Bytes

Contents

module KB
  module FindOrCreatable
    extend ActiveSupport::Concern

    included do
      include Queryable
      include Listable
      include Creatable
    end

    module ClassMethods
      def find_or_create_by(attributes, additional_attributes)
        all(attributes).first || new(create(additional_attributes.merge(attributes)), &:persist!)
      rescue Faraday::Error => e
        raise KB::Error.from_faraday(e)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
barkibu-kb-0.27.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.26.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.25.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.24.1 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.24.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.23.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.22.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.21.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.20.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.19.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.18.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.17.0 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.16.2 lib/kb/models/concerns/find_or_creatable.rb
barkibu-kb-0.16.1 lib/kb/models/concerns/find_or_creatable.rb