Module: Rhoconnect

Extended by:
Rhoconnect
Included in:
Rhoconnect, Server
Defined in:
lib/rhoconnect.rb,
lib/rhoconnect/app.rb,
lib/rhoconnect/user.rb,
lib/rhoconnect/async.rb,
lib/rhoconnect/store.rb,
lib/rhoconnect/client.rb,
lib/rhoconnect/server.rb,
lib/rhoconnect/source.rb,
lib/rhoconnect/license.rb,
lib/rhoconnect/version.rb,
lib/rhoconnect/ping/gcm.rb,
lib/rhoconnect/api_token.rb,
lib/rhoconnect/store_orm.rb,
lib/rhoconnect/credential.rb,
lib/rhoconnect/model/base.rb,
lib/rhoconnect/ping/apple.rb,
lib/rhoconnect/read_state.rb,
lib/rhoconnect/handler/sync.rb,
lib/rhoconnect/stats/record.rb,
lib/rhoconnect/test_methods.rb,
lib/rhoconnect/handler/query.rb,
lib/rhoconnect/jobs/ping_job.rb,
lib/rhoconnect/model/helpers.rb,
lib/rhoconnect/model/js_base.rb,
lib/rhoconnect/handler/search.rb,
lib/rhoconnect/condition/verbs.rb,
lib/rhoconnect/controller/base.rb,
lib/rhoconnect/handler/changes.rb,
lib/rhoconnect/jobs/source_job.rb,
lib/rhoconnect/application/init.rb,
lib/rhoconnect/middleware/stats.rb,
lib/rhoconnect/handler/bulk_data.rb,
lib/rhoconnect/controller/js_base.rb,
lib/rhoconnect/jobs/bulk_data_job.rb,
lib/rhoconnect/middleware/helpers.rb,
lib/rhoconnect/bulk_data/bulk_data.rb,
lib/rhoconnect/controller/app_base.rb,
lib/rhoconnect/handler/query/engine.rb,
lib/rhoconnect/handler/query/runner.rb,
lib/rhoconnect/ping/rhoconnect_push.rb,
lib/rhoconnect/handler/changes/hooks.rb,
lib/rhoconnect/handler/search/engine.rb,
lib/rhoconnect/handler/search/runner.rb,
lib/rhoconnect/handler/changes/engine.rb,
lib/rhoconnect/handler/changes/runner.rb,
lib/rhoconnect/middleware/current_app.rb,
lib/rhoconnect/rho_indifferent_access.rb,
lib/rhoconnect/condition/add_parameter.rb,
lib/rhoconnect/handler/helpers/binding.rb,
lib/rhoconnect/middleware/current_user.rb,
lib/rhoconnect/condition/admin_required.rb,
lib/rhoconnect/condition/login_required.rb,
lib/rhoconnect/condition/verify_success.rb,
lib/rhoconnect/handler/plugin_callbacks.rb,
lib/rhoconnect/condition/client_required.rb,
lib/rhoconnect/condition/source_required.rb,
lib/rhoconnect/handler/helpers/bulk_data.rb,
lib/rhoconnect/handler/helpers/source_job.rb,
lib/rhoconnect/controller/store_controller.rb,
lib/rhoconnect/controller/users_controller.rb,
lib/rhoconnect/handler/authenticate/runner.rb,
lib/rhoconnect/handler/helpers/auth_method.rb,
lib/rhoconnect/model/dynamic_adapter_model.rb,
lib/rhoconnect/controller/system_controller.rb,
lib/rhoconnect/controller/clients_controller.rb,
lib/rhoconnect/controller/sources_controller.rb,
lib/rhoconnect/handler/query/execute_methods.rb,
lib/rhoconnect/controller/source_adapter_base.rb,
lib/rhoconnect/handler/search/execute_methods.rb,
lib/rhoconnect/handler/changes/execute_methods.rb,
lib/rhoconnect/handler/plugin_callbacks/runner.rb,
lib/rhoconnect/controller/read_state_controller.rb,
lib/rhoconnect/handler/query/pass_through_runner.rb,
lib/rhoconnect/predefined_adapters/bench_adapter.rb,
lib/rhoconnect/handler/search/pass_through_runner.rb,
lib/rhoconnect/handler/changes/pass_through_runner.rb,
lib/rhoconnect/middleware/body_content_type_parser.rb,
lib/rhoconnect/middleware/x_domain_session_wrapper.rb,
lib/rhoconnect/handler/authenticate/execute_methods.rb,
lib/rhoconnect/controller/dynamic_adapter_controller.rb,
lib/rhoconnect/model/helpers/find_duplicates_on_update.rb,
lib/rhoconnect/handler/plugin_callbacks/execute_methods.rb

Overview

this is the actual pseudo-middleware handler for Create/Update/Delete

Defined Under Namespace

Modules: BulkDataJob, Condition, Controller, EndPoint, Handler, Middleware, Model, PingJob, Synchrony, TestMethods Classes: ApiException, ApiToken, App, Apple, Base, BulkData, Client, Credential, DefaultServer, Gcm, InvalidDocumentException, InvalidSourceNameError, Iphone, License, LicenseException, LicenseSeatsExceededException, LoginException, MemoryOrm, ReadState, RedisImpl, RhoHashWithIndifferentAccess, RhoInternalBenchmarkAdapter, RhoconnectPush, RhoconnectServerError, Server, Source, SourceJob, Stats, Store, StoreLockException, StoreOrm, User

Constant Summary collapse

APP_NAME =
'application'
API_VERSION =
'v1'.freeze
VERSION =
'4.0.1'
SourceAdapter =

to preserve backward compatibility TODO: Remove in 4.1

Rhoconnect::Model::Base
SourceAdapterException =
Rhoconnect::Model::Exception
SourceAdapterLoginException =
Rhoconnect::Model::LoginException
SourceAdapterLogoffException =
Rhoconnect::Model::LogoffException
SourceAdapterServerTimeoutException =
Rhoconnect::Model::ServerTimeoutException
SourceAdapterServerErrorException =
Rhoconnect::Model::ServerErrorException
SourceAdapterObjectConflictErrorException =
Rhoconnect::Model::ObjectConflictErrorException
CURRENT_REQUEST =

Constants

'CURRENT_REQUEST'.freeze
CURRENT_APP =
'CURRENT_APP'.freeze
CURRENT_USER =
'CURRENT_USER'.freeze
CURRENT_SOURCE =
'CURRENT_SOURCE'.freeze
CURRENT_CLIENT =
'CURRENT_CLIENT'.freeze
QUERY_RES =
'QUERY_RES'.freeze
UNKNOWN_CLIENT =
"Unknown client".freeze
UNKNOWN_SOURCE =
"Unknown source".freeze
SYNC_VERSION =

TODO : Remove in Rhoconnect 4.0

3
API_TOKEN_HEADER =

header names, in the form of server’s HTTP variables X-RhoConnect-API-TOKEN

'HTTP_X_RHOCONNECT_API_TOKEN'.freeze
CLIENT_ID_HEADER =

X-RhoConnect-CLIENT-ID

'HTTP_X_RHOCONNECT_CLIENT_ID'.freeze
PAGE_TOKEN_HEADER =

X-RhoConnect-PAGE-TOKEN

'X-Rhoconnect-PAGE-TOKEN'
PAGE_OBJECT_COUNT_HEADER =

X-RhoConnect-PAGE-OBJECT-COUNT

'X-Rhoconnect-PAGE-OBJECT-COUNT'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.api_tokenObject

Returns the value of attribute api_token.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def api_token
  @api_token
end

.app_directoryObject

Returns the value of attribute app_directory.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def app_directory
  @app_directory
end

.appserverObject

Returns the value of attribute appserver.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def appserver
  @appserver
end

.base_directoryObject

Returns the value of attribute base_directory.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def base_directory
  @base_directory
end

.bulk_sync_poll_intervalObject

Returns the value of attribute bulk_sync_poll_interval.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def bulk_sync_poll_interval
  @bulk_sync_poll_interval
end

.connection_pool_sizeObject

Returns the value of attribute connection_pool_size.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def connection_pool_size
  @connection_pool_size
end

.connection_pool_timeoutObject

Returns the value of attribute connection_pool_timeout.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def connection_pool_timeout
  @connection_pool_timeout
end

Returns the value of attribute cookie_expire.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def cookie_expire
  @cookie_expire
end

.data_directoryObject

Returns the value of attribute data_directory.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def data_directory
  @data_directory
end

.disable_rc_consoleObject

Returns the value of attribute disable_rc_console.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def disable_rc_console
  @disable_rc_console
end

.disable_resque_consoleObject

Returns the value of attribute disable_resque_console.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def disable_resque_console
  @disable_resque_console
end

.licenseObject

Returns the value of attribute license.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def license
  @license
end

.lock_durationObject

Returns the value of attribute lock_duration.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def lock_duration
  @lock_duration
end

.log_disabledObject

Returns the value of attribute log_disabled.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def log_disabled
  @log_disabled
end

.predefined_sourcesObject

Returns the value of attribute predefined_sources.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def predefined_sources
  @predefined_sources
end

.raise_on_expired_lockObject

Returns the value of attribute raise_on_expired_lock.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def raise_on_expired_lock
  @raise_on_expired_lock
end

.redisObject

Returns the value of attribute redis.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def redis
  @redis
end

.redis_timeoutObject

Returns the value of attribute redis_timeout.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def redis_timeout
  @redis_timeout
end

.redis_urlObject

Returns the value of attribute redis_url.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def redis_url
  @redis_url
end

.restart_node_on_errorObject

Returns the value of attribute restart_node_on_error.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def restart_node_on_error
  @restart_node_on_error
end

.statsObject

Returns the value of attribute stats.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def stats
  @stats
end

.store_key_ttlObject

Returns the value of attribute store_key_ttl.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def store_key_ttl
  @store_key_ttl
end

.use_nodeObject

Returns the value of attribute use_node.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def use_node
  @use_node
end

.vendor_directoryObject

Returns the value of attribute vendor_directory.



55
56
57
# File 'lib/rhoconnect.rb', line 55

def vendor_directory
  @vendor_directory
end

Class Method Details

.settingsObject



389
390
391
# File 'lib/rhoconnect.rb', line 389

def self.settings
  @@settings ||= get_config(Rhoconnect.base_directory || ROOT_PATH)[Rhoconnect.environment]
end

.shutdownObject



393
394
395
# File 'lib/rhoconnect.rb', line 393

def self.shutdown
  Rhoconnect::Node.kill_process if Rhoconnect::Node.started
end

Instance Method Details

#add_to_url_map(subclass) ⇒ Object

Rhoconnect API version



71
72
73
74
# File 'lib/rhoconnect.rb', line 71

def add_to_url_map(subclass)
  @controllers_map ||= Set.new
  @controllers_map << subclass
end

#appObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/rhoconnect/application/init.rb', line 36

def app
  url_map = Rhoconnect.url_map
  unless Rhoconnect.disable_resque_console
    url_map['/resque'] = Resque::Server.new
  end
  unless Rhoconnect.disable_rc_console
    url_map['/console'] = RhoconnectConsole::Server.new
  end
  return Rack::URLMap.new url_map
end

#bootstrap(basedir) {|_self| ... } ⇒ Object

Begin Rhoconnect setup methods Server hook to initialize Rhoconnect

Yields:

  • (_self)

Yield Parameters:

  • _self (Rhoconnect)

    the object that the method was called on



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/rhoconnect.rb', line 94

def bootstrap(basedir)
  config = get_config(basedir)
  # Initialize Rhoconnect and Resque
  Rhoconnect.base_directory = basedir
  Rhoconnect.app_directory = get_setting(config,environment,:app_directory)
  Rhoconnect.data_directory = get_setting(config,environment,:data_directory)
  Rhoconnect.vendor_directory = get_setting(config,environment,:vendor_directory)
  Rhoconnect.bulk_sync_poll_interval = get_setting(config,environment,:bulk_sync_poll_interval,3600)
  Rhoconnect.redis = get_setting(config,environment,:redis,false)
  Rhoconnect.connection_pool_size ||= get_setting(config,environment,:connection_pool_size,5)
  Rhoconnect.connection_pool_timeout = get_setting(config,environment,:connection_pool_timeout,30)
  Rhoconnect.redis_timeout = get_setting(config,environment,:redis_timeout,30)
  Rhoconnect.api_token = ENV['API_TOKEN'] || get_setting(config,environment,:api_token,false)
  Rhoconnect.log_disabled = get_setting(config,environment,:log_disabled,false)
  Rhoconnect.raise_on_expired_lock = get_setting(config,environment,:raise_on_expired_lock,false)
  Rhoconnect.lock_duration = get_setting(config,environment,:lock_duration)
  Rhoconnect.cookie_expire = get_setting(config,environment,:cookie_expire)  || 31536000
  Rhoconnect.store_key_ttl = get_setting(config, environment, :store_key_ttl) ||  86400
  Rhoconnect.predefined_sources = {}
  yield self if block_given?
  Store.create(Rhoconnect.redis)
  Resque.redis = Rhoconnect.redis.is_a?(Array) ? Rhoconnect.redis[0] : Rhoconnect.redis
  Rhoconnect.base_directory ||= File.join(File.dirname(__FILE__),'..')
  Rhoconnect.app_directory ||= Rhoconnect.base_directory
  Rhoconnect.data_directory ||= File.join(Rhoconnect.base_directory,'data')
  Rhoconnect.vendor_directory ||= File.join(Rhoconnect.base_directory,'vendor')
  Rhoconnect.stats ||= false
  Rhoconnect.license = License.new
  Rhoconnect.disable_rc_console ||= false
  Rhoconnect.disable_resque_console ||= false
  Rhoconnect.use_node = Rhoconnect.use_node.nil? ? true : Rhoconnect.use_node
  Rhoconnect.restart_node_on_error ||= true if Rhoconnect.use_node
  if File.directory?(File.join(Rhoconnect.app_directory,'sources'))
    check_and_add(File.join(Rhoconnect.app_directory,'sources'))
    # post deprecation warning !!!
warning_for_deprecated_sources_dir = <<_MIGRATE_TO_NEW_RHOCONNECT

***** WARNING *****
RhoConnect has detected that you're using deprecated SourceAdapter classes.

SourceAdapter class support will be removed in RhoConnect 4.1.
Please, migrate your SourceAdapter classes into RhoConnect Models.

For more details, see RhoConnect Migration guidelines at
docs.rhomobile.com

_MIGRATE_TO_NEW_RHOCONNECT
    puts warning_for_deprecated_sources_dir
  end

  check_and_add(File.join(Rhoconnect.app_directory,'models','ruby'))
  start_app(config)
  create_admin_user
end

#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object

Taken from rails inflector



316
317
318
319
320
# File 'lib/rhoconnect.rb', line 316

def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  end
end

#check_and_add(path) ⇒ Object

Add path to load_path unless it has been added already



210
211
212
# File 'lib/rhoconnect.rb', line 210

def check_and_add(path)
  $:.unshift path unless $:.include?(path)
end

#check_default_secret!(secret) ⇒ Object



266
267
268
269
270
271
272
273
# File 'lib/rhoconnect.rb', line 266

def check_default_secret!(secret)
  if secret == '<changeme>'
    log "*"*60+"\n\n"
    log "WARNING: Change the session secret in config.ru from <changeme> to something secure."
    log "  i.e. running `rake rhoconnect:secret` in your rhoconnect app directory will generate a secret you could use.\n\n"
    log "*"*60
  end
end

#check_for_schema_field!(fields) ⇒ Object



275
276
277
278
279
280
# File 'lib/rhoconnect.rb', line 275

def check_for_schema_field!(fields)
  if fields['schema']
    log "ERROR: 'schema' field in settings.yml is not supported anymore, please use source adapter schema method!"
    exit(1)
  end
end

#create_admin_userObject

Generate admin user on first load



199
200
201
202
203
204
205
206
207
# File 'lib/rhoconnect.rb', line 199

def create_admin_user
  unless User.is_exist?('rhoadmin')
    admin = User.create({:login => 'rhoadmin', :admin => 1})
    admin.password = ENV['PSWRD'] || ''
    admin.create_token
  end
  admin = User.load('rhoadmin')
  Rhoconnect.api_token = admin.token_id
end

#create_predefined_source(source_name, params) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/rhoconnect.rb', line 253

def create_predefined_source(source_name,params)
  source_data = Rhoconnect.predefined_sources[source_name]
  return unless source_data
  if source_data[:source_loaded] != true
    source_config = Rhoconnect.source_config(source_name)
    source_config[:name] = source_name
    Source.create(source_config,params)
    app = App.load(Rhoconnect::APP_NAME)
    app.sources << source_name
    source_data[:source_loaded] = true
  end
end

#environmentObject



149
150
151
# File 'lib/rhoconnect.rb', line 149

def environment
(ENV['RHO_ENV'] || ENV['RACK_ENV'] || :development).to_sym
end

#expire_bulk_data(username, partition = :user) ⇒ Object



322
323
324
325
326
# File 'lib/rhoconnect.rb', line 322

def expire_bulk_data(username, partition = :user)
  name = BulkData.get_name(partition,username)
  data = BulkData.load(name)
  data.refresh_time = Time.now.to_i if data
end

#get_config(basedir) ⇒ Object



214
215
216
217
218
219
220
221
222
223
# File 'lib/rhoconnect.rb', line 214

def get_config(basedir)
  # Load settings
  settings_file = File.join(basedir,'settings','settings.yml') if basedir
  if settings_file and File.exist?(settings_file)
    YAML.load_file(settings_file)
  else # Otherwise use setting for blank app
    settings_file = File.join(ENV['HOME'], '.rhoconnect.yml')
    YAML.load_file(settings_file) if File.exist?(settings_file)
  end
end

#get_random_identifierObject

Get secure random string



296
297
298
# File 'lib/rhoconnect.rb', line 296

def get_random_identifier
  SecureRandom.hex
end

#get_tokenObject

Generates new token (64-bit integer) based on # of microseconds since Jan 1 2009



302
303
304
# File 'lib/rhoconnect.rb', line 302

def get_token
  ((Time.now.to_f - Time.mktime(2009,"jan",1,0,0,0,0).to_f) * 10**6).to_i
end

#getelement(element) ⇒ Object

De-serializes oav from set element



289
290
291
292
293
# File 'lib/rhoconnect.rb', line 289

def getelement(element)
  res = element.split(':',3)
  #[res[0], res[1], Base64.decode64(res[2].to_s)]
  [res[0], res[1], res[2]]
end

#lap_timer(msg, start) ⇒ Object



361
362
363
364
365
# File 'lib/rhoconnect.rb', line 361

def lap_timer(msg,start)
  duration = timenow - start
  log "#{msg}: #{duration}"
  timenow
end

#log(*args) ⇒ Object



376
377
378
379
# File 'lib/rhoconnect.rb', line 376

def log(*args)
  now = Time.now.strftime('%I:%M:%S.%L %p %Y-%m-%d')
  puts "[#{Process.pid}][#{now}] #{args.join}" unless Rhoconnect.log_disabled
end

#register_predefined_source(source_name) ⇒ Object

End Rhoconnect setup methods



245
246
247
248
249
250
251
# File 'lib/rhoconnect.rb', line 245

def register_predefined_source(source_name)
  return if Rhoconnect.predefined_sources.has_key?(source_name)

  Rhoconnect.predefined_sources[source_name] = {:source_loaded => false}
  # create Sinatra server for the predefined source here
  Rhoconnect::Controller::SourceAdapterBase.register_controller(source_name)
end

#remove_from_url_map(subclass) ⇒ Object



76
77
78
# File 'lib/rhoconnect.rb', line 76

def remove_from_url_map(subclass)
  @controllers_map.delete(subclass) if @controllers_map
end

#setelement(obj, attrib, value) ⇒ Object

Serializes oav to set element



283
284
285
286
# File 'lib/rhoconnect.rb', line 283

def setelement(obj,attrib,value)
  #"#{obj}:#{attrib}:#{Base64.encode64(value.to_s)}"
  "#{obj}:#{attrib}:#{value.to_s}"
end

#source_config(source_name) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/rhoconnect.rb', line 225

def source_config(source_name)
  source_config = {}
  sources = Rhoconnect.get_config(Rhoconnect.base_directory)[:sources]
  source_config = sources[source_name] unless (sources.nil? or sources[source_name].nil?)
  env_config = Rhoconnect.get_config(Rhoconnect.base_directory)[Rhoconnect.environment]
  force_default = source_config[:force_default]
  source_config.delete(:force_default)
  # apply global env settings
  [:poll_interval, :push_notify].each do |setting|
    def_setting = env_config["#{setting.to_s}_default".to_sym]
    def_setting ||= env_config[setting]
    next unless def_setting
    if source_config[setting].nil? or force_default
      source_config[setting] = def_setting
    end
  end
  source_config
end

#start_app(config) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rhoconnect.rb', line 153

def start_app(config)
  app = nil
  app_name = APP_NAME
  if App.is_exist?(app_name)
    app = App.load(app_name)
  else
    app = App.create(:name => app_name)
  end
  # load all pre-defined adapters files
  Dir[File.join(File.dirname(__FILE__),'rhoconnect','predefined_adapters','*.rb')].each { |adapter| load adapter }
  # load all Ruby Controller files
  Dir[File.join(Rhoconnect.app_directory,'controllers','ruby','*.rb')].each { |controller_file| require controller_file }

  # TODO: process sources not only from setting.yml file
  if config and config[Rhoconnect.environment]
    sources = config[:sources] || []
    Source.delete_all
    app.delete_sources
    sources.each do |source_name,fields|
      source_config = source_config(source_name)
      check_for_schema_field!(source_config)
      source_config[:name] = source_name
      Source.create(source_config,{:app_id => app.name})
      app.sources << source_name
      # check if RubyController class already exists
      unless Object.const_defined?("#{source_name}Controller")
        # add to url map
        Rhoconnect::Controller::SourceAdapterBase.register_controller(source_name)
      end

      # load ruby file for source adapter to re-load class
      load under_score(source_name+'.rb')
    end
  end

  start_nodejs_channels if Rhoconnect.use_node
  # Create associations for all sources
  Source.update_associations(app.sources)
end

#start_nodejs_channels(opts = {}) ⇒ Object



193
194
195
196
# File 'lib/rhoconnect.rb', line 193

def start_nodejs_channels(opts = {})
  Node.shell_node(opts)
  NodeChannel.bootstrap if Node.started
end

#start_timer(msg = 'starting') ⇒ Object



367
368
369
370
# File 'lib/rhoconnect.rb', line 367

def start_timer(msg='starting')
  log "#{msg}"
  timenow
end

#timenowObject



372
373
374
# File 'lib/rhoconnect.rb', line 372

def timenow
  (Time.now.to_f * 1000)
end

#under_score(camel_cased_word) ⇒ Object

Returns require-friendly filename for a class



307
308
309
310
311
312
313
# File 'lib/rhoconnect.rb', line 307

def under_score(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end

#unzip_file(file_dir, params) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/rhoconnect.rb', line 328

def unzip_file(file_dir,params)
  uploaded_file = File.join(file_dir, params[:filename])
  begin
    File.open(uploaded_file, 'wb') do |file|
      file.write(params[:tempfile].read)
    end
    Zip::ZipFile.open(uploaded_file) do |zip_file|
      zip_file.each do |f|
        f_path = File.join(file_dir,f.name)
        FileUtils.mkdir_p(File.dirname(f_path))
        zip_file.extract(f, f_path) { true }
      end
    end
  rescue Exception => e
    log "Failed to unzip `#{uploaded_file}`"
    raise e
  ensure
    FileUtils.rm_f(uploaded_file)
  end
end

#url_mapObject



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rhoconnect.rb', line 80

def url_map
  @controllers_map ||= Set.new
  app_url_map = {}
  @controllers_map.each do |klass|
    if klass.respond_to?(:rest_path) and klass.rest_path.size > 0
      app_url_map[klass.rest_path] = klass.new
    end
  end
  app_url_map['/'] = Rhoconnect::DefaultServer.new
  app_url_map
end

#which(command) ⇒ Object



349
350
351
352
353
354
355
356
357
358
359
# File 'lib/rhoconnect.rb', line 349

def which(command)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  paths = ENV['PATH'].split(File::PATH_SEPARATOR)
  paths.each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{command}#{ext}")
      return exe if File.executable? exe
    end
  end
  return nil
end