Class: RecordAttribute

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
E9Rails::ActiveRecord::AttributeSearchable, E9Rails::ActiveRecord::InheritableOptions, E9Rails::ActiveRecord::STI
Defined in:
app/models/record_attribute.rb

Overview

An arbitrary ‘attribute’ attachable to records.

Gets support for arbitrary options via InheritableOptions. By default it has one option, type, but subclasses could extend for further options by overwriting options_parameters.

By default, the type options are managed via the MenuOption class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.typesObject

Looks up the available types for this attribute by fetching a titleized version of the class name from MenuOption.

e.g.

PhoneNumberAttribute.types

is equivalent to:

MenuOption.fetch_values('Phone Number')


30
31
32
33
34
35
36
# File 'app/models/record_attribute.rb', line 30

def self.types
  if name =~ /^(\w+)Attribute$/ 
    MenuOption.fetch_values($1.titleize)
  else 
    []
  end
end

Instance Method Details

#to_sObject



38
39
40
# File 'app/models/record_attribute.rb', line 38

def to_s
  options.type ? "#{value} (#{options.type})" : value
end