Module: FSR::Cmd

Included in:
CommandSocket
Defined in:
lib/fsr/cmd.rb,
lib/fsr/cmd/chat.rb,
lib/fsr/cmd/enum.rb,
lib/fsr/cmd/kill.rb,
lib/fsr/cmd/calls.rb,
lib/fsr/cmd/fsctl.rb,
lib/fsr/cmd/sofia.rb,
lib/fsr/cmd/status.rb,
lib/fsr/cmd/channels.rb,
lib/fsr/cmd/originate.rb,
lib/fsr/cmd/uuid_dump.rb,
lib/fsr/cmd/conference.rb,
lib/fsr/cmd/valet_info.rb,
lib/fsr/cmd/call_center.rb,
lib/fsr/cmd/sched_hangup.rb,
lib/fsr/cmd/sofia/status.rb,
lib/fsr/cmd/sofia/profile.rb,
lib/fsr/cmd/sofia_contact.rb,
lib/fsr/cmd/uuid_transfer.rb,
lib/fsr/cmd/sched_transfer.rb,
lib/fsr/cmd/uuid_send_dtmf.rb

Defined Under Namespace

Classes: CallCenter, Calls, Channels, Chat, Command, Conference, Enum, Fsctl, Kill, Originate, SchedHangup, SchedTransfer, Sofia, SofiaContact, Status, UuidDump, UuidSendDtmf, UuidTransfer, ValetInfo

Constant Summary collapse

COMMANDS =
{}
LOAD_PATH =
[Pathname(FSR::ROOT).join( "fsr", "cmd")]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.listObject



34
35
36
# File 'lib/fsr/cmd.rb', line 34

def self.list
  COMMANDS.keys
end

.load_all(force_reload = false) ⇒ Object

Load all of the commands we find in Cmd::LOAD_PATH



63
64
65
66
67
68
# File 'lib/fsr/cmd.rb', line 63

def self.load_all(force_reload = false)
  LOAD_PATH.each do |load_path|
    Dir[load_path.join("*.rb").to_s].each { |command_file| load_command(command_file, force_reload) }
  end
  list
end

.load_command(command, force_reload = false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fsr/cmd.rb', line 38

def self.load_command(command, force_reload = false)
  # If we get a path specification and it's an existing file, load it
  if File.file?(command)
    if force_reload
      return load(command)
    else
      return require(command)
    end
  end
  Log.debug "Trying load paths"
  # If we find a file named the same as the command passed in LOAD_PATH, load it
  if found_command_path = LOAD_PATH.detect { |command_path| command_path.join("#{command}.rb").file? }
    command_file = found_command_path.join(command)
    Log.debug "Trying to load #{command_file}"
    if force_reload
      load command_file.to_s + ".rb"
    else
      require command_file
    end
  else
    raise "#{command} not found in #{LOAD_PATH.join(":")}"
  end
end

.register(command, obj) ⇒ Object



27
28
29
30
31
32
# File 'lib/fsr/cmd.rb', line 27

def self.register(command, obj)
  COMMANDS[command.to_sym] = obj

  code = "def %s(*args, &block) COMMANDS[%p].new(self, *args, &block) end" % [command, command]
  Cmd.module_eval(code)
end

Instance Method Details

#commandsObject



70
71
72
# File 'lib/fsr/cmd.rb', line 70

def commands
  FSR::Cmd.list
end