Class: Ldapter::AttributeSet
- Inherits:
-
Object
- Object
- Ldapter::AttributeSet
- Defined in:
- lib/ldapter/attribute_set.rb
Overview
AttributeSet, like the name suggests, represents a set of attributes. Most operations are delegated to an array, so the usual array methods should work transparently.
Instance Attribute Summary (collapse)
-
- (Object) type
readonly
Returns the value of attribute type.
Instance Method Summary (collapse)
-
- (Object) ===(object)
:nodoc:.
-
- (Object) add(*attributes)
(also: #<<, #concat, #push)
Adds the given attributes, discarding duplicates.
-
- (Object) add!(*attributes)
Add the desired attributes to the LDAP server immediately.
- - (Object) as_json(*args)
-
- (Object) before_type_cast
The original attributes before type conversion.
-
- (Object) clear
:nodoc:.
-
- (Object) collect!(&block)
(also: #map!)
:nodoc:.
-
- (Object) delete(*attributes, &block)
(also: #subtract)
Remove the given attributes given, functioning more or less like Array#delete, except accepting multiple arguments.
-
- (Object) delete!(*attributes)
Delete the desired values from the attribute at the LDAP server.
-
- (Object) delete_if(&block)
:nodoc:.
- - (Object) errors
-
- (AttributeSet) initialize(object, key, target)
constructor
:nodoc:.
-
- (Object) insert(index, *objects)
:nodoc:.
-
- (Boolean) mandatory?
Returns true if the attribute is marked MUST in the object class.
-
- (Object) method_missing(method, *args, &block)
Delegates to an array.
-
- (Boolean) no_user_modification?
Returns true for read only attributes.
-
- (Object) reduce
If the attribute is a single value, return it, otherwise, return self.
-
- (Object) reject!(&block)
:nodoc:.
-
- (Object) replace(*attributes)
Does a complete replacement of the attributes.
-
- (Object) replace!(*attributes)
Replace the entire attribute at the LDAP server immediately.
-
- (Boolean) respond_to?(method)
(also: #proxy_respond_to?)
:nodoc:.
-
- (Boolean) single_value?
Returns true if the attribute may not be specified more than once.
- - (Object) to_s
-
- (Object) unshift(*values)
:nodoc:.
Constructor Details
- (AttributeSet) initialize(object, key, target)
:nodoc:
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ldapter/attribute_set.rb', line 22 def initialize(object, key, target) #:nodoc: @object = object @key = LDAP.encode(key) @type = @object.namespace.attribute_type(@key) @syntax = @object.namespace.attribute_syntax(@key) @target = target if @type.nil? @object.logger.warn("ldapter") { "Unknown attribute type #{@key}" } elsif @syntax.nil? @object.logger.warn("ldapter") { "Unknown syntax #{@type.syntax_oid} for attribute type #{Array(@type.name).first}" } end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block)
Delegates to an array.
36 37 38 |
# File 'lib/ldapter/attribute_set.rb', line 36 def method_missing(method,*args,&block) typecast(@target).send(method,*args,&block) end |
Instance Attribute Details
- (Object) type (readonly)
Returns the value of attribute type
194 195 196 |
# File 'lib/ldapter/attribute_set.rb', line 194 def type @type end |
Instance Method Details
- (Object) ===(object)
:nodoc:
40 41 42 |
# File 'lib/ldapter/attribute_set.rb', line 40 def ===(object) #:nodoc: typecast(@target) === object end |
- (Object) add(*attributes) Also known as: <<, concat, push
Adds the given attributes, discarding duplicates. Currently, a duplicate is determined by == (case sensitive) rather than by the server (typically case insensitive). All arrays are flattened.
51 52 53 54 55 56 57 58 |
# File 'lib/ldapter/attribute_set.rb', line 51 def add(*attributes) dest = @target.dup safe_array(attributes).each do |attribute| dest.push(attribute) unless self.include?(attribute) end replace(dest) self end |
- (Object) add!(*attributes)
Add the desired attributes to the LDAP server immediately.
61 62 63 64 |
# File 'lib/ldapter/attribute_set.rb', line 61 def add!(*attributes) @object.add!(@key, safe_array(attributes)) self end |
- (Object) as_json(*args)
211 212 213 |
# File 'lib/ldapter/attribute_set.rb', line 211 def as_json(*args) typecast(@target).as_json(*args) end |
- (Object) before_type_cast
The original attributes before type conversion. Mutating the result mutates the original attributes.
18 19 20 |
# File 'lib/ldapter/attribute_set.rb', line 18 def before_type_cast @target end |
- (Object) clear
:nodoc:
89 90 91 92 |
# File 'lib/ldapter/attribute_set.rb', line 89 def clear #:nodoc: replace([]) self end |
- (Object) collect!(&block) Also known as: map!
:nodoc:
129 130 131 |
# File 'lib/ldapter/attribute_set.rb', line 129 def collect!(&block) #:nodoc: replace(typecast(@target).collect(&block)) end |
- (Object) delete(*attributes, &block) Also known as: subtract
Remove the given attributes given, functioning more or less like Array#delete, except accepting multiple arguments.
Two passes are made to find each element, one case sensitive and one ignoring case, before giving up.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ldapter/attribute_set.rb', line 99 def delete(*attributes,&block) return clear if attributes.flatten.empty? dest = @target.dup ret = [] safe_array(attributes).each do |attribute| ret << dest.delete(attribute) do match = dest.detect {|x| x.downcase == attribute.downcase} if match dest.delete(match) else yield(attribute) if block_given? end end end replace(dest) if attributes.size == 1 && !attributes.first.kind_of?(Array) typecast ret.first else # typecast ret self end end |
- (Object) delete!(*attributes)
Delete the desired values from the attribute at the LDAP server. If no values are given, the entire attribute is removed.
124 125 126 127 |
# File 'lib/ldapter/attribute_set.rb', line 124 def delete!(*attributes) @object.delete!(@key, safe_array(attributes)) self end |
- (Object) delete_if(&block)
:nodoc:
146 147 148 149 |
# File 'lib/ldapter/attribute_set.rb', line 146 def delete_if(&block) #:nodoc: reject!(&block) self end |
- (Object) errors
79 80 81 |
# File 'lib/ldapter/attribute_set.rb', line 79 def errors errors_for(@target) end |
- (Object) insert(index, *objects)
:nodoc:
133 134 135 |
# File 'lib/ldapter/attribute_set.rb', line 133 def insert(index, *objects) #:nodoc: replace(typecast(@target).insert(index, *objects.flatten)) end |
- (Boolean) mandatory?
Returns true if the attribute is marked MUST in the object class.
171 172 173 |
# File 'lib/ldapter/attribute_set.rb', line 171 def mandatory? @object.must.include?(@key) end |
- (Boolean) no_user_modification?
Returns true for read only attributes.
181 182 183 |
# File 'lib/ldapter/attribute_set.rb', line 181 def no_user_modification? @type && @type.no_user_modification? end |
- (Object) reduce
If the attribute is a single value, return it, otherwise, return self.
186 187 188 189 190 191 192 |
# File 'lib/ldapter/attribute_set.rb', line 186 def reduce if single_value? first else self end end |
- (Object) reject!(&block)
:nodoc:
141 142 143 144 |
# File 'lib/ldapter/attribute_set.rb', line 141 def reject!(&block) #:nodoc: array = typecast(@target) replace(array) if array.reject!(&block) end |
- (Object) replace(*attributes)
Does a complete replacement of the attributes. Multiple attributes can be given as either multiple arguments or as an array.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ldapter/attribute_set.rb', line 68 def replace(*attributes) attributes = safe_array(attributes) if no_user_modification? Ldapter::Errors.raise(TypeError.new("read-only attribute #{@key}")) elsif !@object.respond_to?(:valid?) && error = errors_for(attributes).first Ldapter::Errors.raise(TypeError.new("#@key #{error}")) end @target.replace(attributes) self end |
- (Object) replace!(*attributes)
Replace the entire attribute at the LDAP server immediately.
84 85 86 87 |
# File 'lib/ldapter/attribute_set.rb', line 84 def replace!(*attributes) @object.replace!(@key, safe_array(attributes)) self end |
- (Boolean) respond_to?(method) Also known as: proxy_respond_to?
:nodoc:
44 45 46 |
# File 'lib/ldapter/attribute_set.rb', line 44 def respond_to?(method) #:nodoc: proxy_respond_to?(method) || @target.respond_to?(method) end |
- (Boolean) single_value?
Returns true if the attribute may not be specified more than once.
176 177 178 |
# File 'lib/ldapter/attribute_set.rb', line 176 def single_value? @type && @type.single_value? end |
- (Object) to_s
196 197 198 |
# File 'lib/ldapter/attribute_set.rb', line 196 def to_s @target.join("\n") end |
- (Object) unshift(*values)
:nodoc:
137 138 139 |
# File 'lib/ldapter/attribute_set.rb', line 137 def unshift(*values) #:nodoc: insert(0,*values) end |