Class: ActiveLdap::Base
- Inherits:
-
Object
- Object
- ActiveLdap::Base
- Includes:
- GetTextSupport, Enumerable, Reloadable::Deprecated, Reloadable::Subclasses
- Defined in:
- lib/active_ldap/base.rb
Overview
Base
Base is the primary class which contains all of the core ActiveLdap functionality. It is meant to only ever be subclassed by extension classes.
Constant Summary collapse
- VALID_LDAP_MAPPING_OPTIONS =
[:dn_attribute, :prefix, :scope, :classes, :recommended_classes, :excluded_classes, :sort_by, :order]
- @@colorize_logging =
true
- @@configurations =
{}
Class Attribute Summary collapse
-
.abstract_class ⇒ Object
Returns the value of attribute abstract_class.
Class Method Summary collapse
- .abstract_class? ⇒ Boolean
-
.base ⇒ Object
Base.base.
- .base=(value) ⇒ Object
- .base_class ⇒ Object
- .class_local_attr_accessor(search_ancestors, *syms) ⇒ Object
- .class_of_active_ldap_descendant(klass) ⇒ Object
- .create(attributes = nil, &block) ⇒ Object
- .default_search_attribute ⇒ Object
-
.establish_connection(config = nil) ⇒ Object
establish_connection is deprecated since 1.1.0.
- .human_name(options = {}) ⇒ Object
- .inherited(sub_class) ⇒ Object
- .inspect ⇒ Object
-
.ldap_mapping(options = {}) ⇒ Object
This class function is used to setup all mappings between the subclass and ldap for use in activeldap.
-
.parsed_base ⇒ Object
Base.base.
- .prefix ⇒ Object
- .prefix=(value) ⇒ Object
- .scope=(scope) ⇒ Object
- .scope_without_validation= ⇒ Object
- .self_and_descendants_from_active_ldap ⇒ Object
-
.setup_connection(config = nil) ⇒ Object
Connect and bind to LDAP creating a class variable for use by all ActiveLdap objects.
- .validate_scope(scope) ⇒ Object
Instance Method Summary collapse
-
#==(comparison_object) ⇒ Object
Returns true if the
comparison_object
is the same object, or is of the same type and has the same dn. - #[](name, force_array = false) ⇒ Object
- #[]=(name, value) ⇒ Object
-
#attribute_names(normalize = false) ⇒ Object
attributes.
- #attribute_present?(name) ⇒ Boolean
-
#attributes ⇒ Object
This returns the key value pairs in @data with all values cloned.
-
#attributes=(new_attributes) ⇒ Object
This allows a bulk update to the attributes of a record without forcing an immediate save or validation.
- #base ⇒ Object
- #base=(object_local_base) ⇒ Object
- #bind(config_or_password = {}, config_or_ignore = nil, &block) ⇒ Object
- #clear_connection_based_cache ⇒ Object
- #clear_object_class_based_cache ⇒ Object
- #default_search_attribute ⇒ Object
- #delete(options = {}) ⇒ Object
- #delete_all(options = {}) ⇒ Object
-
#destroy ⇒ Object
destroy.
- #destroy_all(options = {}) ⇒ Object
-
#dn ⇒ Object
dn.
- #dn=(value) ⇒ Object (also: #id=)
- #dn_attribute ⇒ Object
- #dn_attribute_of_class ⇒ Object
- #each ⇒ Object
-
#eql?(comparison_object) ⇒ Boolean
Delegates to ==.
-
#exist? ⇒ Boolean
(also: #exists?)
exist?.
-
#hash ⇒ Object
Delegates to id in order to allow two records of the same type and id to work with something like: [ User.find(“a”), User.find(“b”), User.find(“c”) ] & [ User.find(“a”), User.find(“d”) ] # => [ User.find(“a”) ].
- #have_attribute?(name, except = []) ⇒ Boolean (also: #has_attribute?)
- #id ⇒ Object
-
#initialize(attributes = nil) {|_self| ... } ⇒ Base
constructor
new.
- #inspect ⇒ Object
- #may ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
method_missing.
-
#methods(inherited_too = true) ⇒ Object
Add available attributes to the methods.
- #must ⇒ Object
-
#new_entry? ⇒ Boolean
new_entry?.
- #reload ⇒ Object
- #respond_to?(name, include_priv = false) ⇒ Boolean
- #respond_to_without_attributes? ⇒ Object
-
#save ⇒ Object
save.
- #save! ⇒ Object
- #schema ⇒ Object
- #scope ⇒ Object
- #scope=(scope) ⇒ Object
- #scope_of_class ⇒ Object
- #to_ldif ⇒ Object
- #to_ldif_record ⇒ Object
- #to_param ⇒ Object
- #to_s ⇒ Object
- #to_xml(options = {}) ⇒ Object
-
#update_attribute(name, value) ⇒ Object
Updates a given attribute and saves immediately.
-
#update_attributes(attrs) ⇒ Object
This performs a bulk update of attributes and immediately calls #save.
- #update_attributes!(attrs) ⇒ Object
Methods included from GetTextSupport
Constructor Details
#initialize(attributes = nil) {|_self| ... } ⇒ Base
new
Creates a new instance of Base initializing all class and all initialization. Defines local defaults. See examples If multiple values exist for dn_attribute, the first one put here will be authoritative
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/active_ldap/base.rb', line 671 def initialize(attributes=nil) init_base @new_entry = true initial_classes = required_classes | recommended_classes case attributes when nil self.classes = initial_classes when String, Array, DN self.classes = initial_classes self.dn = attributes when Hash classes, attributes = extract_object_class(attributes) self.classes = classes | initial_classes normalized_attributes = {} attributes.each do |key, value| real_key = to_real_attribute_name(key) || key normalized_attributes[real_key] = value end self.dn = normalized_attributes.delete(dn_attribute) self.attributes = normalized_attributes else format = _("'%s' must be either nil, DN value as ActiveLdap::DN, " \ "String or Array or attributes as Hash") raise ArgumentError, format % attributes.inspect end yield self if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
method_missing
If a given method matches an attribute or an attribute alias then call the appropriate method. TODO: Determine if it would be better to define each allowed method
using class_eval instead of using method_missing. This would
give tab completion in irb.
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
# File 'lib/active_ldap/base.rb', line 832 def method_missing(name, *args, &block) key = name.to_s case key when /=$/ real_key = $PREMATCH if have_attribute?(real_key, ['objectClass']) if args.size != 1 raise ArgumentError, _("wrong number of arguments (%d for 1)") % args.size end return set_attribute(real_key, *args, &block) end when /(?:(_before_type_cast)|(\?))?$/ real_key = $PREMATCH before_type_cast = !$1.nil? query = !$2.nil? if have_attribute?(real_key, ['objectClass']) if args.size > 1 raise ArgumentError, _("wrong number of arguments (%d for 1)") % args.size end if before_type_cast return get_attribute_before_type_cast(real_key, *args)[1] elsif query return get_attribute_as_query(real_key, *args) else return get_attribute(real_key, *args) end end end super end |
Class Attribute Details
.abstract_class ⇒ Object
Returns the value of attribute abstract_class.
506 507 508 |
# File 'lib/active_ldap/base.rb', line 506 def abstract_class @abstract_class end |
Class Method Details
.abstract_class? ⇒ Boolean
507 508 509 |
# File 'lib/active_ldap/base.rb', line 507 def abstract_class? defined?(@abstract_class) && @abstract_class end |
.base ⇒ Object
Base.base
This method when included into Base provides an inheritable, overwritable configuration setting
This should be a string with the base of the ldap server such as ‘dc=example,dc=com’, and it should be overwritten by including configuration.rb into this class. When subclassing, the specified prefix will be concatenated.
434 435 436 |
# File 'lib/active_ldap/base.rb', line 434 def base @base ||= compute_base end |
.base=(value) ⇒ Object
439 440 441 442 |
# File 'lib/active_ldap/base.rb', line 439 def base=(value) self.inheritable_base = value @base = nil end |
.base_class ⇒ Object
467 468 469 470 471 472 473 |
# File 'lib/active_ldap/base.rb', line 467 def base_class if self == Base or superclass == Base self else superclass.base_class end end |
.class_local_attr_accessor(search_ancestors, *syms) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/active_ldap/base.rb', line 299 def self.class_local_attr_accessor(search_ancestors, *syms) syms.flatten.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__ + 1) def self.#{sym}(search_superclasses=#{search_ancestors}) @#{sym} ||= nil return @#{sym} if @#{sym} if search_superclasses target = superclass value = nil loop do break nil unless target.respond_to?(:#{sym}) value = target.#{sym} break if value target = target.superclass end value else nil end end def #{sym}; self.class.#{sym}; end def self.#{sym}=(value); @#{sym} = value; end EOS end end |
.class_of_active_ldap_descendant(klass) ⇒ Object
511 512 513 514 515 516 517 518 519 520 |
# File 'lib/active_ldap/base.rb', line 511 def class_of_active_ldap_descendant(klass) if klass.superclass == Base or klass.superclass.abstract_class? klass elsif klass.superclass.nil? raise Error, _("%s doesn't belong in a hierarchy descending " \ "from ActiveLdap") % (name || to_s) else class_of_active_ldap_descendant(klass.superclass) end end |
.create(attributes = nil, &block) ⇒ Object
390 391 392 393 394 395 396 397 398 |
# File 'lib/active_ldap/base.rb', line 390 def create(attributes=nil, &block) if attributes.is_a?(Array) attributes.collect {|attrs| create(attrs, &block)} else object = new(attributes, &block) object.save object end end |
.default_search_attribute ⇒ Object
475 476 477 |
# File 'lib/active_ldap/base.rb', line 475 def default_search_attribute dn_attribute end |
.establish_connection(config = nil) ⇒ Object
establish_connection is deprecated since 1.1.0. Please use setup_connection() instead.
381 382 383 384 385 386 387 388 |
# File 'lib/active_ldap/base.rb', line 381 def establish_connection(config=nil) = _("ActiveLdap::Base.establish_connection has been deprecated " \ "since 1.1.0. " \ "Please use ActiveLdap::Base.setup_connection instead.") ActiveSupport::Deprecation.warn() setup_connection(config) end |
.human_name(options = {}) ⇒ Object
541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/active_ldap/base.rb', line 541 def human_name(={}) defaults = self_and_descendants_from_active_ldap.collect do |klass| if klass.name.blank? nil else :"#{klass.name.underscore}" end end defaults << name.humanize defaults = defaults.compact defaults.first || name || to_s end |
.inherited(sub_class) ⇒ Object
334 335 336 337 338 339 |
# File 'lib/active_ldap/base.rb', line 334 def inherited(sub_class) super sub_class.module_eval do include GetTextSupport end end |
.inspect ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/active_ldap/base.rb', line 479 def inspect if self == Base super elsif abstract_class? "#{super}(abstract)" else detail = nil begin must = [] may = [] class_names = classes.collect do |object_class| must.concat(object_class.must) may.concat(object_class.may) object_class.name end detail = ["objectClass:<#{class_names.join(', ')}>", "must:<#{inspect_attributes(must)}>", "may:<#{inspect_attributes(may)}>"].join(", ") rescue ActiveLdap::ConnectionNotSetup detail = "not-connected" rescue ActiveLdap::Error detail = "connection-failure" end "#{super}(#{detail})" end end |
.ldap_mapping(options = {}) ⇒ Object
This class function is used to setup all mappings between the subclass and ldap for use in activeldap
Example:
ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People',
:classes => ['top', 'posixAccount'],
:scope => :sub
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/active_ldap/base.rb', line 407 def ldap_mapping(={}) = .symbolize_keys () self.dn_attribute = [:dn_attribute] || default_dn_attribute self.dn_attribute = dn_attribute.to_s if dn_attribute.is_a?(Symbol) self.prefix = [:prefix] || default_prefix self.scope = [:scope] self.required_classes = [:classes] self.recommended_classes = [:recommended_classes] self.excluded_classes = [:excluded_classes] self.sort_by = [:sort_by] self.order = [:order] public_class_method :new end |
.parsed_base ⇒ Object
Base.base
This method when included into Base provides an inheritable, overwritable configuration setting
This should be a string with the base of the ldap server such as ‘dc=example,dc=com’, and it should be overwritten by including configuration.rb into this class. When subclassing, the specified prefix will be concatenated. for backward compatibility
437 438 439 |
# File 'lib/active_ldap/base.rb', line 437 def base @base ||= compute_base end |
.prefix ⇒ Object
444 445 446 |
# File 'lib/active_ldap/base.rb', line 444 def prefix @prefix ||= inheritable_prefix and DN.parse(inheritable_prefix) end |
.prefix=(value) ⇒ Object
448 449 450 451 452 |
# File 'lib/active_ldap/base.rb', line 448 def prefix=(value) self.inheritable_prefix = value @prefix = nil @base = nil end |
.scope=(scope) ⇒ Object
455 456 457 458 |
# File 'lib/active_ldap/base.rb', line 455 def scope=(scope) validate_scope(scope) self.scope_without_validation = scope end |
.scope_without_validation= ⇒ Object
454 |
# File 'lib/active_ldap/base.rb', line 454 alias_method :scope_without_validation=, :scope= |
.self_and_descendants_from_active_ldap ⇒ Object
522 523 524 525 526 527 528 529 530 531 |
# File 'lib/active_ldap/base.rb', line 522 def self_and_descendants_from_active_ldap klass = self classes = [klass] while klass != klass.base_class classes << klass = klass.superclass end classes rescue [self] end |
.setup_connection(config = nil) ⇒ Object
Connect and bind to LDAP creating a class variable for use by all ActiveLdap objects.
config
config
must be a hash that may contain any of the following fields: :password_block, :logger, :host, :port, :base, :bind_dn, :try_sasl, :allow_anonymous :bind_dn specifies the DN to bind with. :password_block specifies a Proc object that will yield a String to
be used as the password when called.
:logger specifies a logger object (Logger, Log4r::Logger and s on) :host sets the LDAP server hostname :port sets the LDAP server port :base overwrites Base.base - this affects EVERYTHING :try_sasl indicates that a SASL bind should be attempted when binding
to the server (default: false)
:sasl_mechanisms is an array of SASL mechanism to try
(default: ["GSSAPI", "CRAM-MD5", "EXTERNAL"])
:allow_anonymous indicates that a true anonymous bind is allowed when
trying to bind to the server (default: true)
:retries - indicates the number of attempts to reconnect that will be
undertaken when a stale connection occurs. -1 means infinite.
:sasl_quiet - if true, sets @sasl_quiet on the Ruby/LDAP connection :method - whether to use :ssl, :tls, or :plain (unencrypted) :retry_wait - seconds to wait before retrying a connection :scope - dictates how to find objects. ONELEVEL by default to
avoid dn_attr collisions across OUs. Think before changing.
:timeout - time in seconds - defaults to disabled. This CAN interrupt
search() requests. Be warned.
:retry_on_timeout - whether to reconnect when timeouts occur. Defaults
to true
See lib/active_ldap/configuration.rb for defaults for each option
373 374 375 376 377 |
# File 'lib/active_ldap/base.rb', line 373 def setup_connection(config=nil) super ensure_logger nil end |
.validate_scope(scope) ⇒ Object
460 461 462 463 464 465 |
# File 'lib/active_ldap/base.rb', line 460 def validate_scope(scope) scope = scope.to_sym if scope.is_a?(String) return if scope.nil? or scope.is_a?(Symbol) raise ConfigurationError, _("scope '%s' must be a Symbol") % scope.inspect end |
Instance Method Details
#==(comparison_object) ⇒ Object
Returns true if the comparison_object
is the same object, or is of the same type and has the same dn.
701 702 703 704 705 706 |
# File 'lib/active_ldap/base.rb', line 701 def ==(comparison_object) comparison_object.equal?(self) or (comparison_object.instance_of?(self.class) and comparison_object.dn == dn and !comparison_object.new_entry?) end |
#[](name, force_array = false) ⇒ Object
984 985 986 987 988 989 990 |
# File 'lib/active_ldap/base.rb', line 984 def [](name, force_array=false) if name == "dn" array_of(dn, force_array) else get_attribute(name, force_array) end end |
#[]=(name, value) ⇒ Object
992 993 994 |
# File 'lib/active_ldap/base.rb', line 992 def []=(name, value) set_attribute(name, value) end |
#attribute_names(normalize = false) ⇒ Object
attributes
Return attribute methods so that a program can determine available attributes dynamically without schema awareness
743 744 745 |
# File 'lib/active_ldap/base.rb', line 743 def attribute_names(normalize=false) entry_attribute.names(normalize) end |
#attribute_present?(name) ⇒ Boolean
747 748 749 750 |
# File 'lib/active_ldap/base.rb', line 747 def attribute_present?(name) values = get_attribute(name, true) !values.empty? or values.any? {|x| !(x and x.empty?)} end |
#attributes ⇒ Object
This returns the key value pairs in @data with all values cloned
904 905 906 907 |
# File 'lib/active_ldap/base.rb', line 904 def attributes @simplified_data ||= simplify_data(@data) @simplified_data.clone end |
#attributes=(new_attributes) ⇒ Object
This allows a bulk update to the attributes of a record without forcing an immediate save or validation.
It is unwise to attempt objectClass updates this way. Also be sure to only pass in key-value pairs of your choosing. Do not let URL/form hackers supply the keys.
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/active_ldap/base.rb', line 915 def attributes=(new_attributes) return if new_attributes.blank? _schema = _local_entry_attribute = nil targets = remove_attributes_protected_from_mass_assignment(new_attributes) targets.each do |key, value| setter = "#{key}=" unless respond_to?(setter) _schema ||= schema attribute = _schema.attribute(key) next if attribute.id.nil? _local_entry_attribute ||= local_entry_attribute _local_entry_attribute.register(attribute) end send(setter, value) end end |
#base ⇒ Object
1042 1043 1044 |
# File 'lib/active_ldap/base.rb', line 1042 def base @base ||= compute_base end |
#base=(object_local_base) ⇒ Object
1046 1047 1048 1049 1050 1051 |
# File 'lib/active_ldap/base.rb', line 1046 def base=(object_local_base) ensure_update_dn @dn = nil @base = nil @base_value = object_local_base end |
#bind(config_or_password = {}, config_or_ignore = nil, &block) ⇒ Object
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
# File 'lib/active_ldap/base.rb', line 1002 def bind(config_or_password={}, config_or_ignore=nil, &block) if config_or_password.is_a?(String) config = (config_or_ignore || {}).merge(:password => config_or_password) else config = config_or_password end config = {:bind_dn => dn, :allow_anonymous => false}.merge(config) config[:password_block] ||= block if block_given? setup_connection(config) before_connection = @connection begin @connection = nil connection.connect @connection = connection clear_connection_based_cache clear_association_cache rescue ActiveLdap::Error remove_connection @connection = before_connection raise end true end |
#clear_connection_based_cache ⇒ Object
1027 1028 1029 1030 1031 |
# File 'lib/active_ldap/base.rb', line 1027 def clear_connection_based_cache @schema = nil @local_entry_attribute = nil clear_object_class_based_cache end |
#clear_object_class_based_cache ⇒ Object
1033 1034 1035 1036 |
# File 'lib/active_ldap/base.rb', line 1033 def clear_object_class_based_cache @entry_attribute = nil @real_names = {} end |
#default_search_attribute ⇒ Object
794 795 796 |
# File 'lib/active_ldap/base.rb', line 794 def default_search_attribute self.class.default_search_attribute end |
#delete(options = {}) ⇒ Object
806 807 808 |
# File 'lib/active_ldap/base.rb', line 806 def delete(={}) super(dn, ) end |
#delete_all(options = {}) ⇒ Object
1063 1064 1065 |
# File 'lib/active_ldap/base.rb', line 1063 def delete_all(={}) super({:base => dn}.merge( || {})) end |
#destroy ⇒ Object
destroy
Delete this entry from LDAP
801 802 803 804 |
# File 'lib/active_ldap/base.rb', line 801 def destroy self.class.delete(dn) @new_entry = true end |
#destroy_all(options = {}) ⇒ Object
1067 1068 1069 |
# File 'lib/active_ldap/base.rb', line 1067 def destroy_all(={}) super({:base => dn}.merge( || {})) end |
#dn ⇒ Object
dn
Return the authoritative dn
770 771 772 |
# File 'lib/active_ldap/base.rb', line 770 def dn @dn ||= compute_dn end |
#dn=(value) ⇒ Object Also known as: id=
782 783 784 |
# File 'lib/active_ldap/base.rb', line 782 def dn=(value) set_attribute(dn_attribute_with_fallback, value) end |
#dn_attribute ⇒ Object
788 789 790 791 792 |
# File 'lib/active_ldap/base.rb', line 788 def dn_attribute ensure_update_dn _dn_attribute = @dn_attribute || dn_attribute_of_class to_real_attribute_name(_dn_attribute) || _dn_attribute end |
#dn_attribute_of_class ⇒ Object
787 |
# File 'lib/active_ldap/base.rb', line 787 alias_method(:dn_attribute_of_class, :dn_attribute) |
#each ⇒ Object
996 997 998 999 1000 |
# File 'lib/active_ldap/base.rb', line 996 def each @data.each do |key, values| yield(key.dup, values.dup) end end |
#eql?(comparison_object) ⇒ Boolean
Delegates to ==
709 710 711 |
# File 'lib/active_ldap/base.rb', line 709 def eql?(comparison_object) self == (comparison_object) end |
#exist? ⇒ Boolean Also known as: exists?
exist?
Return whether the entry exists in LDAP or not
755 756 757 |
# File 'lib/active_ldap/base.rb', line 755 def exist? self.class.exists?(dn) end |
#hash ⇒ Object
Delegates to id in order to allow two records of the same type and id to work with something like:
[ User.find("a"), User.find("b"), User.find("c") ] &
[ User.find("a"), User.find("d") ] # => [ User.find("a") ]
717 718 719 720 721 722 723 724 725 726 727 728 729 |
# File 'lib/active_ldap/base.rb', line 717 def hash return super if @_hashing # workaround for GetText :< _dn = nil begin @_hashing = true _dn = dn rescue DistinguishedNameInvalid, DistinguishedNameNotSetError return super ensure @_hashing = false end _dn.hash end |
#have_attribute?(name, except = []) ⇒ Boolean Also known as: has_attribute?
961 962 963 964 |
# File 'lib/active_ldap/base.rb', line 961 def have_attribute?(name, except=[]) real_name = to_real_attribute_name(name) !real_name.nil? and !except.include?(real_name) end |
#id ⇒ Object
774 775 776 |
# File 'lib/active_ldap/base.rb', line 774 def id get_attribute(dn_attribute_with_fallback) end |
#inspect ⇒ Object
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
# File 'lib/active_ldap/base.rb', line 1071 def inspect object_classes = entry_attribute.object_classes inspected_object_classes = object_classes.collect do |object_class| object_class.name end.join(', ') must_attributes = must.collect(&:name).sort.join(', ') may_attributes = may.collect(&:name).sort.join(', ') inspected_attributes = attribute_names.sort.collect do |name| inspect_attribute(name) end.join(', ') result = "\#<#{self.class} objectClass:<#{inspected_object_classes}>, " result << "must:<#{must_attributes}>, may:<#{may_attributes}>, " result << "#{inspected_attributes}>" result end |
#may ⇒ Object
731 732 733 |
# File 'lib/active_ldap/base.rb', line 731 def may entry_attribute.may end |
#methods(inherited_too = true) ⇒ Object
Add available attributes to the methods
866 867 868 869 870 871 872 |
# File 'lib/active_ldap/base.rb', line 866 def methods(inherited_too=true) target_names = entry_attribute.all_names target_names -= ['objectClass', 'objectClass'.underscore] super + target_names.uniq.collect do |x| [x, "#{x}=", "#{x}?", "#{x}_before_type_cast"] end.flatten end |
#must ⇒ Object
735 736 737 |
# File 'lib/active_ldap/base.rb', line 735 def must entry_attribute.must end |
#new_entry? ⇒ Boolean
new_entry?
Return whether the entry is new entry in LDAP or not
763 764 765 |
# File 'lib/active_ldap/base.rb', line 763 def new_entry? @new_entry end |
#reload ⇒ Object
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
# File 'lib/active_ldap/base.rb', line 967 def reload clear_association_cache _, attributes = search(:value => id).find do |_dn, _attributes| dn == _dn end if attributes.nil? raise EntryNotFound, _("Can't find DN '%s' to reload") % dn end @ldap_data.update(attributes) classes, attributes = extract_object_class(attributes) self.classes = classes self.attributes = attributes @new_entry = false self end |
#respond_to?(name, include_priv = false) ⇒ Boolean
875 876 877 878 879 880 881 882 |
# File 'lib/active_ldap/base.rb', line 875 def respond_to?(name, include_priv=false) return true if super name = name.to_s return true if have_attribute?(name, ["objectClass"]) return false if /(?:=|\?|_before_type_cast)$/ !~ name have_attribute?($PREMATCH, ["objectClass"]) end |
#respond_to_without_attributes? ⇒ Object
874 |
# File 'lib/active_ldap/base.rb', line 874 alias_method :respond_to_without_attributes?, :respond_to? |
#save ⇒ Object
save
Save and validate this object into LDAP either adding or replacing attributes TODO: Relative DN support
815 816 817 |
# File 'lib/active_ldap/base.rb', line 815 def save create_or_update end |
#save! ⇒ Object
819 820 821 822 823 |
# File 'lib/active_ldap/base.rb', line 819 def save! unless create_or_update raise EntryNotSaved, _("entry %s can't be saved") % dn end end |
#schema ⇒ Object
1038 1039 1040 |
# File 'lib/active_ldap/base.rb', line 1038 def schema @schema ||= super end |
#scope ⇒ Object
1054 1055 1056 |
# File 'lib/active_ldap/base.rb', line 1054 def scope @scope || scope_of_class end |
#scope=(scope) ⇒ Object
1058 1059 1060 1061 |
# File 'lib/active_ldap/base.rb', line 1058 def scope=(scope) self.class.validate_scope(scope) @scope = scope end |
#scope_of_class ⇒ Object
1053 |
# File 'lib/active_ldap/base.rb', line 1053 alias_method :scope_of_class, :scope |
#to_ldif ⇒ Object
936 937 938 |
# File 'lib/active_ldap/base.rb', line 936 def to_ldif Ldif.new([to_ldif_record]).to_s end |
#to_ldif_record ⇒ Object
932 933 934 |
# File 'lib/active_ldap/base.rb', line 932 def to_ldif_record super(dn, normalize_data(@data)) end |
#to_param ⇒ Object
778 779 780 |
# File 'lib/active_ldap/base.rb', line 778 def to_param id end |
#to_s ⇒ Object
957 958 959 |
# File 'lib/active_ldap/base.rb', line 957 def to_s to_ldif end |
#to_xml(options = {}) ⇒ Object
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 |
# File 'lib/active_ldap/base.rb', line 940 def to_xml(={}) = .dup [:root] ||= (self.class.name || '').underscore [:root] = 'anonymous' if [:root].blank? except = [:except] if except [:except] = except.collect do |name| if name.to_s.downcase == "dn" "dn" else to_real_attribute_name(name) end end.compact end XML.new(dn, normalize_data(@data), schema).to_s() end |
#update_attribute(name, value) ⇒ Object
Updates a given attribute and saves immediately
885 886 887 888 |
# File 'lib/active_ldap/base.rb', line 885 def update_attribute(name, value) send("#{name}=", value) save end |
#update_attributes(attrs) ⇒ Object
This performs a bulk update of attributes and immediately calls #save.
892 893 894 895 |
# File 'lib/active_ldap/base.rb', line 892 def update_attributes(attrs) self.attributes = attrs save end |
#update_attributes!(attrs) ⇒ Object
897 898 899 900 |
# File 'lib/active_ldap/base.rb', line 897 def update_attributes!(attrs) self.attributes = attrs save! end |