Class: ROM::LDAP::Dataset Private

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Includes:
Enumerable, ActiveSupportInstrumentation, Conversion, DSL, Persistence
Defined in:
lib/rom/ldap/dataset.rb,
lib/rom/ldap/dataset/dsl.rb,
lib/rom/ldap/dataset/conversion.rb,
lib/rom/ldap/dataset/persistence.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Modules: Conversion, DSL, Persistence

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversion

included, #to_ast, #to_filter

Methods included from Persistence

#add, #delete, #modify

Methods included from DSL

#approx, #begins, #binary_equal, #bitwise, #contains, #ends, #equal, #excludes, #gt, #gte, #inverse, #lt, #lte, #missing, #outside, #present, #unequal, #within

Methods included from ActiveSupportInstrumentation

#call

Instance Attribute Details

#baseString (readonly)

Returns Set when initializing a relation.

Returns:

  • (String)

    Set when initializing a relation



35
# File 'lib/rom/ldap/dataset.rb', line 35

option :base, type: Types::DN, reader: :private, default: proc { directory.base }

#criteriaArray (readonly)

Returns Query AST.

Returns:

  • (Array)

    Query AST



40
# File 'lib/rom/ldap/dataset.rb', line 40

option :criteria, type: Types::Strict::Array, reader: :private, default: proc { EMPTY_ARRAY }

#directionSymbol (readonly)

Returns:

  • (Symbol)


45
# File 'lib/rom/ldap/dataset.rb', line 45

option :direction, type: Types::Direction, reader: :private, default: proc { :asc }

#directoryDirectory (readonly)

Returns:



23
# File 'lib/rom/ldap/dataset.rb', line 23

option :directory

#nameString (readonly)

Returns Valid LDAP filter filter string.

Returns:

  • (String)

    Valid LDAP filter filter string.



29
# File 'lib/rom/ldap/dataset.rb', line 29

option :name, type: Types::Filter, reader: :private

#offsetInteger (readonly)

Returns Pagination per_page(20).

Returns:

  • (Integer)

    Pagination per_page(20).



50
# File 'lib/rom/ldap/dataset.rb', line 50

option :offset, type: Types::Strict::Integer, reader: :private, optional: true

Class Method Details

.dslArray<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Collection of Dataset::DSL module methods.

Used by Relation to forward methods to Dataset.

Examples:

# => %i{equal has lt begins excludes present}

Returns:

  • (Array<Symbol>)


84
85
86
# File 'lib/rom/ldap/dataset.rb', line 84

def self.dsl
  DSL.public_instance_methods(false)
end

Instance Method Details

#bind(password) ⇒ Boolean

Validate the password against the filtered user.

Parameters:

  • password (String)

Returns:

  • (Boolean)


202
203
204
# File 'lib/rom/ldap/dataset.rb', line 202

def bind(password)
  directory.bind_as(filter: to_ast, password: password)
end

#each(*args, &block) ⇒ Array <Directory::Entry>, Enumerator <Directory::Entry>

Iterate over the entries return from the server.

Returns:



115
116
117
118
119
120
121
122
# 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

#exportHash+

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Handle different string output formats

i.e. DSML, LDIF, JSON, YAML, MessagePack.

Returns:

  • (Hash, Array<Hash>)


211
212
213
214
# File 'lib/rom/ldap/dataset.rb', line 211

def export
  results = map(&:canonical)
  results.one? ? results.first : results
end

#grep(attrs, value) ⇒ Relation

Wildcard search on multiple attributes.

Examples:

dataset.grep([:givenname, :sn], 'foo').opts[:criteria] =>
  [:con_or, [[:op_eql, :givenname, "*foo*"], [:op_eql, :sn, "*foo*"]]]

Parameters:

  • attrs (Array<Symbol>)

    schema attribute names

  • value (String)

    search parameter

Returns:

See Also:



167
168
169
170
171
172
# 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

#inspectString

Inspect dataset revealing current ast and base.

Returns:

  • (String)


138
139
140
# File 'lib/rom/ldap/dataset.rb', line 138

def inspect
  %(#<#{self.class}: base="#{base}" #{to_ast} />)
end

#join(new_criteria, constructor = :con_and) ⇒ Relation

Combine AST criteria - use AND by default

Parameters:

  • new_criteria (Array)
  • constructor (Symbol) (defaults to: :con_and)

Returns:

See Also:



184
185
186
187
188
189
190
191
192
193
# 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

#map(attr = nil, &block) ⇒ Mixed

Iterate over each entry or one attribute of each entry.

Returns:

  • (Mixed)


129
130
131
# File 'lib/rom/ldap/dataset.rb', line 129

def map(attr = nil, &block)
  each.map { |entry| attr ? entry[attr] : entry }.map(&block)
end

#optsHash

Returns internal options.

Returns:

  • (Hash)

    internal options



105
106
107
# File 'lib/rom/ldap/dataset.rb', line 105

def opts
  options.merge(ast: to_ast, filter: to_filter).freeze
end

#totalInteger

Unrestricted count of every entry under the search base

with the domain entry discounted.

Returns:

  • (Integer)


222
223
224
# File 'lib/rom/ldap/dataset.rb', line 222

def total
  directory.base_total - 1
end

#unfilteredDataset

This method is present in Sequel and ensures rom-sql/rom-ldap plugin interoperability.

Returns:



147
148
149
# File 'lib/rom/ldap/dataset.rb', line 147

def unfiltered
  with(criteria: EMPTY_ARRAY)
end

#with(overrides) ⇒ ROM::LDAP::Dataset

Initialise a new class overriding options.

Parameters:

  • overrides (Hash)

    Alternative options

Returns:



98
99
100
# File 'lib/rom/ldap/dataset.rb', line 98

def with(overrides)
  self.class.new(options.merge(overrides))
end