Module: ROM::LDAP::Relation::Reading
- Included in:
- ROM::LDAP::Relation
- Defined in:
- lib/rom/ldap/relation/reading.rb
Instance Method Summary collapse
- #all?(&block) ⇒ Boolean
- #any?(&block) ⇒ Boolean (also: #exist?)
-
#authenticate(password) ⇒ Boolean
Returns True if the filtered entity can bind.
-
#branch(key) ⇒ Object
An alternative search base selected from a class level hash.
-
#by_pk(*pks) ⇒ Relation
Find tuples by primary_key which defaults to :entry_dn Method is required by commands.
-
#count ⇒ Integer
Count the number of entries selected from the paginated dataset.
-
#fetch(*pk) ⇒ Hash
Fetch a tuple identified by the pk.
-
#first ⇒ Hash
First tuple from the relation.
-
#grep(value) ⇒ Relation
(also: #find)
Searches attributes of the projected schema for a match.
-
#last ⇒ Hash
Last tuple from the relation.
-
#limit(number) ⇒ Relation
Limits the dataset to a number of tuples.
-
#list(field) ⇒ Array<Mixed>
Array of values for an :attribute from all tuples.
-
#map(key = nil, &block) ⇒ Array<Array>
Map tuples from the relation.
- #none?(&block) ⇒ Boolean
- #one? ⇒ Boolean (also: #distinct?, #unique?)
-
#operational ⇒ Relation
Include internal operational attributes in the tuples.
-
#order(*attribute) ⇒ Relation
Use server-side sorting if available.
-
#pluck(*names) ⇒ Array<String, Array>
Pluck value(s) from specific attribute(s) unwrapped only if all are lone results.
-
#random ⇒ Relation
Shuffles the dataset.
-
#rename(mapping) ⇒ Relation
Rename attributes in a relation.
-
#reverse ⇒ Relation
Reverses the dataset.
-
#search(new_filter) ⇒ Relation
Replace the relation filter with a new query.
-
#select(*args, &block) ⇒ Relation
(also: #project)
Select specific attributes.
-
#select_append(*args, &block) ⇒ Relation
Append specific columns to select clause.
-
#total ⇒ Integer
Count the number of entries in the dataset.
-
#unfiltered ⇒ Relation
Remove additional search criteria and return to initial filter.
-
#unwrap ⇒ LDAP::Relation
Returns tuples with popped values.
-
#where(*args, &block) ⇒ Object
Overwrites forwarding to Dataset#where.
-
#whole_tree ⇒ Relation
Change the search base to search the whole directory tree.
-
#with_base(alt_base) ⇒ Relation
Specify an alternative search base.
Instance Method Details
#all?(&block) ⇒ Boolean
168 169 170 |
# File 'lib/rom/ldap/relation/reading.rb', line 168 def all?(&block) dataset.__send__(__method__, &block) end |
#any?(&block) ⇒ Boolean Also known as: exist?
153 154 155 |
# File 'lib/rom/ldap/relation/reading.rb', line 153 def any?(&block) dataset.__send__(__method__, &block) end |
#authenticate(password) ⇒ Boolean
Returns True if the filtered entity can bind.
80 81 82 |
# File 'lib/rom/ldap/relation/reading.rb', line 80 def authenticate(password) dataset.bind(password) end |
#branch(key) ⇒ Object
An alternative search base selected from a class level hash.
42 43 44 |
# File 'lib/rom/ldap/relation/reading.rb', line 42 def branch(key) with_base(self.class.branches[key]) end |
#by_pk(*pks) ⇒ Relation
Find tuples by primary_key which defaults to :entry_dn Method is required by commands.
182 183 184 |
# File 'lib/rom/ldap/relation/reading.rb', line 182 def by_pk(*pks) where(primary_key => pks) end |
#count ⇒ Integer
Count the number of entries selected from the paginated dataset.
128 129 130 |
# File 'lib/rom/ldap/relation/reading.rb', line 128 def count dataset.__send__(__method__) end |
#fetch(*pk) ⇒ Hash
Fetch a tuple identified by the pk
198 199 200 |
# File 'lib/rom/ldap/relation/reading.rb', line 198 def fetch(*pk) by_pk(*pk).one! end |
#first ⇒ Hash
First tuple from the relation
210 211 212 |
# File 'lib/rom/ldap/relation/reading.rb', line 210 def first dataset.first.to_h end |
#grep(value) ⇒ Relation Also known as: find
Searches attributes of the projected schema for a match.
320 321 322 323 324 325 |
# File 'lib/rom/ldap/relation/reading.rb', line 320 def grep(value) = schema.attributes.select { |a| a.[:grep] } fields = .any? ? : schema new(dataset.grep(fields.map(&:name).sort, value)) end |
#last ⇒ Hash
Last tuple from the relation
222 223 224 |
# File 'lib/rom/ldap/relation/reading.rb', line 222 def last dataset.reverse_each.first.to_h end |
#limit(number) ⇒ Relation
Limits the dataset to a number of tuples
294 295 296 |
# File 'lib/rom/ldap/relation/reading.rb', line 294 def limit(number) new(dataset.with(limit: number)) end |
#list(field) ⇒ Array<Mixed>
Array of values for an :attribute from all tuples.
115 116 117 118 119 120 121 |
# File 'lib/rom/ldap/relation/reading.rb', line 115 def list(field) if auto_struct? to_a.flat_map(&field) else map(field).to_a.compact.flatten end end |
#map(key = nil, &block) ⇒ Array<Array>
Map tuples from the relation
99 100 101 |
# File 'lib/rom/ldap/relation/reading.rb', line 99 def map(key = nil, &block) dataset.map(key, &block) end |
#none?(&block) ⇒ Boolean
161 162 163 |
# File 'lib/rom/ldap/relation/reading.rb', line 161 def none?(&block) dataset.__send__(__method__, &block) end |
#one? ⇒ Boolean Also known as: distinct?, unique?
144 145 146 |
# File 'lib/rom/ldap/relation/reading.rb', line 144 def one? dataset.__send__(__method__) end |
#operational ⇒ Relation
Include internal operational attributes in the tuples.
60 61 62 |
# File 'lib/rom/ldap/relation/reading.rb', line 60 def operational new(dataset.with(attrs: ALL_ATTRS)) end |
#order(*attribute) ⇒ Relation
Use server-side sorting if available.
Orders the dataset by a given attribute using the coerced value.
SortResult ::= SEQUENCE {
sortResult ENUMERATED {
success (0), -- results are sorted
operationsError (1), -- server internal failure
timeLimitExceeded (3), -- timelimit reached before
-- sorting was completed
strongAuthRequired (8), -- refused to return sorted
-- results via insecure
-- protocol
adminLimitExceeded (11), -- too many matching entries
-- for the server to sort
noSuchAttribute (16), -- unrecognized attribute
-- type in sort key
inappropriateMatching (18), -- unrecognized or inappro-
-- priate matching rule in
-- sort key
insufficientAccessRights (50), -- refused to return sorted
-- results to this client
busy (51), -- too busy to process
unwillingToPerform (53), -- unable to sort
other (80)
},
attributeType [0] AttributeType OPTIONAL }
269 270 271 |
# File 'lib/rom/ldap/relation/reading.rb', line 269 def order(*attribute) new(dataset.with(sort_attrs: attribute)) end |
#pluck(*names) ⇒ Array<String, Array>
Pluck value(s) from specific attribute(s)
unwrapped only if all are lone results.
377 378 379 380 381 382 383 384 385 |
# File 'lib/rom/ldap/relation/reading.rb', line 377 def pluck(*names) raise ArgumentError, 'no attributes provided' if names.empty? map do |entry| results = values = names.map { |n| entry[n] } results = values.map(&:pop) if values.map(&:one?).all? results.one? ? results.pop : results end end |
#random ⇒ Relation
Shuffles the dataset.
306 307 308 |
# File 'lib/rom/ldap/relation/reading.rb', line 306 def random new(dataset.with(random: true)) end |
#rename(mapping) ⇒ Relation
Rename attributes in a relation
This method is intended to be used internally within a relation object
443 444 445 |
# File 'lib/rom/ldap/relation/reading.rb', line 443 def rename(mapping) schema.rename(mapping).call(self) end |
#reverse ⇒ Relation
Reverses the dataset. Use server-side sorting if available.
282 283 284 |
# File 'lib/rom/ldap/relation/reading.rb', line 282 def reverse new(dataset.with(direction: :desc)) end |
#search(new_filter) ⇒ Relation
Replace the relation filter with a new query.
71 72 73 |
# File 'lib/rom/ldap/relation/reading.rb', line 71 def search(new_filter) new(dataset.with(name: new_filter)) end |
#select(*attributes) ⇒ Relation #select(&block) ⇒ Relation Also known as: project
Select specific attributes
425 426 427 |
# File 'lib/rom/ldap/relation/reading.rb', line 425 def select(*args, &block) schema.project(*args, &block).call(self) end |
#select_append(*args, &block) ⇒ Relation
Append specific columns to select clause
454 455 456 |
# File 'lib/rom/ldap/relation/reading.rb', line 454 def select_append(*args, &block) schema.merge(schema.canonical.project(*args, &block)).call(self) end |
#total ⇒ Integer
Count the number of entries in the dataset.
137 138 139 |
# File 'lib/rom/ldap/relation/reading.rb', line 137 def total dataset.__send__(__method__) end |
#unfiltered ⇒ Relation
Remove additional search criteria and return to initial filter.
51 52 53 |
# File 'lib/rom/ldap/relation/reading.rb', line 51 def unfiltered new(dataset.unfiltered) end |
#unwrap ⇒ LDAP::Relation
Returns tuples with popped values.
391 392 393 |
# File 'lib/rom/ldap/relation/reading.rb', line 391 def unwrap new Functions[:map_array, Functions[:map_values, :pop]].call(self) end |
#where(*args, &block) ⇒ Object
Overwrites forwarding to Dataset#where
A Hash argument is passed straight to Dataset#equal. Otherwise the RestrictionDSL builds abstract queries
346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/rom/ldap/relation/reading.rb', line 346 def where(*args, &block) if block where(args).where(schema.restriction(&block)) elsif args.size == 1 && args[0].is_a?(Hash) new(dataset.equal(args[0])) elsif !args.empty? new(dataset.join(args)) else self end end |
#whole_tree ⇒ Relation
Change the search base to search the whole directory tree.
28 29 30 |
# File 'lib/rom/ldap/relation/reading.rb', line 28 def whole_tree with_base(EMPTY_STRING) end |
#with_base(alt_base) ⇒ Relation
Specify an alternative search base.
16 17 18 |
# File 'lib/rom/ldap/relation/reading.rb', line 16 def with_base(alt_base) new(dataset.with(base: alt_base)) end |