Class: AD::Framework::AttributeType
- Inherits:
- 
      Object
      
        - Object
- AD::Framework::AttributeType
 
- Defined in:
- lib/ad-framework/attribute_type.rb
Instance Attribute Summary collapse
- 
  
    
      #attr_ldap_name  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute attr_ldap_name. 
- 
  
    
      #ldap_value  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute ldap_value. 
- 
  
    
      #object  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute object. 
- 
  
    
      #value  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute value. 
Class Method Summary collapse
- .attribute_type_method(attribute, method_name) ⇒ Object
- .define_attribute_type(attribute, klass) ⇒ Object
- .define_reader(attribute, klass) ⇒ Object
- .define_writer(attribute, klass) ⇒ Object
- .key(new_value = nil) ⇒ Object
- .reader_method(attribute) ⇒ Object
- .writer_method(attribute) ⇒ Object
Instance Method Summary collapse
- 
  
    
      #initialize(object, attr_ldap_name, value = nil)  ⇒ AttributeType 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of AttributeType. 
- #inspect ⇒ Object
- #is_set? ⇒ Boolean
- #reset ⇒ Object
- #value_from_field ⇒ Object
Constructor Details
#initialize(object, attr_ldap_name, value = nil) ⇒ AttributeType
Returns a new instance of AttributeType.
| 7 8 9 10 11 | # File 'lib/ad-framework/attribute_type.rb', line 7 def initialize(object, attr_ldap_name, value = nil) self.object = object self.attr_ldap_name = attr_ldap_name self.value = value.nil? ? self.value_from_field : value end | 
Instance Attribute Details
#attr_ldap_name ⇒ Object
Returns the value of attribute attr_ldap_name.
| 5 6 7 | # File 'lib/ad-framework/attribute_type.rb', line 5 def attr_ldap_name @attr_ldap_name end | 
#ldap_value ⇒ Object
Returns the value of attribute ldap_value.
| 5 6 7 | # File 'lib/ad-framework/attribute_type.rb', line 5 def ldap_value @ldap_value end | 
#object ⇒ Object
Returns the value of attribute object.
| 5 6 7 | # File 'lib/ad-framework/attribute_type.rb', line 5 def object @object end | 
#value ⇒ Object
Returns the value of attribute value.
| 5 6 7 | # File 'lib/ad-framework/attribute_type.rb', line 5 def value @value end | 
Class Method Details
.attribute_type_method(attribute, method_name) ⇒ Object
| 69 70 71 72 73 74 75 76 77 78 79 80 81 | # File 'lib/ad-framework/attribute_type.rb', line 69 def attribute_type_method(attribute, method_name) <<-DEFINE_ATTRIBUTE_TYPE def #{method_name} unless @#{method_name} type = #{attribute.attribute_type}.new(self, "#{attribute.ldap_name}") @#{method_name} = type end @#{method_name} end DEFINE_ATTRIBUTE_TYPE end | 
.define_attribute_type(attribute, klass) ⇒ Object
| 57 58 59 60 61 62 63 64 65 66 67 | # File 'lib/ad-framework/attribute_type.rb', line 57 def define_attribute_type(attribute, klass) method_name = "#{attribute.name}_attribute_type" if !klass.instance_methods.collect(&:to_s).include?(method_name) attribute_type_method = self.attribute_type_method(attribute, method_name) if attribute_type_method.kind_of?(::Proc) klass.class_eval(&attribute_type_method) else klass.class_eval(attribute_type_method.to_s) end end end | 
.define_reader(attribute, klass) ⇒ Object
| 83 84 85 86 87 88 89 90 91 | # File 'lib/ad-framework/attribute_type.rb', line 83 def define_reader(attribute, klass) self.define_attribute_type(attribute, klass) reader_method = self.reader_method(attribute) if reader_method.kind_of?(::Proc) klass.class_eval(&reader_method) else klass.class_eval(reader_method.to_s) end end | 
.define_writer(attribute, klass) ⇒ Object
| 103 104 105 106 107 108 109 110 111 | # File 'lib/ad-framework/attribute_type.rb', line 103 def define_writer(attribute, klass) self.define_attribute_type(attribute, klass) writer_method = self.writer_method(attribute) if writer_method.kind_of?(::Proc) klass.class_eval(&writer_method) else klass.class_eval(writer_method.to_s) end end | 
.key(new_value = nil) ⇒ Object
| 50 51 52 53 54 55 | # File 'lib/ad-framework/attribute_type.rb', line 50 def key(new_value = nil) if new_value @key = new_value end @key end | 
.reader_method(attribute) ⇒ Object
| 93 94 95 96 97 98 99 100 101 | # File 'lib/ad-framework/attribute_type.rb', line 93 def reader_method(attribute) <<-DEFINE_READER def #{attribute.name} self.#{attribute.name}_attribute_type.value end DEFINE_READER end | 
.writer_method(attribute) ⇒ Object
| 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | # File 'lib/ad-framework/attribute_type.rb', line 113 def writer_method(attribute) <<-DEFINE_WRITER def #{attribute.name}=(new_value) self.#{attribute.name}_attribute_type.value = new_value if self.respond_to?("#{attribute.name}") self.#{attribute.name} else new_value end end DEFINE_WRITER end | 
Instance Method Details
#inspect ⇒ Object
| 40 41 42 43 44 45 46 | # File 'lib/ad-framework/attribute_type.rb', line 40 def inspect attr_display = [ :value, :ldap_value, :attr_ldap_name ].collect do |attr| "#{attr}: #{self.instance_variable_get("@#{attr}").inspect}" end attr_display.push("object: #{object.class} - #{object.dn.inspect}") [ "#<#{self.class} ", attr_display.sort.join(", "), ">" ].join end | 
#is_set? ⇒ Boolean
| 36 37 38 | # File 'lib/ad-framework/attribute_type.rb', line 36 def is_set? !self.value.nil? end | 
#reset ⇒ Object
| 32 33 34 | # File 'lib/ad-framework/attribute_type.rb', line 32 def reset self.value = self.value_from_field end | 
#value_from_field ⇒ Object
| 13 14 15 | # File 'lib/ad-framework/attribute_type.rb', line 13 def value_from_field (self.object.fields[self.attr_ldap_name] || []).first end |