Module: UCB::LDAP::Schema

Defined in:
lib/ucb_ldap/schema.rb,
lib/ucb_ldap/schema_attribute.rb

Overview

UCB::LDAP::Schema

Class responsible for getting schema information for all of the UCB::LDAP entities. Attributes are modeled as instances of UCB::LDAP::Schema::Attribute.

Each entity (Person, Org, etc.) has a Hash of attributes where the keys are canonical (see Entry.canonical) attribute/alias names and the values are Schema::Attribute’s.

You don’t have to explicitly load schema information; the UCB::LDAP module loads schema information as needed. Unless you want to override the schema url (or file) you probably won’t need to work directly with this class.

Schema Source

Schema information is loaded from a url defined by the SCHEMA_* constants. A version of the file is distributed with this Gem and is used in case the web version is not accessible.

Defined Under Namespace

Classes: Attribute

Constant Summary collapse

SCHEMA_BASE_URL =
'calnet.berkeley.edu'
SCHEMA_CONTENT_PATH =
'/developers/developerResources/yaml/schema/schema.yaml'
SCHEMA_FILE =
"#{File.dirname(__FILE__)}/../../schema/schema.yml"

Class Method Summary collapse

Class Method Details

.load_attributes(no_warn = false) ⇒ Object

Load attributes from URL or file



82
83
84
85
86
87
# File 'lib/ucb_ldap/schema.rb', line 82

def load_attributes(no_warn=false) #:nodoc:
  load_attributes_from_url
rescue
  puts "Warning: schema loading from file" unless no_warn
  load_attributes_from_file
end

.load_attributes_from_fileObject

:nodoc:



104
105
106
# File 'lib/ucb_ldap/schema.rb', line 104

def load_attributes_from_file #:nodoc:
  self.schema_hash = YAML.load(yaml_from_file)
end

.load_attributes_from_urlObject

:nodoc:



89
90
91
# File 'lib/ucb_ldap/schema.rb', line 89

def load_attributes_from_url #:nodoc:
  self.schema_hash = YAML.load(yaml_from_url)
end

.schema_base_urlObject

Returns schema base url. Defaults to SCHEMA_BASE_URL constant.



42
43
44
# File 'lib/ucb_ldap/schema.rb', line 42

def schema_base_url
  @schema_base_url || SCHEMA_BASE_URL
end

.schema_base_url=(base_url) ⇒ Object

Setter for schema_base_url(). Use this to override url of LDAP schema information.



48
49
50
# File 'lib/ucb_ldap/schema.rb', line 48

def schema_base_url=(base_url)
  @schema_base_url = base_url
end

.schema_content_pathObject

Returns schema content path. Defaults to SCHEMA_CONTENT_PATH constant.



53
54
55
# File 'lib/ucb_ldap/schema.rb', line 53

def schema_content_path
  @schema_content_path || SCHEMA_CONTENT_PATH
end

.schema_content_path=(content_path) ⇒ Object

Setter for schema_content_path(). Use this to override content path of LDAP schema information.



59
60
61
# File 'lib/ucb_ldap/schema.rb', line 59

def schema_content_path=(content_path)
  @schema_content_path = content_path
end

.schema_fileObject

Returns schema file. Defaults fo SCHEMA_FILE constant.



64
65
66
# File 'lib/ucb_ldap/schema.rb', line 64

def schema_file
  @schema_file || SCHEMA_FILE
end

.schema_file=(file) ⇒ Object

Setter for schema_file(). Use this to override location of local schema file.



70
71
72
# File 'lib/ucb_ldap/schema.rb', line 70

def schema_file=(file)
  @schema_file = file
end

.schema_hashObject

Returns a hash of all attributes for all entities. Keys are entity names, values hash of attributes for given entity.



37
38
39
# File 'lib/ucb_ldap/schema.rb', line 37

def schema_hash()
  @schema_hash ||= load_attributes
end

.schema_hash=(h) ⇒ Object

Setter for schema_hash()



77
78
79
# File 'lib/ucb_ldap/schema.rb', line 77

def schema_hash=(h) #:nodoc:
  @schema_hash = h
end

.schema_hash_iObject

Get instance variable w/o loading – for testing purposes.



113
114
115
# File 'lib/ucb_ldap/schema.rb', line 113

def schema_hash_i #:nodoc:
  @schema_hash
end

.yaml_from_fileObject

:nodoc:



108
109
110
# File 'lib/ucb_ldap/schema.rb', line 108

def yaml_from_file #:nodoc:
  IO.read(schema_file)
end

.yaml_from_urlObject

:nodoc:



93
94
95
96
97
98
99
100
101
102
# File 'lib/ucb_ldap/schema.rb', line 93

def yaml_from_url #:nodoc:
  http = Net::HTTP.new(SCHEMA_BASE_URL, 443)
  http.use_ssl = true
  response = http.get(SCHEMA_CONTENT_PATH)
  if response.code == "200"
    response.body
  else
    raise("#{SCHEMA_BASE_URL}/#{SCHEMA_CONTENT_PATH} returned #{response.code}")
  end
end