Class: IAuthU::Server::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/iauthu/server.rb

Constant Summary collapse

RUNNERS =
{ :cgi => Rack::Handler::CGI,
          :webrick => Rack::Handler::WEBrick,
          :mongrel => Rack::Handler::Mongrel
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



121
122
123
# File 'lib/iauthu/server.rb', line 121

def initialize
  @server = Server.new
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



125
126
127
# File 'lib/iauthu/server.rb', line 125

def server
  @server
end

Instance Method Details

#auth(&block) ⇒ Object



131
132
133
# File 'lib/iauthu/server.rb', line 131

def auth(&block)
  @server.auth = Authenticator::Chained.build(&block)
end

#logger(dest) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/iauthu/server.rb', line 151

def logger(dest)
  if dest == :default
    dest = STDERR
  end
  if dest.kind_of?(IO) || dest.kind_of?(String) || dest.kind_of?(Symbol)
    CONFIG[:logger] = Logger.new(dest)
  else
    CONFIG[:logger] = dest
  end
end

#login_page(str_or_file = nil, &block) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/iauthu/server.rb', line 135

def (str_or_file=nil, &block)
  return if str_or_file == :default
  if str_or_file
    if File.exist?(str_or_file)
      File.open(str_or_file) do |f|
        @server. = f.read
      end
    else
      @server. = str_or_file
    end
    return
  else
    @server. = block.call.to_s
  end
end

#run(type, opts = {}) ⇒ Object



162
163
164
165
# File 'lib/iauthu/server.rb', line 162

def run(type, opts={})
  @server.runner = RUNNERS[type] || RUNNERS[:webrick]
  @server.port ||= opts[:port]
end

#site(&block) ⇒ Object



127
128
129
# File 'lib/iauthu/server.rb', line 127

def site(&block)
  @server.site = Site.build(&block)
end