Module: AD::Framework::Patterns::Searchable::ClassMethods
- Defined in:
- lib/ad-framework/patterns/searchable.rb
Instance Method Summary collapse
- #all(args = {}) ⇒ Object
- #build_ad_search_args(args = {}) ⇒ Object
- #find(dn) ⇒ Object
- #first(args = {}) ⇒ Object
Instance Method Details
#all(args = {}) ⇒ Object
64 65 66 |
# File 'lib/ad-framework/patterns/searchable.rb', line 64 def all(args = {}) self.fetch_ad_entry(args, true) end |
#build_ad_search_args(args = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ad-framework/patterns/searchable.rb', line 68 def build_ad_search_args(args = {}) default_args = { :objectclass__eq => self.schema.ldap_name, :base => self.schema.treebase } (args || {}).inject(default_args) do |search_args, (key, value)| case(key.to_sym) when :where if value.kind_of?(Array) value = value.inject({}){|where, condition| where.merge(condition) } end search_args.merge(value) when :limit search_args.merge({ :size => value }) else search_args.merge({ key => value }) end end end |
#find(dn) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ad-framework/patterns/searchable.rb', line 45 def find(dn) dn = self.build_ad_dn(dn) args = { :where => { :dn__eq => dn }, :size => 1 } object = self.fetch_ad_entry(args) if !object dn = args[:where][:dn__eq] raise(*[ AD::Framework::EntryNotFound, "An entry could not be found with dn #{dn.inspect} (#{self.class})" ]) end object end |
#first(args = {}) ⇒ Object
59 60 61 62 |
# File 'lib/ad-framework/patterns/searchable.rb', line 59 def first(args = {}) args = { :where => args, :size => 1 } self.fetch_ad_entry(args) end |