class ROM::LDAP::Dataset
@api private
Public Class Methods
Collection of Dataset::DSL
module methods.
Used by Relation to forward methods to Dataset.
@return [Array<Symbol>]
@example
# => %i{equal has lt begins excludes present}
# File lib/rom/ldap/dataset.rb, line 84 def self.dsl DSL.public_instance_methods(false) end
Public Instance Methods
Validate the password against the filtered user.
@param password [String]
@return [Boolean]
@api public
# File lib/rom/ldap/dataset.rb, line 202 def bind(password) directory.bind_as(filter: to_ast, password: password) end
Iterate over the entries return from the server.
@return [Array <Directory::Entry>] @return [Enumerator <Directory::Entry>]
@api public
# File lib/rom/ldap/dataset.rb, line 115 def each(*args, &block) results = paginated? ? entries[page_range] : entries results = results.sort_by { rand } if random results = results.reverse_each if reversed? results = results.map { |e| apply_aliases(e) } if aliases.any? block_given? ? results.each(*args, &block) : results.to_enum end
Handle different string output formats
i.e. DSML, LDIF, JSON, YAML, MessagePack.
@return [Hash, Array<Hash>]
# File lib/rom/ldap/dataset.rb, line 211 def export results = map(&:canonical) results.one? ? results.first : results end
Wildcard search on multiple attributes.
@example
dataset.grep([:givenname, :sn], 'foo').opts[:criteria] => [:con_or, [[:op_eql, :givenname, "*foo*"], [:op_eql, :sn, "*foo*"]]]
@param attrs [Array<Symbol>] schema attribute names
@param value [String] search parameter
@return [Relation]
@api public
# File lib/rom/ldap/dataset.rb, line 167 def grep(attrs, value) new_criteria = attrs.map do |attr| match_dsl([[attr, value]], left: WILDCARD, right: WILDCARD) end join(new_criteria, :con_or) end
Inspect dataset revealing current ast and base.
@return [String]
@api public
# File lib/rom/ldap/dataset.rb, line 138 def inspect %(#<#{self.class}: base="#{base}" #{to_ast} />) end
@see Relation#where
Combine AST criteria - use AND by default
@param new_criteria [Array] @param constructor [Symbol]
@return [Relation]
@api public
# File lib/rom/ldap/dataset.rb, line 184 def join(new_criteria, constructor = :con_and) new_chain = join_dsl(constructor, new_criteria) # check because RestrictionDSL sometimes offers empty criteria if new_chain.empty? self else chain(*new_chain) end end
Iterate over each entry or one attribute of each entry.
@return [Mixed]
@api public
# File lib/rom/ldap/dataset.rb, line 129 def map(attr = nil, &block) each.map { |entry| attr ? entry[attr] : entry }.map(&block) end
@return [Hash] internal options
@api public
# File lib/rom/ldap/dataset.rb, line 105 def opts options.merge(ast: to_ast, filter: to_filter).freeze end
Unrestricted count of every entry under the search base
with the domain entry discounted.
@return [Integer]
@api public
# File lib/rom/ldap/dataset.rb, line 222 def total directory.base_total - 1 end
This method is present in Sequel and ensures rom-sql/rom-ldap plugin interoperability.
@return [Dataset]
@api public
# File lib/rom/ldap/dataset.rb, line 147 def unfiltered with(criteria: EMPTY_ARRAY) end
Initialise a new class overriding options.
@return [ROM::LDAP::Dataset]
@param overrides [Hash] Alternative options
@api public
# File lib/rom/ldap/dataset.rb, line 98 def with(overrides) self.class.new(**options.merge(overrides)) end
Private Instance Methods
# File lib/rom/ldap/dataset.rb, line 280 def alias_map { dn: :dn }.merge(attrs.zip(aliases).to_h) end
# File lib/rom/ldap/dataset.rb, line 276 def apply_aliases(entry) Functions[:rename_keys][alias_map, entry].invert end
Communicate with LDAP
servers.
@see Connection::SearchRequest for #query keywords defintion.
@return [Array<Hash>] Populate with a directory search.
@api private
# File lib/rom/ldap/dataset.rb, line 234 def entries results = directory.query( filter: to_ast, base: base, attributes: renamed_select, sorted: renamed_sort, max: limit, reverse: reversed? ) options[:criteria] = [] results end
@return [Range]
@api private
# File lib/rom/ldap/dataset.rb, line 262 def page_range offset..(offset + limit - 1) end
@api private
# File lib/rom/ldap/dataset.rb, line 267 def paginated? limit && offset end
@api private
# File lib/rom/ldap/dataset.rb, line 250 def renamed_select directory.canonical_attributes(attrs) if attrs end
@api private
# File lib/rom/ldap/dataset.rb, line 255 def renamed_sort directory.canonical_attributes(sort_attrs) if sort_attrs end
@api private
# File lib/rom/ldap/dataset.rb, line 272 def reversed? direction.eql?(:desc) end