Class: DevDNSd::Application
- Inherits:
-
RExec::Daemon::Base
- Object
- RExec::Daemon::Base
- DevDNSd::Application
- Includes:
- DevDNSd::ApplicationMethods::Server, DevDNSd::ApplicationMethods::System, Lazier::I18n
- Defined in:
- lib/devdnsd/application.rb
Overview
The main DevDNSd application.
Constant Summary
- ANY_REQUEST =
Class for ANY DNS request.
Resolv::DNS::Resource::IN::ANY
- ANY_CLASSES =
List of classes handled in case of DNS request with resource class ANY.
[Resolv::DNS::Resource::IN::A, Resolv::DNS::Resource::IN::AAAA, Resolv::DNS::Resource::IN::ANY, Resolv::DNS::Resource::IN::CNAME, Resolv::DNS::Resource::IN::HINFO, Resolv::DNS::Resource::IN::MINFO, Resolv::DNS::Resource::IN::MX, Resolv::DNS::Resource::IN::NS, Resolv::DNS::Resource::IN::PTR, Resolv::DNS::Resource::IN::SOA, Resolv::DNS::Resource::IN::TXT]
Instance Attribute Summary (collapse)
-
- (Mamertes::Command) command
readonly
The Mamertes command.
-
- (Configuration) config
readonly
The Configuration of this application.
-
- (Symbol|nil) locale
readonly
The current application locale.
-
- (Bovem::Logger) logger
The logger for this application.
Class Method Summary (collapse)
-
+ (Object) check_ruby_implementation
Check if the current implementation supports DevDNSd.
-
+ (Application) instance(command = nil, locale = nil, force = false)
Returns a unique (singleton) instance of the application.
-
+ (Object) quit
Stops the application.
-
+ (Object) run
Runs the application in foreground.
Instance Method Summary (collapse)
-
- (Logger) get_logger
Gets the current logger of the application.
-
- (Application) initialize(command, locale)
constructor
Creates a new application.
-
- (NilClass) on_start
This method is called when the server starts.
-
- (NilClass) on_stop
This method is called when the server stop.
Methods included from DevDNSd::ApplicationMethods::Server
#perform_server, #process_rule, #process_rule_in_classes
Methods included from DevDNSd::ApplicationMethods::System
#action_install, #action_start, #action_stop, #action_uninstall, #dns_update, #execute_command, #is_osx?, #launch_agent_path, #resolver_path
Constructor Details
- (Application) initialize(command, locale)
Creates a new application.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/devdnsd/application.rb', line 392 def initialize(command, locale) self.i18n_setup(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.i18n = locale @locale = locale @command = command = @command.application..reject {|_, v| v.nil? } # Setup logger Bovem::Logger.start_time = Time.now @logger = Bovem::Logger.create(Bovem::Logger.get_real_file(["log_file"]) || Bovem::Logger.default_file, Logger::INFO) # Open configuration read_configuration() self end |
Instance Attribute Details
- (Mamertes::Command) command (readonly)
The Mamertes command.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/devdnsd/application.rb', line 372 class Application < RExec::Daemon::Base # Class for ANY DNS request. ANY_REQUEST = Resolv::DNS::Resource::IN::ANY # List of classes handled in case of DNS request with resource class ANY. ANY_CLASSES = [Resolv::DNS::Resource::IN::A, Resolv::DNS::Resource::IN::AAAA, Resolv::DNS::Resource::IN::ANY, Resolv::DNS::Resource::IN::CNAME, Resolv::DNS::Resource::IN::HINFO, Resolv::DNS::Resource::IN::MINFO, Resolv::DNS::Resource::IN::MX, Resolv::DNS::Resource::IN::NS, Resolv::DNS::Resource::IN::PTR, Resolv::DNS::Resource::IN::SOA, Resolv::DNS::Resource::IN::TXT] include Lazier::I18n include DevDNSd::ApplicationMethods::System include DevDNSd::ApplicationMethods::Server attr_reader :config attr_reader :command attr_accessor :logger attr_reader :locale # Creates a new application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. def initialize(command, locale) self.i18n_setup(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.i18n = locale @locale = locale @command = command = @command.application..reject {|_, v| v.nil? } # Setup logger Bovem::Logger.start_time = Time.now @logger = Bovem::Logger.create(Bovem::Logger.get_real_file(["log_file"]) || Bovem::Logger.default_file, Logger::INFO) # Open configuration read_configuration() self end # Gets the current logger of the application. # # @return [Logger] The current logger of the application. def get_logger @logger ||= Bovem::Logger.create(@config.foreground ? Bovem::Logger.default_file : @config.log_file, @config.log_level, @log_formatter) end # This method is called when the server starts. By default is a no-op. # # @return [NilClass] `nil`. def on_start end # This method is called when the server stop. # # @return [NilClass] `nil`. def on_stop end # Returns a unique (singleton) instance of the application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. # @param force [Boolean] If to force recreation of the instance. # @return [Application] The unique (singleton) instance of the application. def self.instance(command = nil, locale = nil, force = false) @instance = nil if force @instance ||= DevDNSd::Application.new(command, locale) if command @instance end # Runs the application in foreground. # # @see #perform_server def self.run self.instance.perform_server end # Stops the application. def self.quit ::EventMachine.stop rescue nil end # Check if the current implementation supports DevDNSd. def self.check_ruby_implementation if defined?(Rubinius) || defined?(JRuby) then Kernel.puts(Lazier::Localizer.new(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")).i18n.no_jruby_rubinius) Kernel.exit(0) end end private # Reads configuration. # # @param options [Hash] The configuration to read. def read_configuration() begin @config = DevDNSd::Configuration.new(["configuration"], , @logger) @logger = nil @logger = self.get_logger rescue Bovem::Errors::InvalidConfiguration => e @logger ? @logger.fatal(e.) : Bovem::Logger.create("STDERR").fatal(self.i18n.logging_failed(log_file)) raise ::SystemExit end end end |
- (Configuration) config (readonly)
The Configuration of this application.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/devdnsd/application.rb', line 372 class Application < RExec::Daemon::Base # Class for ANY DNS request. ANY_REQUEST = Resolv::DNS::Resource::IN::ANY # List of classes handled in case of DNS request with resource class ANY. ANY_CLASSES = [Resolv::DNS::Resource::IN::A, Resolv::DNS::Resource::IN::AAAA, Resolv::DNS::Resource::IN::ANY, Resolv::DNS::Resource::IN::CNAME, Resolv::DNS::Resource::IN::HINFO, Resolv::DNS::Resource::IN::MINFO, Resolv::DNS::Resource::IN::MX, Resolv::DNS::Resource::IN::NS, Resolv::DNS::Resource::IN::PTR, Resolv::DNS::Resource::IN::SOA, Resolv::DNS::Resource::IN::TXT] include Lazier::I18n include DevDNSd::ApplicationMethods::System include DevDNSd::ApplicationMethods::Server attr_reader :config attr_reader :command attr_accessor :logger attr_reader :locale # Creates a new application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. def initialize(command, locale) self.i18n_setup(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.i18n = locale @locale = locale @command = command = @command.application..reject {|_, v| v.nil? } # Setup logger Bovem::Logger.start_time = Time.now @logger = Bovem::Logger.create(Bovem::Logger.get_real_file(["log_file"]) || Bovem::Logger.default_file, Logger::INFO) # Open configuration read_configuration() self end # Gets the current logger of the application. # # @return [Logger] The current logger of the application. def get_logger @logger ||= Bovem::Logger.create(@config.foreground ? Bovem::Logger.default_file : @config.log_file, @config.log_level, @log_formatter) end # This method is called when the server starts. By default is a no-op. # # @return [NilClass] `nil`. def on_start end # This method is called when the server stop. # # @return [NilClass] `nil`. def on_stop end # Returns a unique (singleton) instance of the application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. # @param force [Boolean] If to force recreation of the instance. # @return [Application] The unique (singleton) instance of the application. def self.instance(command = nil, locale = nil, force = false) @instance = nil if force @instance ||= DevDNSd::Application.new(command, locale) if command @instance end # Runs the application in foreground. # # @see #perform_server def self.run self.instance.perform_server end # Stops the application. def self.quit ::EventMachine.stop rescue nil end # Check if the current implementation supports DevDNSd. def self.check_ruby_implementation if defined?(Rubinius) || defined?(JRuby) then Kernel.puts(Lazier::Localizer.new(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")).i18n.no_jruby_rubinius) Kernel.exit(0) end end private # Reads configuration. # # @param options [Hash] The configuration to read. def read_configuration() begin @config = DevDNSd::Configuration.new(["configuration"], , @logger) @logger = nil @logger = self.get_logger rescue Bovem::Errors::InvalidConfiguration => e @logger ? @logger.fatal(e.) : Bovem::Logger.create("STDERR").fatal(self.i18n.logging_failed(log_file)) raise ::SystemExit end end end |
- (Symbol|nil) locale (readonly)
The current application locale.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/devdnsd/application.rb', line 372 class Application < RExec::Daemon::Base # Class for ANY DNS request. ANY_REQUEST = Resolv::DNS::Resource::IN::ANY # List of classes handled in case of DNS request with resource class ANY. ANY_CLASSES = [Resolv::DNS::Resource::IN::A, Resolv::DNS::Resource::IN::AAAA, Resolv::DNS::Resource::IN::ANY, Resolv::DNS::Resource::IN::CNAME, Resolv::DNS::Resource::IN::HINFO, Resolv::DNS::Resource::IN::MINFO, Resolv::DNS::Resource::IN::MX, Resolv::DNS::Resource::IN::NS, Resolv::DNS::Resource::IN::PTR, Resolv::DNS::Resource::IN::SOA, Resolv::DNS::Resource::IN::TXT] include Lazier::I18n include DevDNSd::ApplicationMethods::System include DevDNSd::ApplicationMethods::Server attr_reader :config attr_reader :command attr_accessor :logger attr_reader :locale # Creates a new application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. def initialize(command, locale) self.i18n_setup(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.i18n = locale @locale = locale @command = command = @command.application..reject {|_, v| v.nil? } # Setup logger Bovem::Logger.start_time = Time.now @logger = Bovem::Logger.create(Bovem::Logger.get_real_file(["log_file"]) || Bovem::Logger.default_file, Logger::INFO) # Open configuration read_configuration() self end # Gets the current logger of the application. # # @return [Logger] The current logger of the application. def get_logger @logger ||= Bovem::Logger.create(@config.foreground ? Bovem::Logger.default_file : @config.log_file, @config.log_level, @log_formatter) end # This method is called when the server starts. By default is a no-op. # # @return [NilClass] `nil`. def on_start end # This method is called when the server stop. # # @return [NilClass] `nil`. def on_stop end # Returns a unique (singleton) instance of the application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. # @param force [Boolean] If to force recreation of the instance. # @return [Application] The unique (singleton) instance of the application. def self.instance(command = nil, locale = nil, force = false) @instance = nil if force @instance ||= DevDNSd::Application.new(command, locale) if command @instance end # Runs the application in foreground. # # @see #perform_server def self.run self.instance.perform_server end # Stops the application. def self.quit ::EventMachine.stop rescue nil end # Check if the current implementation supports DevDNSd. def self.check_ruby_implementation if defined?(Rubinius) || defined?(JRuby) then Kernel.puts(Lazier::Localizer.new(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")).i18n.no_jruby_rubinius) Kernel.exit(0) end end private # Reads configuration. # # @param options [Hash] The configuration to read. def read_configuration() begin @config = DevDNSd::Configuration.new(["configuration"], , @logger) @logger = nil @logger = self.get_logger rescue Bovem::Errors::InvalidConfiguration => e @logger ? @logger.fatal(e.) : Bovem::Logger.create("STDERR").fatal(self.i18n.logging_failed(log_file)) raise ::SystemExit end end end |
- (Bovem::Logger) logger
The logger for this application.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/devdnsd/application.rb', line 372 class Application < RExec::Daemon::Base # Class for ANY DNS request. ANY_REQUEST = Resolv::DNS::Resource::IN::ANY # List of classes handled in case of DNS request with resource class ANY. ANY_CLASSES = [Resolv::DNS::Resource::IN::A, Resolv::DNS::Resource::IN::AAAA, Resolv::DNS::Resource::IN::ANY, Resolv::DNS::Resource::IN::CNAME, Resolv::DNS::Resource::IN::HINFO, Resolv::DNS::Resource::IN::MINFO, Resolv::DNS::Resource::IN::MX, Resolv::DNS::Resource::IN::NS, Resolv::DNS::Resource::IN::PTR, Resolv::DNS::Resource::IN::SOA, Resolv::DNS::Resource::IN::TXT] include Lazier::I18n include DevDNSd::ApplicationMethods::System include DevDNSd::ApplicationMethods::Server attr_reader :config attr_reader :command attr_accessor :logger attr_reader :locale # Creates a new application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. def initialize(command, locale) self.i18n_setup(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")) self.i18n = locale @locale = locale @command = command = @command.application..reject {|_, v| v.nil? } # Setup logger Bovem::Logger.start_time = Time.now @logger = Bovem::Logger.create(Bovem::Logger.get_real_file(["log_file"]) || Bovem::Logger.default_file, Logger::INFO) # Open configuration read_configuration() self end # Gets the current logger of the application. # # @return [Logger] The current logger of the application. def get_logger @logger ||= Bovem::Logger.create(@config.foreground ? Bovem::Logger.default_file : @config.log_file, @config.log_level, @log_formatter) end # This method is called when the server starts. By default is a no-op. # # @return [NilClass] `nil`. def on_start end # This method is called when the server stop. # # @return [NilClass] `nil`. def on_stop end # Returns a unique (singleton) instance of the application. # # @param command [Mamertes::Command] The current Mamertes command. # @param locale [Symbol] The locale to use for the application. # @param force [Boolean] If to force recreation of the instance. # @return [Application] The unique (singleton) instance of the application. def self.instance(command = nil, locale = nil, force = false) @instance = nil if force @instance ||= DevDNSd::Application.new(command, locale) if command @instance end # Runs the application in foreground. # # @see #perform_server def self.run self.instance.perform_server end # Stops the application. def self.quit ::EventMachine.stop rescue nil end # Check if the current implementation supports DevDNSd. def self.check_ruby_implementation if defined?(Rubinius) || defined?(JRuby) then Kernel.puts(Lazier::Localizer.new(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")).i18n.no_jruby_rubinius) Kernel.exit(0) end end private # Reads configuration. # # @param options [Hash] The configuration to read. def read_configuration() begin @config = DevDNSd::Configuration.new(["configuration"], , @logger) @logger = nil @logger = self.get_logger rescue Bovem::Errors::InvalidConfiguration => e @logger ? @logger.fatal(e.) : Bovem::Logger.create("STDERR").fatal(self.i18n.logging_failed(log_file)) raise ::SystemExit end end end |
Class Method Details
+ (Object) check_ruby_implementation
Check if the current implementation supports DevDNSd.
454 455 456 457 458 459 |
# File 'lib/devdnsd/application.rb', line 454 def self.check_ruby_implementation if defined?(Rubinius) || defined?(JRuby) then Kernel.puts(Lazier::Localizer.new(:devdnsd, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")).i18n.no_jruby_rubinius) Kernel.exit(0) end end |
+ (Application) instance(command = nil, locale = nil, force = false)
Returns a unique (singleton) instance of the application.
435 436 437 438 439 |
# File 'lib/devdnsd/application.rb', line 435 def self.instance(command = nil, locale = nil, force = false) @instance = nil if force @instance ||= DevDNSd::Application.new(command, locale) if command @instance end |
+ (Object) quit
Stops the application.
449 450 451 |
# File 'lib/devdnsd/application.rb', line 449 def self.quit ::EventMachine.stop rescue nil end |
+ (Object) run
Runs the application in foreground.
444 445 446 |
# File 'lib/devdnsd/application.rb', line 444 def self.run self.instance.perform_server end |
Instance Method Details
- (Logger) get_logger
Gets the current logger of the application.
413 414 415 |
# File 'lib/devdnsd/application.rb', line 413 def get_logger @logger ||= Bovem::Logger.create(@config.foreground ? Bovem::Logger.default_file : @config.log_file, @config.log_level, @log_formatter) end |
- (NilClass) on_start
This method is called when the server starts. By default is a no-op.
420 421 |
# File 'lib/devdnsd/application.rb', line 420 def on_start end |
- (NilClass) on_stop
This method is called when the server stop.
426 427 |
# File 'lib/devdnsd/application.rb', line 426 def on_stop end |