Module: RJR

Defined in:
lib/rjr/errors.rb,
lib/rjr/node.rb,
lib/rjr/common.rb,
lib/rjr/common.rb,
lib/rjr/message.rb,
lib/rjr/version.rb,
lib/rjr/nodes/tcp.rb,
lib/rjr/nodes/web.rb,
lib/rjr/dispatcher.rb,
lib/rjr/em_adapter.rb,
lib/rjr/nodes/amqp.rb,
lib/rjr/nodes/easy.rb,
lib/rjr/nodes/unix.rb,
lib/rjr/nodes/local.rb,
lib/rjr/nodes/multi.rb,
lib/rjr/thread_pool.rb,
lib/rjr/nodes/missing.rb,
lib/rjr/nodes/template.rb,
lib/rjr/nodes/ws.rb

Overview

Thread Pool (second implementation)

Copyright © 2010-2013 Mohammed Morsi <[email protected]> Licensed under the Apache License, Version 2.0

Defined Under Namespace

Modules: Errors, MessageMixins, Nodes Classes: Dispatcher, EMAdapter, Logger, MessageUtil, Node, NodeCallback, NotificationMessage, Request, RequestMessage, ResponseMessage, Result, ThreadPool, ThreadPoolJob

Constant Summary collapse

VERSION =
'0.18.2'

Class Method Summary collapse

Class Method Details

.invalid_json_class?(jc) ⇒ Boolean

Returns:

  • (Boolean)


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/rjr/common.rb', line 201

def self.invalid_json_class?(jc)
  Class.whitelist_json_classes ||= false

  Class.whitelist_json_classes ?
    # only permit classes user explicitly authorizes
    !Class.permitted_json_classes.include?(jc) :

    # allow any class
    jc.to_s.split(/::/).inject(Object) do |p,c|
      case
      when c.empty?  then p
      when p.constants.collect { |c| c.to_s }.include?(c)
        then p.const_get(c)
      else
        nil
      end
    end.nil?
end

.parse_json(js) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
# File 'lib/rjr/common.rb', line 242

def self.parse_json(js)
  jp = ::JSON.parse js, :create_additions => false
  if jp.is_a?(Array)
    validate_json_array(jp)
  elsif jp.is_a?(Hash)
    validate_json_hash(jp)
  else
    return jp
  end
  ::JSON.parse js, :create_additions => true
end

.persistent_nodesObject

Return the persistent rjr nodes



19
20
21
22
23
24
25
26
# File 'lib/rjr/common.rb', line 19

def self.persistent_nodes
  # rerun each time (eg don't store in var) incase new nodes were included
  RJR::Nodes.constants.collect { |n|
    nc = RJR::Nodes.const_get(n)
    nc.superclass == RJR::Node && nc.persistent? ?
    nc : nil
  }.compact
end

.validate_json_array(ja) ⇒ Object



232
233
234
235
236
237
238
239
240
# File 'lib/rjr/common.rb', line 232

def self.validate_json_array(ja)
  ja.each { |jai|
    if jai.is_a?(Array)
      validate_json_array(jai)
    elsif jai.is_a?(Hash)
      validate_json_hash(jai)
    end
  }
end

.validate_json_hash(jh) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/rjr/common.rb', line 220

def self.validate_json_hash(jh)
  jh.each { |k,v|
    if k == ::JSON.create_id && invalid_json_class?(v)
      raise ArgumentError, "can't create json class #{v}"
    elsif v.is_a?(Array)
      validate_json_array(v)
    elsif v.is_a?(Hash)
      validate_json_hash(v)
    end
  }
end