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/version.rb,
lib/rhoconnect/ping/fcm.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, Fcm, Gcm, InvalidDocumentException, InvalidSourceNameError, Iphone, 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 =
'7.5.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
-
.api_token ⇒ Object
Returns the value of attribute api_token.
-
.app_directory ⇒ Object
Returns the value of attribute app_directory.
-
.appserver ⇒ Object
Returns the value of attribute appserver.
-
.base_directory ⇒ Object
Returns the value of attribute base_directory.
-
.bulk_sync_poll_interval ⇒ Object
Returns the value of attribute bulk_sync_poll_interval.
-
.connection_pool_size ⇒ Object
Returns the value of attribute connection_pool_size.
-
.connection_pool_timeout ⇒ Object
Returns the value of attribute connection_pool_timeout.
-
.cookie_expire ⇒ Object
Returns the value of attribute cookie_expire.
-
.data_directory ⇒ Object
Returns the value of attribute data_directory.
-
.disable_rc_console ⇒ Object
Returns the value of attribute disable_rc_console.
-
.disable_resque_console ⇒ Object
Returns the value of attribute disable_resque_console.
-
.lock_duration ⇒ Object
Returns the value of attribute lock_duration.
-
.log_disabled ⇒ Object
Returns the value of attribute log_disabled.
-
.node_channel_timeout ⇒ Object
Returns the value of attribute node_channel_timeout.
-
.predefined_sources ⇒ Object
Returns the value of attribute predefined_sources.
-
.raise_on_expired_lock ⇒ Object
Returns the value of attribute raise_on_expired_lock.
-
.redis ⇒ Object
Returns the value of attribute redis.
-
.redis_timeout ⇒ Object
Returns the value of attribute redis_timeout.
-
.redis_url ⇒ Object
Returns the value of attribute redis_url.
-
.restart_node_on_error ⇒ Object
Returns the value of attribute restart_node_on_error.
-
.stats ⇒ Object
Returns the value of attribute stats.
-
.store_key_ttl ⇒ Object
Returns the value of attribute store_key_ttl.
-
.use_node ⇒ Object
Returns the value of attribute use_node.
-
.vendor_directory ⇒ Object
Returns the value of attribute vendor_directory.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_to_url_map(subclass) ⇒ Object
Rhoconnect API version.
- #app ⇒ Object
-
#bootstrap(basedir) {|_self| ... } ⇒ Object
Begin Rhoconnect setup methods Server hook to initialize Rhoconnect.
-
#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object
Taken from rails inflector.
-
#check_and_add(path) ⇒ Object
Add path to load_path unless it has been added already.
- #check_default_secret!(secret) ⇒ Object
- #check_for_schema_field!(fields) ⇒ Object
-
#create_admin_user ⇒ Object
Generate admin user on first load.
- #create_predefined_source(source_name, params) ⇒ Object
- #environment ⇒ Object
- #expire_bulk_data(username, partition = :user) ⇒ Object
- #get_config(basedir) ⇒ Object
-
#get_random_identifier ⇒ Object
Get secure random string.
-
#get_token ⇒ Object
Generates new token (64-bit integer) based on # of microseconds since Jan 1 2009.
-
#getelement(element) ⇒ Object
De-serializes oav from set element.
- #lap_timer(msg, start) ⇒ Object
- #log(*args) ⇒ Object
-
#register_predefined_source(source_name) ⇒ Object
End Rhoconnect setup methods.
- #remove_from_url_map(subclass) ⇒ Object
-
#setelement(obj, attrib, value) ⇒ Object
Serializes oav to set element.
- #source_config(source_name) ⇒ Object
- #start_app(config) ⇒ Object
- #start_nodejs_channels(opts = {}) ⇒ Object
- #start_timer(msg = 'starting') ⇒ Object
- #timenow ⇒ Object
-
#under_score(camel_cased_word) ⇒ Object
Returns require-friendly filename for a class.
- #unzip_file(file_dir, params) ⇒ Object
- #url_map ⇒ Object
- #which(command) ⇒ Object
Class Attribute Details
.api_token ⇒ Object
Returns the value of attribute api_token.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def api_token @api_token end |
.app_directory ⇒ Object
Returns the value of attribute app_directory.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def app_directory @app_directory end |
.appserver ⇒ Object
Returns the value of attribute appserver.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def appserver @appserver end |
.base_directory ⇒ Object
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_interval ⇒ Object
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_size ⇒ Object
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_timeout ⇒ Object
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 |
.cookie_expire ⇒ Object
Returns the value of attribute cookie_expire.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def @cookie_expire end |
.data_directory ⇒ Object
Returns the value of attribute data_directory.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def data_directory @data_directory end |
.disable_rc_console ⇒ Object
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_console ⇒ Object
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 |
.lock_duration ⇒ Object
Returns the value of attribute lock_duration.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def lock_duration @lock_duration end |
.log_disabled ⇒ Object
Returns the value of attribute log_disabled.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def log_disabled @log_disabled end |
.node_channel_timeout ⇒ Object
Returns the value of attribute node_channel_timeout.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def node_channel_timeout @node_channel_timeout end |
.predefined_sources ⇒ Object
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_lock ⇒ Object
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 |
.redis ⇒ Object
Returns the value of attribute redis.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def redis @redis end |
.redis_timeout ⇒ Object
Returns the value of attribute redis_timeout.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def redis_timeout @redis_timeout end |
.redis_url ⇒ Object
Returns the value of attribute redis_url.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def redis_url @redis_url end |
.restart_node_on_error ⇒ Object
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 |
.stats ⇒ Object
Returns the value of attribute stats.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def stats @stats end |
.store_key_ttl ⇒ Object
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_node ⇒ Object
Returns the value of attribute use_node.
54 55 56 |
# File 'lib/rhoconnect.rb', line 54 def use_node @use_node end |
.vendor_directory ⇒ Object
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
.settings ⇒ Object
390 391 392 |
# File 'lib/rhoconnect.rb', line 390 def self.settings @@settings ||= get_config(Rhoconnect.base_directory || ROOT_PATH)[Rhoconnect.environment] end |
.shutdown ⇒ Object
394 395 396 |
# File 'lib/rhoconnect.rb', line 394 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 |
#app ⇒ Object
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
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. = 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.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 Rhoconnect.node_channel_timeout = get_setting(config, environment, :node_channel_timeout, 30) 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
317 318 319 320 321 |
# File 'lib/rhoconnect.rb', line 317 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
211 212 213 |
# File 'lib/rhoconnect.rb', line 211 def check_and_add(path) $:.unshift path unless $:.include?(path) end |
#check_default_secret!(secret) ⇒ Object
267 268 269 270 271 272 273 274 |
# File 'lib/rhoconnect.rb', line 267 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
276 277 278 279 280 281 |
# File 'lib/rhoconnect.rb', line 276 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_user ⇒ Object
Generate admin user on first load
200 201 202 203 204 205 206 207 208 |
# File 'lib/rhoconnect.rb', line 200 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
254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/rhoconnect.rb', line 254 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 |
#environment ⇒ Object
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
323 324 325 326 327 |
# File 'lib/rhoconnect.rb', line 323 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
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/rhoconnect.rb', line 215 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_identifier ⇒ Object
Get secure random string
297 298 299 |
# File 'lib/rhoconnect.rb', line 297 def get_random_identifier SecureRandom.hex end |
#get_token ⇒ Object
Generates new token (64-bit integer) based on # of microseconds since Jan 1 2009
303 304 305 |
# File 'lib/rhoconnect.rb', line 303 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
290 291 292 293 294 |
# File 'lib/rhoconnect.rb', line 290 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
362 363 364 365 366 |
# File 'lib/rhoconnect.rb', line 362 def lap_timer(msg,start) duration = timenow - start log "#{msg}: #{duration}" timenow end |
#log(*args) ⇒ Object
377 378 379 380 |
# File 'lib/rhoconnect.rb', line 377 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
246 247 248 249 250 251 252 |
# File 'lib/rhoconnect.rb', line 246 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
284 285 286 287 |
# File 'lib/rhoconnect.rb', line 284 def setelement(obj,attrib,value) #"#{obj}:#{attrib}:#{Base64.encode64(value.to_s)}" "#{obj}:#{attrib}:#{value.to_s}" end |
#source_config(source_name) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/rhoconnect.rb', line 226 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 192 |
# 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 & Model files Dir[File.join(Rhoconnect.app_directory,'controllers','ruby','*.rb')].each { |controller_file| require controller_file } Dir[File.join(Rhoconnect.app_directory,'{sources,models}','**','*.rb')].each do |adapter_file| base_file = File.basename(adapter_file, '.*') klazz = camelize(base_file) require adapter_file unless Object.const_defined?("#{klazz}Controller") # add to url map Rhoconnect::Controller::SourceAdapterBase.register_controller(klazz) end end # 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 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
194 195 196 197 |
# File 'lib/rhoconnect.rb', line 194 def start_nodejs_channels(opts = {}) Node.shell_node(opts) NodeChannel.bootstrap(Rhoconnect.node_channel_timeout) if Node.started end |
#start_timer(msg = 'starting') ⇒ Object
368 369 370 371 |
# File 'lib/rhoconnect.rb', line 368 def start_timer(msg='starting') log "#{msg}" timenow end |
#timenow ⇒ Object
373 374 375 |
# File 'lib/rhoconnect.rb', line 373 def timenow (Time.now.to_f * 1000) end |
#under_score(camel_cased_word) ⇒ Object
Returns require-friendly filename for a class
308 309 310 311 312 313 314 |
# File 'lib/rhoconnect.rb', line 308 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
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/rhoconnect.rb', line 329 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::File.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_map ⇒ Object
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
350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/rhoconnect.rb', line 350 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 |