Class: Lafcadio::ObjectField
- Inherits:
-
Object
- Object
- Lafcadio::ObjectField
- Includes:
- Comparable
- Defined in:
- lib/lafcadio/objectField/ObjectField.rb
Overview
ObjectField is the abstract base class of any field for domain objects.
Direct Known Subclasses
BlobField, BooleanField, DateField, DateTimeField, DecimalField, IntegerField, LinkField, TextField, TextListField
Instance Attribute Summary collapse
-
#dbFieldName ⇒ Object
Returns the value of attribute dbFieldName.
-
#default ⇒ Object
Returns the value of attribute default.
-
#defaultFieldName ⇒ Object
readonly
Returns the value of attribute defaultFieldName.
-
#hideDisplay ⇒ Object
Returns the value of attribute hideDisplay.
-
#hideLabel ⇒ Object
Returns the value of attribute hideLabel.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#notNull ⇒ Object
Returns the value of attribute notNull.
-
#notUniqueMsg ⇒ Object
Returns the value of attribute notUniqueMsg.
-
#objectType ⇒ Object
readonly
Returns the value of attribute objectType.
-
#unique ⇒ Object
Returns the value of attribute unique.
-
#writeOnce ⇒ Object
Returns the value of attribute writeOnce.
Class Method Summary collapse
-
.instantiateFromXml(domainClass, fieldElt) ⇒ Object
:nodoc:.
-
.instantiateWithParameters(domainClass, parameters) ⇒ Object
:nodoc:.
-
.instantiationParameters(fieldElt) ⇒ Object
:nodoc:.
-
.valueType ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#bind_write? ⇒ Boolean
:nodoc:.
- #db_table_and_field_name ⇒ Object
-
#dbWillAutomaticallyWrite ⇒ Object
:nodoc:.
-
#englishName ⇒ Object
:nodoc:.
-
#firstTime(fieldManager) ⇒ Object
:nodoc:.
-
#initialize(objectType, name, englishName = nil) ⇒ ObjectField
constructor
- objectType
-
The domain class that this object field belongs to.
-
#nameForSQL ⇒ Object
Returns the name that this field is referenced by in the MySQL table.
-
#nullErrorMsg ⇒ Object
:nodoc:.
-
#prevValue(pkId) ⇒ Object
:nodoc:.
-
#processBeforeVerify(value) ⇒ Object
:nodoc:.
-
#valueForSQL(value) ⇒ Object
Returns a string value suitable for committing this field’s value to MySQL.
-
#valueFromSQL(string) ⇒ Object
Given the SQL value string, returns a Ruby-native value.
-
#verify(value, pkId) ⇒ Object
:nodoc:.
-
#verifyUniqueness(value, pkId) ⇒ Object
:nodoc:.
Constructor Details
#initialize(objectType, name, englishName = nil) ⇒ ObjectField
- objectType
-
The domain class that this object field belongs to.
- name
-
The name of this field.
- englishName
-
The descriptive English name of this field. (Deprecated)
42 43 44 45 46 47 48 49 50 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 42 def initialize(objectType, name, englishName = nil ) @objectType = objectType @name = name @dbFieldName = name @notNull = true @unique = false ( @default, @notUniqueMsg ) = [ nil, nil ] @englishNameOrNil = englishName end |
Instance Attribute Details
#dbFieldName ⇒ Object
Returns the value of attribute dbFieldName.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def dbFieldName @dbFieldName end |
#default ⇒ Object
Returns the value of attribute default.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def default @default end |
#defaultFieldName ⇒ Object (readonly)
Returns the value of attribute defaultFieldName.
9 10 11 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 9 def defaultFieldName @defaultFieldName end |
#hideDisplay ⇒ Object
Returns the value of attribute hideDisplay.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def hideDisplay @hideDisplay end |
#hideLabel ⇒ Object
Returns the value of attribute hideLabel.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def hideLabel @hideLabel end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 9 def name @name end |
#notNull ⇒ Object
Returns the value of attribute notNull.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def notNull @notNull end |
#notUniqueMsg ⇒ Object
Returns the value of attribute notUniqueMsg.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def notUniqueMsg @notUniqueMsg end |
#objectType ⇒ Object (readonly)
Returns the value of attribute objectType.
9 10 11 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 9 def objectType @objectType end |
#unique ⇒ Object
Returns the value of attribute unique.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def unique @unique end |
#writeOnce ⇒ Object
Returns the value of attribute writeOnce.
10 11 12 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 10 def writeOnce @writeOnce end |
Class Method Details
.instantiateFromXml(domainClass, fieldElt) ⇒ Object
:nodoc:
25 26 27 28 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 25 def ObjectField.instantiateFromXml( domainClass, fieldElt ) #:nodoc: parameters = instantiationParameters( fieldElt ) instantiateWithParameters( domainClass, parameters ) end |
.instantiateWithParameters(domainClass, parameters) ⇒ Object
:nodoc:
30 31 32 33 34 35 36 37 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 30 def self.instantiateWithParameters( domainClass, parameters ) #:nodoc: instance = self.new( domainClass, parameters['name'], parameters['englishName'] ) if ( dbFieldName = parameters['dbFieldName'] ) instance.dbFieldName = dbFieldName end instance end |
.instantiationParameters(fieldElt) ⇒ Object
:nodoc:
17 18 19 20 21 22 23 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 17 def ObjectField.instantiationParameters( fieldElt ) #:nodoc: parameters = {} parameters['name'] = fieldElt.attributes['name'] parameters['englishName'] = fieldElt.attributes['englishName'] parameters['dbFieldName'] = fieldElt.attributes['dbFieldName'] parameters end |
.valueType ⇒ Object
:nodoc:
13 14 15 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 13 def ObjectField.valueType #:nodoc: Object end |
Instance Method Details
#<=>(other) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 130 def <=>(other) if @objectType == other.objectType && name == other.name 0 else object_id <=> other.object_id end end |
#bind_write? ⇒ Boolean
:nodoc:
52 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 52 def bind_write?; false; end |
#db_table_and_field_name ⇒ Object
54 55 56 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 54 def db_table_and_field_name "#{ objectType.tableName }.#{ dbFieldName }" end |
#dbWillAutomaticallyWrite ⇒ Object
:nodoc:
138 139 140 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 138 def dbWillAutomaticallyWrite #:nodoc: false end |
#englishName ⇒ Object
:nodoc:
58 59 60 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 58 def englishName #:nodoc: @englishNameOrNil || English.camelCaseToEnglish(name).capitalize end |
#firstTime(fieldManager) ⇒ Object
:nodoc:
110 111 112 113 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 110 def firstTime(fieldManager) #:nodoc: pkId = fieldManager.getpkId pkId == nil end |
#nameForSQL ⇒ Object
Returns the name that this field is referenced by in the MySQL table. By default this is the same as the name; to override it, set ObjectField#dbFieldName.
100 101 102 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 100 def nameForSQL dbFieldName end |
#nullErrorMsg ⇒ Object
:nodoc:
62 63 64 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 62 def nullErrorMsg #:nodoc: English.sentence "Please enter %a %nam.", englishName.downcase end |
#prevValue(pkId) ⇒ Object
:nodoc:
115 116 117 118 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 115 def prevValue(pkId) #:nodoc: prevObject = ObjectStore.getObjectStore.get(@objectType, pkId) prevObject.send(name) end |
#processBeforeVerify(value) ⇒ Object
:nodoc:
120 121 122 123 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 120 def processBeforeVerify(value) #:nodoc: value = @default if value == nil value end |
#valueForSQL(value) ⇒ Object
Returns a string value suitable for committing this field’s value to MySQL.
106 107 108 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 106 def valueForSQL(value) value || 'null' end |
#valueFromSQL(string) ⇒ Object
Given the SQL value string, returns a Ruby-native value.
126 127 128 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 126 def valueFromSQL(string) string end |
#verify(value, pkId) ⇒ Object
:nodoc:
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 66 def verify(value, pkId) #:nodoc: if value.nil? && notNull raise FieldValueError, nullErrorMsg, caller end if value valueType = self.class.valueType unless value.class <= valueType raise FieldValueError, "#{name} needs an object of type #{valueType.name}", caller end verifyUniqueness(value, pkId) if unique end end |
#verifyUniqueness(value, pkId) ⇒ Object
:nodoc:
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/lafcadio/objectField/ObjectField.rb', line 80 def verifyUniqueness(value, pkId) #:nodoc: inferrer = Query::Inferrer.new( @objectType ) { |domain_obj| Query.And( domain_obj.send( self.name ).equals( value ), domain_obj.pkId.equals( pkId ).not ) } collisions = ObjectStore.getObjectStore.getSubset( inferrer.execute ) if collisions.size > 0 if @notUniqueMsg notUniqueMsg = @notUniqueMsg else notUniqueMsg = "That #{englishName.downcase} is already taken. " + "Please choose another." end raise FieldValueError, notUniqueMsg, caller end end |