Module: QUI::CommonHelpers::Model::ClassMethods
- Defined in:
- lib/qui-common-helpers.rb
Instance Method Summary collapse
- #enum_human_value(attribute_name, value) ⇒ Object
- #has_link_default_description(field) ⇒ Object
- #is_enum?(attribute_name) ⇒ Boolean
- #validates_enum_of(attribute_name) ⇒ Object
Instance Method Details
#enum_human_value(attribute_name, value) ⇒ Object
62 63 64 65 66 |
# File 'lib/qui-common-helpers.rb', line 62 def enum_human_value(attribute_name, value) raise ArgumentError, "Attribute #{attribute_name} is not defined as enum with validates_enum_of" unless is_enum? attribute_name I18n.t(:"activerecord.enums.#{self.to_s.tableize.singularize}.#{attribute_name}.#{value}") end |
#has_link_default_description(field) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/qui-common-helpers.rb', line 75 def has_link_default_description(field) @link_default_description_field = field class << self attr_reader :link_default_description_field end end |
#is_enum?(attribute_name) ⇒ Boolean
57 58 59 60 |
# File 'lib/qui-common-helpers.rb', line 57 def is_enum?(attribute_name) return false unless @enums @enums.include? attribute_name.to_sym end |
#validates_enum_of(attribute_name) ⇒ Object
68 69 70 71 72 |
# File 'lib/qui-common-helpers.rb', line 68 def validates_enum_of(attribute_name) @enums ||= [] @enums << attribute_name.to_sym validates_inclusion_of attribute_name, :in => I18n.t("activerecord.enums.#{table_name.singularize}.#{attribute_name}").collect{|k,v| k.to_s.to_i } end |