Module: Validateable::ClassMethods

Defined in:
lib/validateable.rb

Instance Method Summary collapse

Instance Method Details

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


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

def human_attribute_name(attribute_key_name, options = {})
  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.translate(defaults.shift, options.merge(default: defaults, scope: [:activerecord, :attributes]))
end

#human_name(options = {}) ⇒ Object


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

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.translate(defaults.shift, { scope: [:activerecord, :models], count: 1, default: defaults }.merge(options))
end

#self_and_descendants_from_active_recordObject


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

def self_and_descendants_from_active_record
  [self]
end