Module: ArtirixDataModels::Model::PrimaryKey

Extended by:
ActiveSupport::Concern
Defined in:
lib/artirix_data_models/model.rb

Defined Under Namespace

Modules: ClassMethods Classes: UndefinedPrimaryKeyAttributeError

Constant Summary collapse

PARAM_JOIN_STRING =
'/'.freeze

Instance Method Summary collapse

Instance Method Details

#primary_keyObject



286
287
288
289
# File 'lib/artirix_data_models/model.rb', line 286

def primary_key
  raise UndefinedPrimaryKeyAttributeError unless self.class.primary_key_attribute.present?
  send(self.class.primary_key_attribute)
end

#set_primary_key(value) ⇒ Object



291
292
293
294
# File 'lib/artirix_data_models/model.rb', line 291

def set_primary_key(value)
  raise UndefinedPrimaryKeyAttributeError unless self.class.primary_key_attribute.present?
  send("#{self.class.primary_key_attribute}=", value)
end

#to_keyObject



307
308
309
310
311
312
313
314
# File 'lib/artirix_data_models/model.rb', line 307

def to_key
  # for ActiveModel compliant
  if persisted?
    [primary_key]
  else
    nil
  end
end

#to_paramObject



298
299
300
301
302
303
304
305
# File 'lib/artirix_data_models/model.rb', line 298

def to_param
  # for ActiveModel compliant
  if persisted?
    to_key.join PARAM_JOIN_STRING
  else
    nil
  end
end