Top Level Namespace

Defined Under Namespace

Modules: AbstractNumeric, AbstractPopover, AbstractStringInput, ClassesInput, Logging, MNotification, MRelogin, MReport, Modal Classes: ArrayInput, BullClientController, BullServerController, CheckInput, DisplayDoc, DisplayList, EMLogger, FloatCommaInput, FloatInput, Form, FormButtons, HashInput, HorizontalMenu, IntegerCommaInput, IntegerInput, MultiLineInput, MultipleSelectInput, Notification, NotificationController, PasswordInput, RVar, RadioInput, SelectInput, SelectObjectInput, StringInput

Instance Method Summary collapse

Instance Method Details

#encode_times(doc, base = '') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bull/encode_times.rb', line 25

def encode_times doc, base=''
  ret = []
  if doc.is_a? Array
    doc.each_with_index { |v, i| ret << encode_times(v, base + '.' + i.to_s)}
  elsif doc.is_a? Hash
    doc.each_pair {|k, v| ret << encode_times(v, base + '.' + k.to_s)}
  elsif doc.is_a? Time
    return base[1..-1]
  end
  ret.flatten
end

#format_float(value) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
# File 'lib/bull/ui_core.rb', line 272

def format_float value
  e, d = value.to_s.split('.')
  d = '' if value.to_s.end_with?('.')
  return '' if e.nil?
  v = format_integer e
  if d.nil?
    v
  else
    v + '.' + d
  end
end

#format_integer(value) ⇒ Object



262
263
264
265
266
267
268
269
270
# File 'lib/bull/ui_core.rb', line 262

def format_integer value
  path = value.to_s.reverse.split(/(\d\d\d)/).select{|v| v != ''}
  if path[-1] == '-'
    path.pop
    '-' + path.join(',').reverse
  else
    path.join(',').reverse
  end
end

#get_nested!(ret, attr) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bull/utils.rb', line 22

def get_nested! ret, attr
  ret_ = ret
  path = attr.split '.'
  root = path.shift
  doc = {}
  doc[root] = yield root

  if path.empty?
    ret[root] = doc[root] if root != 'id'
  else
    path.unshift root
    while !path.empty?
      aux = path.shift
      doc = doc[aux]
      if path.empty?
        ret[aux] = doc
      else
        ret = ret[aux] || ret[aux] = {}
      end
    end
  end
  ret_
end

#reactive(*args, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/bull/reactive_var.rb', line 85

def reactive(*args, &block)
    ret = {}
    args.each do |v|
        id = v.add(block)
        ret[id] = v
    end
    block.call
    ret
end

#resolve_times(doc, keys) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bull/encode_times.rb', line 3

def resolve_times doc, keys
  keys.each do |k|
    d = doc
    ks = k.split('.')
    attr = ks.shift.to_sym
    while ks != []
      if d.is_a? Array
        d = d[attr.to_i]
      else
        d = d[attr]
      end
      attr = ks.shift.to_sym
    end
    begin
        i = Integer(attr.to_s)
        d[i] = Time.parse d[i]
    rescue
        d[attr] = Time.parse d[attr]
    end
  end
end

#set_nested(attr, value, doc) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bull/utils.rb', line 1

def set_nested attr, value, doc
  path = attr.split '.'
  root = path.shift
  if path.empty?
    yield root, value
  else
    doc = doc[root] || {}
    doc_ = doc
    while !path.empty?
      aux = path.shift
      if path.empty?
        doc[aux] = value
      else
        doc[aux] = {} if doc[aux].nil?
        doc = doc[aux]
      end
    end
    yield root, doc_
  end
end

#start(app_controller, key_path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bull/start.rb', line 8

def start app_controller, key_path
  puts Time.now
  #MReport.load_reports

  $r = RethinkDB::RQL.new
  conn = $r.connect()

  EM.run do
    EM::WebSocket.run(:host => "0.0.0.0",
                      :port => 3000,
                      :secure => true,
                      :tls_options => {
                        :private_key_file => File.join(key_path, 'privateKey.key'), # "../../privateKey.key",
                        :cert_chain_file => File.join(key_path, 'certificate.crt') #"../../certificate.crt"
                      }
                      ) do |ws|
      controller = nil

      ws.onopen { |handshake| controller = app_controller.new ws, conn}

      ws.onmessage do |msg|
        begin
          controller.notify msg
        rescue Exception => e
          puts 'message: ', e.message
          puts 'trace: ', e.backtrace.inspect
        end
      end

      ws.onclose { controller.close; controller = nil }

      ws.onerror { |e| puts "Error: #{e.message}"}
    end
  end
end

#symbolize_keys(obj) ⇒ Object



1
2
3
4
5
6
7
8
9
# File 'lib/bull/symbolize.rb', line 1

def symbolize_keys obj
  if obj.is_a? Hash
    return obj.inject({}) {|memo, (k, v)| memo[k.to_sym]=symbolize_keys(v); memo}
  end
  if obj.is_a? Array
    return obj.map {|x| symbolize_keys x}
  end
  obj
end