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.0'
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.



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

def api_token
  @api_token
end

.app_directoryObject

Returns the value of attribute app_directory.



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

def app_directory
  @app_directory
end

.appserverObject

Returns the value of attribute appserver.



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

def appserver
  @appserver
end

.base_directoryObject

Returns the value of attribute base_directory.



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

def base_directory
  @base_directory
end

.bulk_sync_poll_intervalObject

Returns the value of attribute bulk_sync_poll_interval.



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

def bulk_sync_poll_interval
  @bulk_sync_poll_interval
end

.connection_pool_sizeObject

Returns the value of attribute connection_pool_size.



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

def connection_pool_size
  @connection_pool_size
end

.connection_pool_timeoutObject

Returns the value of attribute connection_pool_timeout.



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

def connection_pool_timeout
  @connection_pool_timeout
end

Returns the value of attribute cookie_expire.



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

def cookie_expire
  @cookie_expire
end

.data_directoryObject

Returns the value of attribute data_directory.



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

def data_directory
  @data_directory
end

.disable_rc_consoleObject

Returns the value of attribute disable_rc_console.



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

def disable_rc_console
  @disable_rc_console
end

.disable_resque_consoleObject

Returns the value of attribute disable_resque_console.



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

def disable_resque_console
  @disable_resque_console
end

.licenseObject

Returns the value of attribute license.



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

def license
  @license
end

.lock_durationObject

Returns the value of attribute lock_duration.



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

def lock_duration
  @lock_duration
end

.log_disabledObject

Returns the value of attribute log_disabled.



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

def log_disabled
  @log_disabled
end

.predefined_sourcesObject

Returns the value of attribute predefined_sources.



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

def predefined_sources
  @predefined_sources
end

.raise_on_expired_lockObject

Returns the value of attribute raise_on_expired_lock.



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

def raise_on_expired_lock
  @raise_on_expired_lock
end

.redisObject

Returns the value of attribute redis.



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

def redis
  @redis
end

.redis_timeoutObject

Returns the value of attribute redis_timeout.



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

def redis_timeout
  @redis_timeout
end

.restart_node_on_errorObject

Returns the value of attribute restart_node_on_error.



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

def restart_node_on_error
  @restart_node_on_error
end

.statsObject

Returns the value of attribute stats.



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

def stats
  @stats
end

.store_key_ttlObject

Returns the value of attribute store_key_ttl.



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

def store_key_ttl
  @store_key_ttl
end

.use_nodeObject

Returns the value of attribute use_node.



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

def use_node
  @use_node
end

.vendor_directoryObject

Returns the value of attribute vendor_directory.



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

def vendor_directory
  @vendor_directory
end

Class Method Details

.settingsObject



385
386
387
# File 'lib/rhoconnect.rb', line 385

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

.shutdownObject



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

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

Instance Method Details

#add_to_url_map(subclass) ⇒ Object

Rhoconnect API version



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

def add_to_url_map(subclass)
  @controllers_map ||= Set.new
  #puts " adding to URL map #{subclass.name}"
  @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



90
91
92
93
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
# File 'lib/rhoconnect.rb', line 90

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 = "\n***** WARNING *****\nRhoConnect has detected that you're using deprecated SourceAdapter classes.\n\nSourceAdapter class support will be removed in RhoConnect 4.1.\nPlease, migrate your SourceAdapter classes into RhoConnect Models.\n\nFor more details, see RhoConnect Migration guidelines at\ndocs.rhomobile.com\n\n"
    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



312
313
314
315
316
# File 'lib/rhoconnect.rb', line 312

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



206
207
208
# File 'lib/rhoconnect.rb', line 206

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

#check_default_secret!(secret) ⇒ Object



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

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



271
272
273
274
275
276
# File 'lib/rhoconnect.rb', line 271

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



195
196
197
198
199
200
201
202
203
# File 'lib/rhoconnect.rb', line 195

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



249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/rhoconnect.rb', line 249

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



145
146
147
# File 'lib/rhoconnect.rb', line 145

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

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



318
319
320
321
322
# File 'lib/rhoconnect.rb', line 318

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



210
211
212
213
214
215
216
217
218
219
# File 'lib/rhoconnect.rb', line 210

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_uuidObject

Get random UUID string



292
293
294
# File 'lib/rhoconnect.rb', line 292

def get_random_uuid
  UUIDTools::UUID.random_create.to_s.gsub(/\-/,'')
end

#get_tokenObject

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



298
299
300
# File 'lib/rhoconnect.rb', line 298

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



285
286
287
288
289
# File 'lib/rhoconnect.rb', line 285

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



357
358
359
360
361
# File 'lib/rhoconnect.rb', line 357

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

#log(*args) ⇒ Object



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

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



241
242
243
244
245
246
247
# File 'lib/rhoconnect.rb', line 241

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

#setelement(obj, attrib, value) ⇒ Object

Serializes oav to set element



279
280
281
282
# File 'lib/rhoconnect.rb', line 279

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

#source_config(source_name) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/rhoconnect.rb', line 221

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



149
150
151
152
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
# File 'lib/rhoconnect.rb', line 149

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



189
190
191
192
# File 'lib/rhoconnect.rb', line 189

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

#start_timer(msg = 'starting') ⇒ Object



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

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

#timenowObject



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

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

#under_score(camel_cased_word) ⇒ Object

Returns require-friendly filename for a class



303
304
305
306
307
308
309
# File 'lib/rhoconnect.rb', line 303

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



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/rhoconnect.rb', line 324

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



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rhoconnect.rb', line 76

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



345
346
347
348
349
350
351
352
353
354
355
# File 'lib/rhoconnect.rb', line 345

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