In Files

  • webrick/httpauth/htgroup.rb

WEBrick::HTTPAuth::Htgroup

Public Class Methods

new(path) click to toggle source
 
               # File webrick/httpauth/htgroup.rb, line 15
def initialize(path)
  @path = path
  @mtime = Time.at(0)
  @group = Hash.new
  open(@path,"a").close unless File::exist?(@path)
  reload
end
            

Public Instance Methods

add(group, members) click to toggle source
 
               # File webrick/httpauth/htgroup.rb, line 56
def add(group, members)
  @group[group] = members(group) | members
end
            
flush(output=nil) click to toggle source
 
               # File webrick/httpauth/htgroup.rb, line 37
def flush(output=nil)
  output ||= @path
  tmp = Tempfile.new("htgroup", File::dirname(output))
  begin
    @group.keys.sort.each{|group|
      tmp.puts(format("%s: %s", group, self.members(group).join(" ")))
    }
    tmp.close
    File::rename(tmp.path, output)
  rescue
    tmp.close(true)
  end
end
            
members(group) click to toggle source
 
               # File webrick/httpauth/htgroup.rb, line 51
def members(group)
  reload
  @group[group] || []
end
            
reload() click to toggle source
 
               # File webrick/httpauth/htgroup.rb, line 23
def reload
  if (mtime = File::mtime(@path)) > @mtime
    @group.clear
    open(@path){|io|
      while line = io.gets
        line.chomp!
        group, members = line.split(/:\s*/)
        @group[group] = members.split(/\s+/)
      end
    }
    @mtime = mtime
  end
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus