2018-11-09 13:39:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-13 05:05:16 -05:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
# This module expects an `ATTRS` const to be defined on the subclass
|
2021-04-07 14:09:45 -04:00
|
|
|
# See GitalyClient::WikiPage for an example
|
2017-11-13 05:05:16 -05:00
|
|
|
module AttributesBag
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2019-10-15 23:06:12 -04:00
|
|
|
attr_accessor(*const_get(:ATTRS, false))
|
2017-11-13 05:05:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
params = params.with_indifferent_access
|
|
|
|
|
|
|
|
attributes.each do |attr|
|
|
|
|
instance_variable_set("@#{attr}", params[attr])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
attributes.all? do |field|
|
|
|
|
instance_variable_get("@#{field}") == other.instance_variable_get("@#{field}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def attributes
|
2019-10-15 23:06:12 -04:00
|
|
|
self.class.const_get(:ATTRS, false)
|
2017-11-13 05:05:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|