diff options
Diffstat (limited to 'app/models/concerns/sha_attribute.rb')
-rw-r--r-- | app/models/concerns/sha_attribute.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/models/concerns/sha_attribute.rb b/app/models/concerns/sha_attribute.rb new file mode 100644 index 00000000000..67ecf470f7e --- /dev/null +++ b/app/models/concerns/sha_attribute.rb @@ -0,0 +1,20 @@ +module ShaAttribute + extend ActiveSupport::Concern + + module ClassMethods + def sha_attribute(name) + return unless table_exists? + + column = columns.find { |c| c.name == name.to_s } + + # In case the table doesn't exist we won't be able to find the column, + # thus we will only check the type if the column is present. + if column && column.type != :binary + raise ArgumentError, + "sha_attribute #{name.inspect} is invalid since the column type is not :binary" + end + + attribute(name, Gitlab::Database::ShaAttribute.new) + end + end +end |