Module: DataMapper::Model::LdapResource

Included in:
DataMapper::Model
Defined in:
lib/ldap_resource.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(password) ⇒ TrueClass, FalseClass

authenticate the current resource against the stored password

Parameters:

  • password (String)

    to authenticate

Returns:

  • (TrueClass, FalseClass)

    whether password was right or wrong



102
103
104
105
106
# File 'lib/ldap_resource.rb', line 102

def authenticate(password)
  ldap.authenticate(ldap.dn(self.class.dn_prefix(self),
                            self.class.treebase),
                    password)
end

#dn_prefix(prefix_or_resource = nil, &block) ⇒ String?

if called without parameter or block the given dn_prefix gets returned. if called with a block then the block gets stored. if called with a String then it gets stored. if called with a Resource then either the stored block gets called with that Resource or the stored String gets returned.

Parameters:

  • prefix_or_resource (String, DataMapper::Resource) (defaults to: nil)

    either a String, a Resource or nil

  • block (&block)

    to be stored for later calls

Returns:

  • (String, nil)

    when called with a Resource



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ldap_resource.rb', line 164

def dn_prefix(prefix_or_resource = nil, &block)
  if prefix_or_resource
    if prefix_or_resource.instance_of? String
      @ldap_dn = prefix_or_resource
    elsif @ldap_dn.instance_of? String
      @ldap_dn
    else
      @ldap_dn.call(prefix_or_resource)
    end
  else
    @ldap_dn = block
  end
end

#ldap_properties(properties_or_resource = nil, &block) ⇒ Hash

if called without parameter or block the given properties get returned. if called with a block then the block gets stored. if called with new properties they get stored. if called with a Resource then either the stored block gets called with that Resource or the stored properties get returned.

Parameters:

  • properties_or_resource (Hash, DataMapper::Resource) (defaults to: nil)

    either a Hash with properties, a Resource or nil

  • &block (block)

    to be stored for later calls when properties_or_resource is nil

Returns:

  • (Hash)

    when called with a Resource



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ldap_resource.rb', line 116

def ldap_properties(properties_or_resource = nil, &block)
  if properties_or_resource
    if properties_or_resource.instance_of? Hash
      @ldap_properties = properties_or_resource
    elsif @ldap_properties.instance_of? Hash
      @ldap_properties
    else
      @ldap_properties.call(properties_or_resource)
    end
  else
    @ldap_properties = block
  end
end

#multivalue_field(field = nil) ⇒ Symbol

if called without parameter then the stored field gets returned otherwise the given parameters gets stored

Parameters:

  • field (Symbol, String) (defaults to: nil)

    a new multivalue_field

Returns:

  • (Symbol)

    the multivalue_field



182
183
184
185
186
187
188
# File 'lib/ldap_resource.rb', line 182

def multivalue_field(field = nil)
  if field.nil?
    @ldap_multivalue_field
  else
    @ldap_multivalue_field = field.to_sym
  end
end

#treebase(base_or_resource = nil, &block) ⇒ String

if called without parameter or block the given treebase gets returned. if called with a block then the block gets stored. if called with a String then it gets stored. if called with a Resource then either the stored block gets called with that Resource or the stored String gets returned.

Parameters:

  • treebase_or_resource (String, DataMapper::Resource)

    either a String, a Resource or nil

  • &block (block)

    to be stored for later calls when base_or_resource is nil

Returns:

  • (String)

    when called with a Resource



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ldap_resource.rb', line 138

def treebase(base_or_resource = nil, &block)
  if base_or_resource
    if base_or_resource.instance_of? String
      @treebase = base_or_resource
    elsif @treebase.instance_of? String
      @treebase
    else
      @treebase.call(base_or_resource)
    end
  else
    if block
      @treebase = block
    else # backwards compatibility
      @treebase
    end
  end
end