1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
module ActiveLdap
module AttributeMethods
module Read
extend ActiveSupport::Concern
private
def attribute(attr, *args)
return get_attribute(attr, args.first)
end
def _read_attribute(name)
get_attribute(name)
end
# get_attribute
#
# Return the value of the attribute called by method_missing?
def get_attribute(name, force_array=false)
name, value = get_attribute_before_type_cast(name, force_array)
return value if name.nil?
attribute = schema.attribute(name)
type_cast(attribute, value)
end
def type_cast(attribute, value)
case value
when Hash
result = {}
value.each do |option, val|
result[option] = type_cast(attribute, val)
end
if result.size == 1 and result.has_key?("binary")
result["binary"]
else
result
end
when Array
value.collect do |val|
type_cast(attribute, val)
end
else
attribute.type_cast(value)
end
end
end
end
end
|