Class: Acs::Ldap::Pusher
- Inherits:
-
Object
- Object
- Acs::Ldap::Pusher
- Defined in:
- lib/acs/ldap/pusher.rb
Instance Method Summary collapse
- #count ⇒ Object
- #create(model, options = {}) ⇒ Object
- #destroy(model, options = {}) ⇒ Object
- #exist?(model) ⇒ Boolean
- #find_by(key, value) ⇒ Object
- #flush ⇒ Object
- #index ⇒ Object
-
#initialize(connector, options = {}) ⇒ Pusher
constructor
connector : Acs::Ldap::Connector instance options : directly set a mapper at initialization.
- #mapper=(mapper) ⇒ Object
- #save(model, options = {}) ⇒ Object
- #update(model, options = {}) ⇒ Object
Constructor Details
Instance Method Details
#count ⇒ Object
79 80 81 82 |
# File 'lib/acs/ldap/pusher.rb', line 79 def count filter = Net::LDAP::Filter.pres('uid') @connector.search({base: base, filter: filter}).data.count end |
#create(model, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/acs/ldap/pusher.rb', line 27 def create(model, = {}) attributes = @mapper.attributes(model).except!(:uid) attributes.merge!(objectClass: @mapper.object_class) Acs::Ldap.logger.debug "Pusher#create dn '#{dn(model)}' attributes '#{attributes.inspect}'" @connector.add( dn(model), attributes ) end |
#destroy(model, options = {}) ⇒ Object
59 60 61 |
# File 'lib/acs/ldap/pusher.rb', line 59 def destroy(model, = {}) @connector.delete(dn(model)) end |
#exist?(model) ⇒ Boolean
67 68 69 |
# File 'lib/acs/ldap/pusher.rb', line 67 def exist?(model) @connector.search({base: dn(model)}).data.length > 0 end |
#find_by(key, value) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/acs/ldap/pusher.rb', line 71 def find_by(key, value) @connector.search_by( base, key, value ) end |
#flush ⇒ Object
63 64 65 |
# File 'lib/acs/ldap/pusher.rb', line 63 def flush @connector.delete_all(ou) end |
#index ⇒ Object
22 23 24 25 |
# File 'lib/acs/ldap/pusher.rb', line 22 def index filter = Net::LDAP::Filter.pres('uid') @connector.search({base: base, filter: filter}) end |
#mapper=(mapper) ⇒ Object
10 11 12 |
# File 'lib/acs/ldap/pusher.rb', line 10 def mapper=(mapper) @mapper = mapper end |
#save(model, options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/acs/ldap/pusher.rb', line 14 def save(model, = {}) if exist?(model) update(model) else create(model) end end |
#update(model, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/acs/ldap/pusher.rb', line 39 def update(model, = {}) changes = .fetch(:changes, nil) attributes = @mapper.attributes(model).except(:uid) operations = [] attributes.each do |key, value| if attributes.nil? or attributes.include?(key) if changes.nil? operations << [:replace, key.to_s, value] else operations << [:replace, key.to_s, value] if changes.has_key?(key) end end end @connector.update( dn(model), operations ) end |