Module: Bridge::Util

Defined in:
lib/util.rb

Overview

:nodoc: all

Defined Under Namespace

Classes: CallbackReference

Class Method Summary collapse

Class Method Details

.error(msg) ⇒ Object



32
33
34
# File 'lib/util.rb', line 32

def self.error msg
  @log.error msg
end

.find_ops(obj) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/util.rb', line 55

def self.find_ops obj
  if obj.is_a? Module
    return obj.methods false
  else
    return obj.class.instance_methods false
  end
end

.generate_guidObject



11
12
13
14
# File 'lib/util.rb', line 11

def self.generate_guid
  chars = (('a'..'z').to_a + (0..9).to_a)
  (0...12).map{ chars[rand(26)] }.join
end

.info(msg) ⇒ Object



24
25
26
# File 'lib/util.rb', line 24

def self.info msg
  @log.info msg
end

.parse(str) ⇒ Object



20
21
22
# File 'lib/util.rb', line 20

def self.parse str
  JSON::parse str
end

.ref_callback(ref) ⇒ Object



48
49
50
51
52
53
# File 'lib/util.rb', line 48

def self.ref_callback ref
  CallbackReference.new ref do |*args, &blk|
    args << blk if blk
    self.call *args
  end
end

.set_log_level(level) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/util.rb', line 36

def self.set_log_level level
  if level > 2
    @log.level = Logger::INFO
  elsif level == 2
    @log.level = Logger::WARN
  elsif level == 1
    @log.level = Logger::ERROR
  else
    @log.level = Logger::FATAL
  end
end

.stringify(obj) ⇒ Object



16
17
18
# File 'lib/util.rb', line 16

def self.stringify obj
  JSON::generate obj
end

.warn(msg) ⇒ Object



28
29
30
# File 'lib/util.rb', line 28

def self.warn msg
  @log.warn msg
end