class ModelAuditor::AttributeReaders::Associated

Attributes

key[R]
model[R]

Public Class Methods

new(model, key) click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 8
def initialize(model, key)
  @model = model
  @key = key
end

Public Instance Methods

value() click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 13
def value
  title || name || id
end

Protected Instance Methods

attr_name(pattern, replacement = '') click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 19
def attr_name(pattern, replacement = '')
  return unless key.to_s =~ pattern

  attribute_name = key.to_s.gsub(pattern, replacement)

  attribute_name if model.respond_to?(attribute_name)
end

Private Instance Methods

associated_model() click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 41
def associated_model
  return unless method_name

  model.send(method_name)
end
id() click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 37
def id
  associated_model.id if associated_model.respond_to?(:id)
end
method_name() click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 47
def method_name
  attr_name(/_id$/)
end
name() click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 33
def name
  associated_model.name if associated_model.respond_to?(:name)
end
title() click to toggle source
# File lib/model_auditor/attribute_readers/associated.rb, line 29
def title
  associated_model.title if associated_model.respond_to?(:title)
end