Module: SMQueue

Defined in:
lib/smqueue.rb,
lib/smqueue/adapters/stdio.rb,
lib/smqueue/adapters/stdio.rb,
lib/smqueue/adapters/stdio.rb,
lib/smqueue/adapters/stdio.rb,
lib/smqueue/adapters/stomp.rb,
lib/smqueue/adapters/spread.rb

Overview

set of utility adapters for SMQueue

Defined Under Namespace

Classes: Adapter, AdapterConfiguration, Message, NullAdapter, ReadlineAdapter, SpreadAdapter, StdioAdapter, StdioLineAdapter, StompAdapter, YamlAdapter

Constant Summary collapse

VERSION =

Mr Bones project skeleton boilerplate :stopdoc:

'0.2.0'
LIBPATH =
::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
ReadLineAdapter =
ReadlineAdapter

Class Method Summary collapse

Class Method Details

.calc_expiry_time(seconds = 86400 * 7) ⇒ Object

JMS expiry time in milliseconds from now



96
97
98
# File 'lib/smqueue.rb', line 96

def calc_expiry_time(seconds = 86400 * 7) # one week
  ((Time.now.utc + seconds).to_f * 1000).to_i
end

.const_resolve(constant) ⇒ Object

resolve a string representing a classname



101
102
103
# File 'lib/smqueue.rb', line 101

def const_resolve(constant)
  constant.to_s.split(/::/).reject{|x| x.empty?}.inject(self) { |prev, this| prev.const_get(this) }
end

.dbg(*args, &block) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/smqueue.rb', line 82

def dbg(*args, &block)
  if $DEBUG
    if args.size > 0
      STDERR.print "SMQUEUE.DBG: "
      STDERR.puts(*args)
    end
    if block_given?
      STDERR.print "SMQUEUE.DBG: "
      STDERR.puts(block.call)
    end
  end
end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



54
55
56
# File 'lib/smqueue.rb', line 54

def self.libpath( *args )
  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end

.new(*args, &block) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/smqueue.rb', line 183

def new(*args, &block)
  a = args.first
  if a.kind_of?(Hash) && a.key?(:configuration)
    args = [a[:configuration]]
  end
  Adapter.create(*args, &block)
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



62
63
64
# File 'lib/smqueue.rb', line 62

def self.path( *args )
  args.empty? ? PATH : ::File.join(PATH, args.flatten)
end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to rquire all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



71
72
73
74
75
76
77
# File 'lib/smqueue.rb', line 71

def self.require_all_libs_relative_to( fname, dir = nil )
  dir ||= ::File.basename(fname, '.*')
  search_me = ::File.expand_path(
      ::File.join(::File.dirname(fname), dir, '*', '*.rb'))

  Dir.glob(search_me).sort.each {|rb| require rb}
end

.versionObject

Returns the version string for the library.



46
47
48
# File 'lib/smqueue.rb', line 46

def self.version
  VERSION
end