Module: ActiveRecord::EnumeratedModel
- Defined in:
- lib/active_record-enumerated_model/version.rb,
lib/active_record-enumerated_model/enumerated_model.rb
Defined Under Namespace
Modules: ClassMethods
Classes: NilConstantError, UnknownAttributeError
Constant Summary
collapse
- VERSION =
"0.1.2"
Class Method Summary
collapse
Class Method Details
.constant_friendly_string(str) ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/active_record-enumerated_model/enumerated_model.rb', line 62
def self.constant_friendly_string(str)
const = str.upcase
const.gsub!(/\s+/, '_') const.gsub!(/^[^A-Z]+/, '') const.gsub!(/[-\/\\]/, '_') const.gsub!(/[^A-Z_]/, '') const.gsub!(/_+/, '_') const.gsub!(/[^A-Z0-9]$/, '') const
end
|
.included(caller) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/active_record-enumerated_model/enumerated_model.rb', line 54
def self.included(caller)
caller.extend(ClassMethods)
caller.send(:include, ActiveRecord::ReadonlyModel)
if caller.attribute_names.include? 'name'
caller.create_enumeration_constants :name
end
end
|