digitalhelpersleague/asterism

View on GitHub
lib/sequel/find_or_something_extension.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Sequel
  module FindOrSomethingExtension
    def find_or_create(vals)
      first(vals) || model.create(
        vals.merge(
          association_reflection[:key] => model_object.context
        )
      )
    end

    def find_or_initialize(vals)
      first(vals) || model.new(
        vals.merge(
          association_reflection[:key] => model_object.context
        )
      )
    end

  end
end