Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store next naming sequence in custom_attributes
With this implemenation naming sequences are global through current region. The binding can be changed to other models through NamingSequenceMixin. https://bugzilla.redhat.com/show_bug.cgi?id=1173336
- Loading branch information
Showing
5 changed files
with
52 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module NamingSequenceMixin | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# these are possible naming sequences because there is no constraint to source column | ||
has_many :naming_sequences, :as => :resource, :dependent => :destroy, :class_name => "CustomAttribute" | ||
end | ||
|
||
def next_naming_sequence(name, source) | ||
lock do | ||
record = naming_sequences.where(:name => name, :source => source).first_or_initialize | ||
record.update_attributes!(:value => record.value.to_i + 1) | ||
|
||
record.value | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters