Class: Bookie::Database::Group
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Bookie::Database::Group
- Defined in:
- lib/bookie/database/group.rb
Overview
A group of users
Class Method Summary collapse
-
.find_or_create!(name, known_groups = nil) ⇒ Object
Finds a group by name, creating it if it doesn’t exist.
Class Method Details
.find_or_create!(name, known_groups = nil) ⇒ Object
Finds a group by name, creating it if it doesn’t exist
If known_groups
is provided, it will be used as a cache to reduce the number of database lookups needed.
This uses Lock#synchronize internally, so it probably should not be called within a transaction block.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bookie/database/group.rb', line 18 def self.find_or_create!(name, known_groups = nil) group = known_groups[name] if known_groups unless group Lock[:groups].synchronize do group = find_by(name: name) group ||= create!(name: name) end known_groups[name] = group if known_groups end group end |