Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/guilded/rails/active_record/human_attribute_hint.rb,
lib/guilded/rails/active_record/human_attribute_override.rb

Class Method Summary collapse

Class Method Details

.attr_human_hint(attributes) ⇒ Object

Allows alternate humanized versions of attributes to be set. For example, an attribute such as ‘num_employees’ would be converted to ‘Num employees’ normally using human_attribute_name. More descriptive text can be set. Example:

attr_human_name 'num_employees' => 'Number of employees'


7
8
9
10
11
12
13
14
15
# File 'lib/guilded/rails/active_record/human_attribute_hint.rb', line 7

def attr_human_hint(attributes) # :nodoc:
  return unless table_exists?

  attributes.stringify_keys!
  write_inheritable_hash("attr_human_hint", attributes || {})

  # assign the current class to each column that is being assigned a new human attribute name
  self.columns.reject{|c| !attributes.has_key?(c.name)}.each{|c| c.parent_record_class = self}
end

.attr_human_name(attributes) ⇒ Object

Allows alternate humanized versions of attributes to be set. For example, an attribute such as ‘num_employees’ would be converted to ‘Num employees’ normally using human_attribute_name. More descriptive text can be set. Example:

attr_human_name 'num_employees' => 'Number of employees'


7
8
9
10
11
12
13
14
15
# File 'lib/guilded/rails/active_record/human_attribute_override.rb', line 7

def attr_human_name(attributes) # :nodoc:
  return unless table_exists?

  attributes.stringify_keys!
  write_inheritable_hash("attr_human_name", attributes || {})

  # assign the current class to each column that is being assigned a new human attribute name
  self.columns.reject{|c| !attributes.has_key?(c.name)}.each{|c| c.parent_record_class = self}
end

.human_attribute_hint(attribute_key_name) ⇒ Object

Transforms attribute key names into a more humane format, such as “First name” instead of “first_name”. Example:

Person.human_attribute_name("first_name") # => "First name"


24
25
26
# File 'lib/guilded/rails/active_record/human_attribute_hint.rb', line 24

def human_attribute_hint(attribute_key_name) #:nodoc:
  (read_inheritable_attribute("attr_human_hint") || {})[attribute_key_name.to_s] || ''
end

.human_attribute_name(attribute_key_name) ⇒ Object

Transforms attribute key names into a more humane format, such as “First name” instead of “first_name”. Example:

Person.human_attribute_name("first_name") # => "First name"


24
25
26
# File 'lib/guilded/rails/active_record/human_attribute_override.rb', line 24

def human_attribute_name(attribute_key_name) #:nodoc:
  (read_inheritable_attribute("attr_human_name") || {})[attribute_key_name.to_s] || attribute_key_name.to_s.humanize.titleize
end

.human_hint_attributesObject

Returns a hash of alternate human name conversions set with attr_human_name.



18
19
20
# File 'lib/guilded/rails/active_record/human_attribute_hint.rb', line 18

def human_hint_attributes # :nodoc:
  read_inheritable_attribute("attr_human_hint")
end

.human_name_attributesObject

Returns a hash of alternate human name conversions set with attr_human_name.



18
19
20
# File 'lib/guilded/rails/active_record/human_attribute_override.rb', line 18

def human_name_attributes # :nodoc:
  read_inheritable_attribute("attr_human_name")
end