Class: ActiveLdap::Association::Collection — activeldap - ActiveLdap

Class: ActiveLdap::Association::Collection

Inherits:
Proxy
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_ldap/association/collection.rb

Direct Known Subclasses

BelongsToMany, Children, HasMany, HasManyWrap

Instance Method Summary (collapse)

Methods inherited from Proxy

#===, #initialize, #loaded, #loaded?, #proxy_respond_to?, #reload, #respond_to?, #target, #target=

Constructor Details

This class inherits a constructor from ActiveLdap::Association::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveLdap::Association::Proxy

Instance Method Details

- (Object) <<(*entries) Also known as: push, concat



18
19
20
# File 'lib/active_ldap/association/collection.rb', line 18

def <<(*entries)
  add_entries(*entries)
end

- (Object) delete(*entries)



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_ldap/association/collection.rb', line 28

def delete(*entries)
  entries = flatten_deeper(entries).reject do |entry|
    @target.delete(entry) if entry.new_entry?
    entry.new_entry?
  end
  return if entries.empty?

  delete_entries(entries)
  entries.each do |entry|
    @target.delete(entry)
  end
end

- (Object) each(&block)



24
25
26
# File 'lib/active_ldap/association/collection.rb', line 24

def each(&block)
  to_ary.each(&block)
end

- (Boolean) exists?

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/active_ldap/association/collection.rb', line 62

def exists?
  load_target
  not @target.empty?
end

- (Object) replace(others)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_ldap/association/collection.rb', line 41

def replace(others)
  load_target

  entry = @target.first
  if entry.nil?
    deleted_entries = []
    added_entries = others
  else
    base_class = entry.class
    others = others.collect do |other|
      other = base_class.find(other) unless other.is_a?(base_class)
      other
    end
    deleted_entries = @target - others
    added_entries = others - @target
  end

  delete(deleted_entries)
  concat(added_entries)
end

- (Object) reset



13
14
15
16
# File 'lib/active_ldap/association/collection.rb', line 13

def reset
  @target = []
  @loaded = false
end

- (Object) to_ary



8
9
10
11
# File 'lib/active_ldap/association/collection.rb', line 8

def to_ary
  load_target
  @target.to_ary
end