Class: SdbDal::DomainAttributeDescription
- Inherits:
-
Object
- Object
- SdbDal::DomainAttributeDescription
- Includes:
- SdbFormatter
- Defined in:
- lib/sdb_dal/domain_attribute_description.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#is_collection ⇒ Object
Returns the value of attribute is_collection.
-
#is_encrypted ⇒ Object
Returns the value of attribute is_encrypted.
-
#is_primary_key ⇒ Object
Returns the value of attribute is_primary_key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value_type ⇒ Object
Returns the value of attribute value_type.
Class Method Summary collapse
Instance Method Summary collapse
- #format_for_sdb(value) ⇒ Object
- #format_for_sdb_single(value) ⇒ Object
-
#initialize(name, type, is_encrypted = false, options = {}) ⇒ DomainAttributeDescription
constructor
A new instance of DomainAttributeDescription.
- #is_clob ⇒ Object
- #parse_from_sdb(value) ⇒ Object
- #parse_from_sdb_single(value) ⇒ Object
Methods included from SdbFormatter
#format_boolean, #format_date, #format_float, #format_integer, #format_reference_set, #format_string, #format_unsigned_integer, #parse_boolean, #parse_date, #parse_float, #parse_integer, #parse_reference_set, #parse_unsigned_integer, #zero_pad_float, #zero_pad_integer
Constructor Details
#initialize(name, type, is_encrypted = false, options = {}) ⇒ DomainAttributeDescription
Returns a new instance of DomainAttributeDescription.
18 19 20 21 22 23 24 25 26 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 18 def initialize(name,type,is_encrypted=false,={}) self.name=name self.value_type=type self.is_collection=(type==:reference_set) self.is_collection ||= ( .has_key?(:is_collection) and [:is_collection]) self.is_primary_key=.has_key?(:is_primary_key) && [:is_primary_key]==true self.is_encrypted=is_encrypted self.is_encrypted=[:is_encrypted] if .has_key?(:is_encrypted) end |
Instance Attribute Details
#is_collection ⇒ Object
Returns the value of attribute is_collection.
10 11 12 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 10 def is_collection @is_collection end |
#is_encrypted ⇒ Object
Returns the value of attribute is_encrypted.
11 12 13 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 11 def is_encrypted @is_encrypted end |
#is_primary_key ⇒ Object
Returns the value of attribute is_primary_key.
9 10 11 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 9 def is_primary_key @is_primary_key end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 7 def name @name end |
#value_type ⇒ Object
Returns the value of attribute value_type.
8 9 10 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 8 def value_type @value_type end |
Class Method Details
.crypto ⇒ Object
13 14 15 16 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 13 def self.crypto @@crypto||= Configuration.singleton.crypto @@crypto end |
Instance Method Details
#format_for_sdb(value) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 30 def format_for_sdb(value) return format_for_sdb_single( value) unless self.is_collection==true result=[] value.each do |single_value| result << format_for_sdb_single( single_value) end result end |
#format_for_sdb_single(value) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 38 def format_for_sdb_single(value) return nil if value == nil && self.value_type!=:boolean if self.value_type==:integer result= format_integer(value) elsif self.value_type==:reference_set result= format_reference_set(value) elsif self.value_type==:date result= format_date(value) elsif self.value_type==:boolean result= format_boolean(value) elsif self.value_type==:unsigned_integer result= format_unsigned_integer(value) elsif self.value_type==:float result= format_float(value) else result= format_string(value.to_s) end if is_encrypted result=DomainAttributeDescription.crypto.encrypt(result) end result end |
#is_clob ⇒ Object
27 28 29 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 27 def is_clob return self.value_type==:clob end |
#parse_from_sdb(value) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 62 def parse_from_sdb( value) return parse_from_sdb_single( value) unless self.is_collection==true return [] unless value result=[] value.each do |single_value| result << parse_from_sdb_single( single_value) end result end |
#parse_from_sdb_single(value) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sdb_dal/domain_attribute_description.rb', line 72 def parse_from_sdb_single( value) return nil if value==nil if is_encrypted begin value=DomainAttributeDescription.crypto.decrypt(value) rescue #assume wasn't encrypted originally end end if self.value_type==:integer return parse_integer(value) elsif self.value_type==:date return parse_date(value) elsif self.value_type==:reference_set return parse_reference_set(value) elsif self.value_type==:boolean return parse_boolean(value) elsif self.value_type==:unsigned_integer return parse_unsigned_integer(value) elsif self.value_type==:float return parse_float(value) else return value.to_s end return value end |