Module: Validateable::ClassMethods

Defined in:
lib/validateable.rb

Instance Method Summary collapse

Instance Method Details

#human_attribute_name(attribute_key_name, options = {}) ⇒ Object

rubocop:todo Metrics/AbcSize



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/validateable.rb', line 24

def human_attribute_name(attribute_key_name, options = {}) # rubocop:todo Metrics/AbcSize
  defaults =
    self_and_descendants_from_active_record.map do |klass|
      "#{klass.name.underscore}.#{attribute_key_name}" \
        "#{klass.name.underscore}.#{attribute_key_name}"
    end
  defaults << options[:default] if options[:default]
  defaults.flatten!
  defaults << attribute_key_name.to_s.humanize
  options[:count] ||= 1
  I18n.t(defaults.shift, **options.merge(default: defaults, scope: %i[activerecord attributes]))
end

#human_name(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/validateable.rb', line 37

def human_name(options = {})
  defaults =
    self_and_descendants_from_active_record.map do |klass|
      "#{klass.name.underscore}" \
        "#{klass.name.underscore}"
    end
  defaults << name.humanize
  I18n.t(defaults.shift, { scope: %i[activerecord models], count: 1, default: defaults }.merge(options))
end

#self_and_descendants_from_active_recordObject



20
21
22
# File 'lib/validateable.rb', line 20

def self_and_descendants_from_active_record
  [self]
end