class RadiusRB::Dictionary

Constants

DEFAULT_DICTIONARIES_PATH

Public Class Methods

default() click to toggle source
# File lib/radiusrb/dictionary.rb, line 73
def default
  new DEFAULT_DICTIONARIES_PATH
end
new(initial_path = nil) click to toggle source
# File lib/radiusrb/dictionary.rb, line 26
def initialize(initial_path = nil)
  @attributes = AttributesCollection.new
  @vendors = VendorCollection.new

  read_files initial_path if initial_path
end

Public Instance Methods

attribute_id_defined?(id) click to toggle source
# File lib/radiusrb/dictionary.rb, line 55
def attribute_id_defined?(id)
  !@attributes.find_by_id(id).nil?
end
attribute_name_defined?(name) click to toggle source
# File lib/radiusrb/dictionary.rb, line 51
def attribute_name_defined?(name)
  !@attributes.find_by_name(name).nil?
end
attributes() click to toggle source
# File lib/radiusrb/dictionary.rb, line 63
def attributes
  @attributes
end
find_attribute_by_id(id) click to toggle source
# File lib/radiusrb/dictionary.rb, line 47
def find_attribute_by_id(id)
  @attributes.find_by_id(id)
end
find_attribute_by_name(name) click to toggle source
# File lib/radiusrb/dictionary.rb, line 43
def find_attribute_by_name(name)
  @attributes.find_by_name(name)
end
name() click to toggle source
# File lib/radiusrb/dictionary.rb, line 67
def name
  "Dictionary"
end
read_files(path) click to toggle source
# File lib/radiusrb/dictionary.rb, line 33
def read_files(path)
  dict_files = File.join(path, "*")
  Dir.glob(dict_files) { |file|
    read_attributes(file)
  }
  Dir.glob(dict_files) { |file|
    read_values(file)
  }
end
vendors() click to toggle source
# File lib/radiusrb/dictionary.rb, line 59
def vendors
  @vendors
end

Protected Instance Methods

read_attributes(path) click to toggle source
# File lib/radiusrb/dictionary.rb, line 81
def read_attributes(path)
  file = File.open(path) do |f|
    current_vendor = nil
    f.each_line do |line|
      next if line =~ /^\#/ # discard comments
      split_line = line.split(/\s+/)
      next if split_line == []
      case split_line.first.upcase
      when "ATTRIBUTE"
        current_vendor.nil? ? set_attr(split_line) : set_vendor_attr(current_vendor, split_line)
      when "VENDOR"
        add_vendor(split_line)
      when "BEGIN-VENDOR"
        current_vendor = set_vendor(split_line)
      when "END-VENDOR"
        current_vendor = nil
      end
    end
  end
end
read_values(path) click to toggle source
# File lib/radiusrb/dictionary.rb, line 102
def read_values(path)
  file = File.open(path) do |f|
    current_vendor = nil
    f.each_line do |line|
      next if line =~ /^\#/ # discard comments
      split_line = line.split(/\s+/)
      next if split_line == []
      case split_line.first.upcase
      when "VALUE"
        if current_vendor.nil?
          set_value(split_line)
        else
          begin
            set_vendor_value(current_vendor, split_line)
          rescue
            set_value(split_line)
          end
        end
      when "BEGIN-VENDOR"
        current_vendor = set_vendor(split_line)
      when "END-VENDOR"
        current_vendor = nil
      end
    end
  end
end

Private Instance Methods

add_vendor(line) click to toggle source
# File lib/radiusrb/dictionary.rb, line 139
def add_vendor(line)
  @vendors.add(line[2], line[1])
end
set_attr(line) click to toggle source
# File lib/radiusrb/dictionary.rb, line 131
def set_attr(line)
  @attributes.add(line[1], line[2], line[3])
end
set_value(line) click to toggle source
# File lib/radiusrb/dictionary.rb, line 135
def set_value(line)
  @attributes.find_by_name(line[1]).add_value(line[2], line[3])
end
set_vendor(line) click to toggle source
# File lib/radiusrb/dictionary.rb, line 143
def set_vendor(line)
  @vendors.find_by_name(line[1])
end
set_vendor_attr(vendor, line) click to toggle source
# File lib/radiusrb/dictionary.rb, line 147
def set_vendor_attr(vendor, line)
  vendor.add_attribute(line[1], line[2], line[3])
end
set_vendor_value(vendor, line) click to toggle source
# File lib/radiusrb/dictionary.rb, line 151
def set_vendor_value(vendor, line)
  vendor.find_attribute_by_name(line[1]).add_value(line[2], line[3])
end