class UCB::LDAP::Schema::Attribute
UCB::LDAP::SchemaAttribute¶ ↑
This class models schema information about an LDAP
attribute.
This class is used internally by various UCB::LDAP
classes. Users of UCB::LDAP
probably won't need to interact with this class directly.
The LDAP
entity classes have access to their Attribute's.
uid_attr = UCB::LDAP::Person.attribute(:uid) # :symbol ok as attribute name uid_attr.name #=> 'uid' uid_attr.aliases #=> ['userid'] uid_attr.description #=> 'Standard LDAP attribute type' uid_attr.multi_valued? #=> true uid_attr.required? #=> true uid_attr.type #=> 'string' uas_attr = UCB::LDAP::Person.attribute('berkeleyEduNameGenerational') # case doesn't matter uas_attr.name #=> 'berkeleyEduNameGenerational' uas_attr.aliases #=> ['ucbvalidflag'] uas_attr.description #=> 'Generational Name' uas_attr.multi_valued? #=> false uas_attr.required? #=> false uas_attr.type #=> 'boolean'
Public Instance Methods
Returns Array of aliases as found in schema. Returns empty Array ([]) if no aliases.
# File lib/ucb_ldap/schema_attribute.rb, line 52 def aliases @aliases end
Return true
if attribute type is boolean.
# File lib/ucb_ldap/schema_attribute.rb, line 125 def boolean? type == "boolean" end
Takes a value returned from an LDAP
attribute (Array
of String
) and returns value with correct cardinality (array or scalar) cast to correct type
.
# File lib/ucb_ldap/schema_attribute.rb, line 90 def get_value(array) if array.nil? return false if boolean? return [] if multi_valued? return nil end typed_array = apply_type_to_array(array) multi_valued? ? typed_array : typed_array.first end
Return true
if attribute type is integer.
# File lib/ucb_ldap/schema_attribute.rb, line 120 def integer? type == "integer" end
Returns a value in LDAP
attribute value format (Array
of String
).
# File lib/ucb_ldap/schema_attribute.rb, line 135 def ldap_value(value) return nil if value.nil? return value.map{|v| ldap_value_stripped(v)} if value.instance_of?(Array) return [ldap_value_stripped(value)] end
Returns true
if attribute is multi-valued, else false
. Multi-valued attribute values are returned as an Array.
# File lib/ucb_ldap/schema_attribute.rb, line 83 def multi_valued? @multi_valued end
Returns attribute name as found in the schema
# File lib/ucb_ldap/schema_attribute.rb, line 45 def name @name end
Returns true
if attribute is required, else false
# File lib/ucb_ldap/schema_attribute.rb, line 77 def required? @required end
Return true
if attribute type is string.
# File lib/ucb_ldap/schema_attribute.rb, line 115 def string? type == "string" end
Return true
if attribute type is timestamp
# File lib/ucb_ldap/schema_attribute.rb, line 130 def timestamp? type == "timestamp" end
Returns (data) type. Used by get_value
() to cast value to correct Ruby type.
Supported types and corresponding Ruby type:
* string String * integer Fixnum * boolean TrueClass / FalseClass * timestamp DateTime (convenience methods may return Date if attribute's semantics don't include time)
# File lib/ucb_ldap/schema_attribute.rb, line 65 def type @type end
Private Instance Methods
Remove leading/trailing white-space and imbedded newlines.
# File lib/ucb_ldap/schema_attribute.rb, line 144 def ldap_value_stripped(s) s.to_s.strip.gsub(/\n/,"") end