class Mutt::Ldap::Query::Worker

Attributes

query[R]

Public Class Methods

new(query) click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 14
def initialize(query)
  @query = query
end

Public Instance Methods

config() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 27
def config
  @config ||= YAML.load_file(config_path)
end
config_path() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 18
def config_path
  @xdg ||= XDG::Environment.new
  File.join(@xdg.config_home, 'mutt-ldap-query', 'config.yml')
end
configured?() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 23
def configured?
  File.exist?(config_path)
end
edit_config() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 65
def edit_config
  system("${EDITOR:-vi} #{config_path}")
end
gen_config() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 58
def gen_config
  raise "#{config_path} already exist." if configured?

  FileUtils.mkdir_p(File.dirname(config_path))
  File.write(config_path, sample_config, perm: 0o600)
end
mail_attributes() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 54
def mail_attributes
  %w[mail mailAlternateAddress]
end
sample_config() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 69
        def sample_config
          <<~CONFIG
            :host: ldap.example.com
            :port: 389
            :base: ou=people,dc=example,dc=com
            :auth:
              :method: :simple
              :username: cn=mutt-ldap-query,ou=services,dc=example,dc=com
              :password: secret
            :encryption:
              :method: :start_tls
          CONFIG
        end
search_attributes() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 44
def search_attributes
  %w[cn mail mailAlternateAddress description]
end
search_filter() click to toggle source
# File lib/mutt/ldap/query/worker.rb, line 48
def search_filter
  res = Net::LDAP::Filter.eq('objectClass', 'person')
  res &= query.map { |q| search_attributes.map { |a| Net::LDAP::Filter.contains(a, q) } }.flatten.inject(:|) if query.any?
  res
end