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



214
215
216
217
# File 'lib/artirix_data_models/model.rb', line 214

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

#set_primary_key(value) ⇒ Object



219
220
221
222
# File 'lib/artirix_data_models/model.rb', line 219

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

#to_keyObject



235
236
237
238
239
240
241
242
# File 'lib/artirix_data_models/model.rb', line 235

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

#to_paramObject



226
227
228
229
230
231
232
233
# File 'lib/artirix_data_models/model.rb', line 226

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