Class: AD::Framework::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/ad-framework/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Schema

Returns a new instance of Schema.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ad-framework/schema.rb', line 10

def initialize(klass)
  self.klass = klass

  self.rdn = :name
  self.auxiliary_classes = []
  self.callbacks = {}

  if self.klass.is_a?(::Class) && self.klass.superclass.respond_to?(:schema)
    self.inherit_from(self.klass.superclass.schema)
  else
    self.attributes = Set.new
    self.mandatory = Set.new
    self.structural_classes = []
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



7
8
9
# File 'lib/ad-framework/schema.rb', line 7

def attributes
  @attributes
end

#auxiliary_classesObject

Returns the value of attribute auxiliary_classes.



7
8
9
# File 'lib/ad-framework/schema.rb', line 7

def auxiliary_classes
  @auxiliary_classes
end

#callbacksObject

Returns the value of attribute callbacks.



8
9
10
# File 'lib/ad-framework/schema.rb', line 8

def callbacks
  @callbacks
end

#klassObject

Returns the value of attribute klass.



8
9
10
# File 'lib/ad-framework/schema.rb', line 8

def klass
  @klass
end

#ldap_nameObject

Returns the value of attribute ldap_name.



7
8
9
# File 'lib/ad-framework/schema.rb', line 7

def ldap_name
  @ldap_name
end

#mandatoryObject

Returns the value of attribute mandatory.



8
9
10
# File 'lib/ad-framework/schema.rb', line 8

def mandatory
  @mandatory
end

#rdnObject

Returns the value of attribute rdn.



7
8
9
# File 'lib/ad-framework/schema.rb', line 7

def rdn
  @rdn
end

#structural_classesObject

Returns the value of attribute structural_classes.



7
8
9
# File 'lib/ad-framework/schema.rb', line 7

def structural_classes
  @structural_classes
end

Instance Method Details

#add_attributes(attribute_names) ⇒ Object



46
47
48
49
# File 'lib/ad-framework/schema.rb', line 46

def add_attributes(attribute_names)
  self.add_read_attributes(attribute_names)
  self.add_write_attributes(attribute_names)
end

#add_auxiliary_class(klass) ⇒ Object



77
78
79
80
81
# File 'lib/ad-framework/schema.rb', line 77

def add_auxiliary_class(klass)
  self.auxiliary_classes << klass
  self.bring_in(klass.schema)
  self.auxiliary_classes.uniq!
end

#add_callback(timing, action, method_names) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/ad-framework/schema.rb', line 83

def add_callback(timing, action, method_names)
  self.callbacks[action.to_sym] ||= {}
  self.callbacks[action.to_sym][timing.to_sym] ||= []
  method_names.each do |method_name|
    self.callbacks[action.to_sym][timing.to_sym] << method_name
  end
end

#add_mandatory(attribute_names) ⇒ Object



64
65
66
67
68
# File 'lib/ad-framework/schema.rb', line 64

def add_mandatory(attribute_names)
  attribute_names.each do |attribute_name|
    self.mandatory << attribute_name
  end
end

#add_read_attributes(attribute_names) ⇒ Object



51
52
53
54
55
56
# File 'lib/ad-framework/schema.rb', line 51

def add_read_attributes(attribute_names)
  attribute_names.collect(&:to_sym).each do |name|
    AD::Framework::Attribute.new(name).define_reader(self.klass)
    self.attributes << name.to_sym
  end
end

#add_write_attributes(attribute_names) ⇒ Object



58
59
60
61
62
# File 'lib/ad-framework/schema.rb', line 58

def add_write_attributes(attribute_names)
  attribute_names.collect(&:to_sym).each do |name|
    AD::Framework::Attribute.new(name).define_writer(self.klass)
  end
end

#inspectObject



91
92
93
94
95
96
# File 'lib/ad-framework/schema.rb', line 91

def inspect
  attrs_display = [ :klass, :ldap_name, :rdn, :attributes ].collect do |attr|
    "#{attr}: #{self.send(attr).inspect}"
  end
  [ "#<#{self.class} ", attrs_display.join(", "), ">" ].join
end

#object_classesObject



70
71
72
73
74
75
# File 'lib/ad-framework/schema.rb', line 70

def object_classes
  [ self.structural_classes.to_a,
    self.klass,
    self.auxiliary_classes.to_a
  ].flatten.compact
end

#treebaseObject



34
35
36
37
38
39
40
# File 'lib/ad-framework/schema.rb', line 34

def treebase
  if @treebase && self.default_treebase && !(@treebase.include?(self.default_treebase))
    [ @treebase, self.default_treebase ].join(", ")
  else
    (@treebase || self.default_treebase)
  end
end

#treebase=(new_value) ⇒ Object



42
43
44
# File 'lib/ad-framework/schema.rb', line 42

def treebase=(new_value)
  @treebase = new_value
end