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.

Constant Summary collapse

PARTIAL_PATH =
'e9_attributes/record_attributes'
FORM_PARTIAL =
PARTIAL_PATH + '/form_partial'
LAYOUT_PARTIAL =
PARTIAL_PATH + '/record_attribute'
TEMPLATES =
PARTIAL_PATH + '/templates'

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')


40
41
42
43
44
45
46
# File 'app/models/record_attribute.rb', line 40

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

Instance Method Details

#to_sObject



48
49
50
# File 'app/models/record_attribute.rb', line 48

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