Module: Hector

Defined in:
lib/hector/boot.rb,
lib/hector/errors.rb,
lib/hector/server.rb,
lib/hector/channel.rb,
lib/hector/logging.rb,
lib/hector/request.rb,
lib/hector/service.rb,
lib/hector/session.rb,
lib/hector/version.rb,
lib/hector/identity.rb,
lib/hector/response.rb,
lib/hector/deference.rb,
lib/hector/heartbeat.rb,
lib/hector/connection.rb,
lib/hector/commands/who.rb,
lib/hector/user_session.rb,
lib/hector/commands/away.rb,
lib/hector/commands/join.rb,
lib/hector/commands/mode.rb,
lib/hector/commands/nick.rb,
lib/hector/commands/part.rb,
lib/hector/commands/ping.rb,
lib/hector/commands/pong.rb,
lib/hector/commands/quit.rb,
lib/hector/commands/names.rb,
lib/hector/commands/topic.rb,
lib/hector/commands/whois.rb,
lib/hector/commands/invite.rb,
lib/hector/commands/notice.rb,
lib/hector/commands/privmsg.rb,
lib/hector/commands/realname.rb,
lib/hector/concerns/presence.rb,
lib/hector/concerns/keep_alive.rb,
lib/hector/yaml_identity_adapter.rb,
lib/hector/concerns/authentication.rb

Defined Under Namespace

Modules: Commands, Concerns Classes: CannotSendToChannel, Channel, Connection, ErroneousNickname, Error, Heartbeat, Identity, InvalidPassword, IrcError, LoadError, NicknameInUse, NoSuchChannel, NoSuchNickOrChannel, NullLogger, Request, Response, SSLConnection, Service, Session, UserSession, YamlIdentityAdapter

Constant Summary collapse

VERSION =
"1.0.4"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.addressObject

Returns the value of attribute address.



3
4
5
# File 'lib/hector/server.rb', line 3

def address
  @address
end

.libObject

Returns the value of attribute lib.



6
7
8
# File 'lib/hector/boot.rb', line 6

def lib
  @lib
end

.loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/hector/logging.rb', line 12

def logger
  @logger
end

.portObject

Returns the value of attribute port.



3
4
5
# File 'lib/hector/server.rb', line 3

def port
  @port
end

.rootObject

Returns the value of attribute root.



6
7
8
# File 'lib/hector/boot.rb', line 6

def root
  @root
end

.server_nameObject

Returns the value of attribute server_name.



3
4
5
# File 'lib/hector/server.rb', line 3

def server_name
  @server_name
end

.ssl_portObject

Returns the value of attribute ssl_port.



3
4
5
# File 'lib/hector/server.rb', line 3

def ssl_port
  @ssl_port
end

Class Method Details

.defer(&block) ⇒ Object



3
4
5
# File 'lib/hector/deference.rb', line 3

def defer(&block)
  EM.defer(&block)
end

.find_application_root_from(working_directory) ⇒ Object



36
37
38
39
40
# File 'lib/hector/boot.rb', line 36

def find_application_root_from(working_directory)
  dir = Pathname.new(working_directory)
  dir = dir.parent while dir != dir.parent && dir.basename.to_s !~ /\.hect$/
  dir == dir.parent ? nil : dir
end

.IrcError(command, *options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/hector/errors.rb', line 13

def self.IrcError(command, *options)
  fatal = options.last.is_a?(Hash) && options.last.delete(:fatal)
  Class.new(IrcError).tap do |klass|
    klass.class_eval do
      define_method(:command) { command.dup }
      define_method(:options) { options.dup }
      define_method(:fatal?) { fatal }
    end
  end
end

.load_applicationObject



31
32
33
34
# File 'lib/hector/boot.rb', line 31

def load_application
  $:.unshift Hector.root.join("lib")
  load Hector.root.join("init.rb")
end

.load_defaultsObject



22
23
24
25
26
27
28
29
# File 'lib/hector/boot.rb', line 22

def load_defaults
  log_path = Hector.root.join("log/hector.log")
  Hector.logger = Logger.new(log_path)
  Hector.logger.datetime_format = "%Y-%m-%d %H:%M:%S"

  identities_path = Hector.root.join("config/identities.yml")
  Hector::Identity.adapter = Hector::YamlIdentityAdapter.new(identities_path)
end

.load_rootObject



14
15
16
17
18
19
20
# File 'lib/hector/boot.rb', line 14

def load_root
  if root = ENV["HECTOR_ROOT"]
    Hector.root = Pathname.new(File.expand_path(root))
  else
    Hector.root = find_application_root_from(Dir.pwd)
  end
end

.next_tick(&block) ⇒ Object



7
8
9
# File 'lib/hector/deference.rb', line 7

def next_tick(&block)
  EM.next_tick(&block)
end

.startObject

Raises:



8
9
10
11
12
# File 'lib/hector/boot.rb', line 8

def start
  raise LoadError, "please specify HECTOR_ROOT" unless Hector.root
  load_defaults
  load_application
end

.start_serverObject



5
6
7
8
9
10
# File 'lib/hector/server.rb', line 5

def start_server
  EventMachine.start_server(@address, @port, Connection)
  EventMachine.start_server(@address, @ssl_port, SSLConnection)
  logger.info("Hector running on #{@address}:#{@port}")
  logger.info("Secure Hector running on #{@address}:#{@ssl_port}")
end