| Class | URI::LDAP |
| In: |
lib/uri/ldap.rb
|
| Parent: | Generic |
| DEFAULT_PORT | = | 389 |
| COMPONENT | = | [ :scheme, :host, :port, :dn, :attributes, :scope, :filter, :extensions, ].freeze |
| SCOPE | = | [ SCOPE_ONE = 'one', SCOPE_SUB = 'sub', SCOPE_BASE = 'base', ].freeze |
# File lib/uri/ldap.rb, line 41
41: def self.build(args)
42: tmp = Util::make_components_hash(self, args)
43:
44: if tmp[:dn]
45: tmp[:path] = tmp[:dn]
46: end
47:
48: query = []
49: [:extensions, :filter, :scope, :attributes].collect do |x|
50: next if !tmp[x] && query.size == 0
51: query.unshift(tmp[x])
52: end
53:
54: tmp[:query] = query.join('?')
55:
56: return super(tmp)
57: end
# File lib/uri/ldap.rb, line 59
59: def initialize(*arg)
60: super(*arg)
61:
62: if @fragment
63: raise InvalidURIError, 'bad LDAP URL'
64: end
65:
66: parse_dn
67: parse_query
68: end
# File lib/uri/ldap.rb, line 131
131: def attributes=(val)
132: set_attributes(val)
133: val
134: end
# File lib/uri/ldap.rb, line 179
179: def extensions=(val)
180: set_extensions(val)
181: val
182: end
# File lib/uri/ldap.rb, line 124
124: def set_attributes(val)
125: @attributes = val
126: build_path_query
127: @attributes
128: end
# File lib/uri/ldap.rb, line 108
108: def set_dn(val)
109: @dn = val
110: build_path_query
111: @dn
112: end
# File lib/uri/ldap.rb, line 172
172: def set_extensions(val)
173: @extensions = val
174: build_path_query
175: @extensions
176: end
# File lib/uri/ldap.rb, line 156
156: def set_filter(val)
157: @filter = val
158: build_path_query
159: @filter
160: end
# File lib/uri/ldap.rb, line 140
140: def set_scope(val)
141: @scope = val
142: build_path_query
143: @scope
144: end
# File lib/uri/ldap.rb, line 92
92: def build_path_query
93: @path = '/' + @dn
94:
95: query = []
96: [@extensions, @filter, @scope, @attributes].each do |x|
97: next if !x && query.size == 0
98: query.unshift(x)
99: end
100: @query = query.join('?')
101: end
# File lib/uri/ldap.rb, line 75
75: def parse_query
76: @attributes = nil
77: @scope = nil
78: @filter = nil
79: @extensions = nil
80:
81: if @query
82: attrs, scope, filter, extensions = @query.split('?')
83:
84: @attributes = attrs if attrs && attrs.size > 0
85: @scope = scope if scope && scope.size > 0
86: @filter = filter if filter && filter.size > 0
87: @extensions = extensions if extensions && extensions.size > 0
88: end
89: end