class Formulaic::Label
Attributes
action[R]
attribute[R]
model_name[R]
Public Class Methods
new(model_name, attribute, action)
click to toggle source
# File lib/formulaic/label.rb, line 5 def initialize(model_name, attribute, action) @model_name = model_name @attribute = attribute @action = action end
Public Instance Methods
to_str()
click to toggle source
# File lib/formulaic/label.rb, line 11 def to_str if attribute.is_a?(String) attribute else translate || human_attribute_name || attribute.to_s.humanize end end
Also aliased as: to_s
Private Instance Methods
class_exists?(class_name)
click to toggle source
# File lib/formulaic/label.rb, line 45 def class_exists?(class_name) Object.const_defined?(class_name.to_s.classify) rescue NameError false end
human_attribute_name()
click to toggle source
# File lib/formulaic/label.rb, line 26 def human_attribute_name if class_exists?(model_name.to_s.classify) model_class = model_name.to_s.classify.constantize if model_class.respond_to?(:human_attribute_name) model_class.human_attribute_name(attribute.to_s) end end end
lookup_paths()
click to toggle source
# File lib/formulaic/label.rb, line 35 def lookup_paths [ :"#{model_name}.#{action}.#{attribute}", :"#{model_name}.#{attribute}", :"defaults.#{action}.#{attribute}", :"defaults.#{attribute}", '', ] end
translate()
click to toggle source
# File lib/formulaic/label.rb, line 22 def translate I18n.t(lookup_paths.first, scope: :'simple_form.labels', default: lookup_paths).presence end