Class: LDAP::Server::MatchingRule
- Inherits:
-
Object
- Object
- LDAP::Server::MatchingRule
- Defined in:
- lib/ldap/server/match.rb,
lib/ldap/server/match.rb
Overview
And now, here are some matching rules you can use (RFC2252 section 8)
Defined Under Namespace
Modules: Equality, IA5Downcase, IA5Trim, Integer, Ordering, StringDowncase, StringTrim, Substrings Classes: DefaultMatchingClass
Constant Summary collapse
- DefaultMatch =
DefaultMatchingClass.new
- @@rules =
oid / name / alias => object
{}
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#obsolete ⇒ Object
readonly
Returns the value of attribute obsolete.
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
-
#syntax ⇒ Object
readonly
Returns the value of attribute syntax.
Class Method Summary collapse
-
.add(*args, &blk) ⇒ Object
Add a new matching rule.
-
.all_matching_rules ⇒ Object
Return all known matching rules.
-
.find(x) ⇒ Object
Find a MatchingRule object given a name or oid, or return nil (? should we create one automatically, like Syntax).
-
.from_def(str, &blk) ⇒ Object
Create a new MatchingRule object, given its description string.
Instance Method Summary collapse
-
#initialize(oid, names, syntax, desc = nil, obsolete = false, &blk) ⇒ MatchingRule
constructor
Create a new MatchingRule object.
- #name ⇒ Object
- #normalize(x) ⇒ Object
- #to_def ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(oid, names, syntax, desc = nil, obsolete = false, &blk) ⇒ MatchingRule
Create a new MatchingRule object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ldap/server/match.rb', line 16 def initialize(oid, names, syntax, desc=nil, obsolete=false, &blk) @oid = oid @names = names @names = [@names] unless @names.is_a?(Array) @desc = desc @obsolete = obsolete @syntax = LDAP::Server::Syntax.find(syntax) # creates new obj if reqd @def = nil # initialization hook self.instance_eval(&blk) if blk end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
12 13 14 |
# File 'lib/ldap/server/match.rb', line 12 def desc @desc end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
12 13 14 |
# File 'lib/ldap/server/match.rb', line 12 def names @names end |
#obsolete ⇒ Object (readonly)
Returns the value of attribute obsolete.
12 13 14 |
# File 'lib/ldap/server/match.rb', line 12 def obsolete @obsolete end |
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
12 13 14 |
# File 'lib/ldap/server/match.rb', line 12 def oid @oid end |
#syntax ⇒ Object (readonly)
Returns the value of attribute syntax.
12 13 14 |
# File 'lib/ldap/server/match.rb', line 12 def syntax @syntax end |
Class Method Details
.add(*args, &blk) ⇒ Object
Add a new matching rule
72 73 74 75 76 77 78 79 |
# File 'lib/ldap/server/match.rb', line 72 def self.add(*args, &blk) s = new(*args, &blk) @@rules[s.oid] = s return if s.names.nil? s.names.each do |n| @@rules[n.downcase] = s end end |
.all_matching_rules ⇒ Object
Return all known matching rules
91 92 93 |
# File 'lib/ldap/server/match.rb', line 91 def self.all_matching_rules @@rules.values.uniq end |
.find(x) ⇒ Object
Find a MatchingRule object given a name or oid, or return nil (? should we create one automatically, like Syntax)
84 85 86 87 |
# File 'lib/ldap/server/match.rb', line 84 def self.find(x) return x if x.nil? or x.is_a?(LDAP::Server::MatchingRule) @@rules[x.downcase] end |
.from_def(str, &blk) ⇒ Object
Create a new MatchingRule object, given its description string
42 43 44 45 46 47 |
# File 'lib/ldap/server/match.rb', line 42 def self.from_def(str, &blk) m = LDAP::Server::Syntax::MatchingRuleDescription.match(str) raise LDAP::ResultError::InvalidAttributeSyntax, "Bad MatchingRuleDescription #{str.inspect}" unless m new(m[1], m[2].scan(/'(.*?)'/).flatten, m[5], m[3], m[4], &blk) end |
Instance Method Details
#name ⇒ Object
28 29 30 |
# File 'lib/ldap/server/match.rb', line 28 def name (@names && names[0]) || @oid end |
#normalize(x) ⇒ Object
36 37 38 |
# File 'lib/ldap/server/match.rb', line 36 def normalize(x) x end |
#to_def ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ldap/server/match.rb', line 49 def to_def return @def if @def ans = "( #{@oid} " if names.nil? or @names.empty? # nothing elsif @names.size == 1 ans << "NAME '#{@names[0]}' " else ans << "NAME ( " @names.each { |n| ans << "'#{n}' " } ans << ") " end ans << "DESC '#@desc' " if @desc ans << "OBSOLETE " if @obsolete ans << "SYNTAX #@syntax " if @syntax ans << ")" @def = ans end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/ldap/server/match.rb', line 32 def to_s (@names && names[0]) || @oid end |