Class: Lafcadio::EnumField
- Inherits:
-
TextField
- Object
- ObjectField
- TextField
- Lafcadio::EnumField
- Defined in:
- lib/lafcadio/objectField/EnumField.rb
Overview
EnumField represents an enumerated field that can only be set to one of a set range of string values. To set the enumeration in the class definition XML, use the following format:
<field name="flavor" class="EnumField">
<enums>
<enum>Vanilla</enum>
<enum>Chocolate</enum>
<enum>Lychee</enum>
</enums>
</field>
If you’re defining the field in Ruby, you can simply pass in an array of enums as the enums
argument.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#enums ⇒ Object
readonly
Returns the value of attribute enums.
Attributes inherited from TextField
Attributes inherited from ObjectField
#dbFieldName, #default, #defaultFieldName, #hideDisplay, #hideLabel, #name, #notNull, #notUniqueMsg, #objectType, #unique, #writeOnce
Class Method Summary collapse
-
.instantiateWithParameters(domainClass, parameters) ⇒ Object
:nodoc:.
-
.instantiationParameters(fieldElt) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(objectType, name, enums, englishName = nil) ⇒ EnumField
constructor
- objectType
-
The domain class that this field belongs to.
-
#valueForSQL(value) ⇒ Object
:nodoc:.
Methods inherited from ObjectField
#<=>, #bind_write?, #dbWillAutomaticallyWrite, #db_table_and_field_name, #englishName, #firstTime, instantiateFromXml, #nameForSQL, #nullErrorMsg, #prevValue, #processBeforeVerify, #valueFromSQL, valueType, #verify, #verifyUniqueness
Constructor Details
#initialize(objectType, name, enums, englishName = nil) ⇒ EnumField
- objectType
-
The domain class that this field belongs to.
- name
-
The name of this domain class.
- enums
-
An array of Strings representing the possible choices for this field.
- englishName
-
The English name of this field. (Deprecated)
48 49 50 51 52 53 54 55 56 |
# File 'lib/lafcadio/objectField/EnumField.rb', line 48 def initialize(objectType, name, enums, englishName = nil) require 'lafcadio/util/QueueHash' super objectType, name, englishName if enums.class == Array @enums = QueueHash.newFromArray enums else @enums = enums end end |
Instance Attribute Details
#enums ⇒ Object (readonly)
Returns the value of attribute enums.
41 42 43 |
# File 'lib/lafcadio/objectField/EnumField.rb', line 41 def enums @enums end |
Class Method Details
.instantiateWithParameters(domainClass, parameters) ⇒ Object
:nodoc:
36 37 38 39 |
# File 'lib/lafcadio/objectField/EnumField.rb', line 36 def EnumField.instantiateWithParameters( domainClass, parameters ) #:nodoc: self.new( domainClass, parameters['name'], parameters['enums'], parameters['englishName'] ) end |
.instantiationParameters(fieldElt) ⇒ Object
:nodoc:
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lafcadio/objectField/EnumField.rb', line 18 def EnumField.instantiationParameters( fieldElt ) #:nodoc: parameters = super( fieldElt ) if fieldElt.elements['enums'][1].attributes['key'] enumValues = [] fieldElt.elements.each( 'enums/enum' ) { |enumElt| enumValues << enumElt.attributes['key'] enumValues << enumElt.text.to_s } parameters['enums'] = QueueHash.new( *enumValues ) else parameters['enums'] = [] fieldElt.elements.each( 'enums/enum' ) { |enumElt| parameters['enums'] << enumElt.text.to_s } end parameters end |
Instance Method Details
#valueForSQL(value) ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/lafcadio/objectField/EnumField.rb', line 58 def valueForSQL(value) #:nodoc: value != '' ?(super(value)) : 'null' end |