Class: BackgroundQueue::ServerLib::Config::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/server_lib/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_entry) ⇒ Address

Returns a new instance of Address.



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/background_queue/server_lib/config.rb', line 207

def initialize(config_entry)
  if config_entry.nil? 
    @host = "0.0.0.0"
    @port = BackgroundQueue::Config::DEFAULT_PORT
  else
    port = BackgroundQueue::Utils.get_hash_entry(config_entry, :port)
    if port.nil?
      @port = BackgroundQueue::Config::DEFAULT_PORT
    elsif port.kind_of?(Numeric)
      @port = port.to_i
    elsif port.kind_of?(String)
      if port.to_s.strip == port.to_s.to_i.to_s
        @port = port.to_i
      else
        raise "Invalid port: #{port}"
      end
    else
      raise "Invalid port: should be number or string"
    end
    if @port <= 0
      raise "Invalid port: must be greater then zero"
    end
    host = BackgroundQueue::Utils.get_hash_entry(config_entry, :host)
    if host.nil?
      @host = "0.0.0.0"
    elsif host.kind_of?(String)
      if IPAddress.valid? host
        @host = host
      else
        raise "Invalid host: #{host}"
      end
    else
      raise "Invalid host: should be string"
    end
  end
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



203
204
205
# File 'lib/background_queue/server_lib/config.rb', line 203

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



204
205
206
# File 'lib/background_queue/server_lib/config.rb', line 204

def port
  @port
end