rhoconnect 3.4.5 → 4.0.0.beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. data/CHANGELOG.md +57 -3
  2. data/Gemfile +9 -7
  3. data/Gemfile.lock +37 -37
  4. data/Rakefile +18 -7
  5. data/bench/benchapp/Gemfile +1 -1
  6. data/bench/benchapp/config.ru +0 -3
  7. data/bench/benchapp/controllers/ruby/application.rb +17 -0
  8. data/bench/benchapp/controllers/ruby/application_controller.rb +17 -0
  9. data/bench/benchapp/controllers/ruby/mock_adapter_controller.rb +8 -0
  10. data/bench/benchapp/controllers/ruby/queue_mock_adapter_controller.rb +8 -0
  11. data/bench/benchapp/{sources → models/ruby}/mock_adapter.rb +1 -1
  12. data/bench/benchapp/{sources → models/ruby}/queue_mock_adapter.rb +0 -0
  13. data/bench/benchapp/spec/{sources → models/ruby}/mock_adapter_spec.rb +1 -1
  14. data/bench/benchapp/spec/{sources → models/ruby}/queue_mock_adapter_spec.rb +1 -1
  15. data/bench/benchapp/spec/spec_helper.rb +2 -2
  16. data/bench/blobapp/Gemfile +1 -1
  17. data/bench/blobapp/config.ru +0 -3
  18. data/bench/blobapp/controllers/ruby/application_controller.rb +17 -0
  19. data/bench/blobapp/controllers/ruby/blob_adapter_controller.rb +8 -0
  20. data/bench/blobapp/{sources → models/ruby}/blob_adapter.rb +9 -2
  21. data/bench/blobapp/spec/{sources → models/ruby}/blob_adapter_spec.rb +1 -1
  22. data/bench/blobapp/spec/spec_helper.rb +1 -1
  23. data/bench/lib/bench/cli.rb +1 -1
  24. data/bench/scripts/blob_cud_script.rb +1 -1
  25. data/bench/scripts/query_md_script.rb +1 -1
  26. data/bench/scripts/query_only_script.rb +1 -1
  27. data/bench/scripts/query_script.rb +1 -1
  28. data/bench/scripts/test_query_script.rb +7 -1
  29. data/bench/spec/mock_adapter_spec.rb +1 -1
  30. data/bench/spec/result_spec.rb +3 -3
  31. data/bin/rhoconnect +5 -3
  32. data/commands/dtach/dtach_install.rb +2 -2
  33. data/commands/execute.rb +8 -3
  34. data/commands/generators/app.rb +3 -3
  35. data/commands/generators/controller.rb +6 -0
  36. data/commands/generators/model.rb +6 -0
  37. data/commands/generators/source.rb +3 -3
  38. data/commands/generators/update.rb +1 -1
  39. data/commands/redis/redis_about.rb +2 -2
  40. data/commands/redis/redis_download.rb +1 -1
  41. data/commands/redis/redis_install.rb +4 -3
  42. data/commands/redis/redis_restart.rb +4 -4
  43. data/commands/redis/redis_start.rb +5 -4
  44. data/commands/redis/redis_startbg.rb +5 -4
  45. data/commands/redis/redis_status.rb +13 -0
  46. data/commands/redis/redis_stop.rb +3 -3
  47. data/commands/rhoconnect/config.rb +28 -16
  48. data/commands/rhoconnect/flushdb.rb +1 -2
  49. data/commands/rhoconnect/get_token.rb +15 -11
  50. data/commands/rhoconnect/restart.rb +13 -5
  51. data/commands/rhoconnect/set_admin_password.rb +8 -8
  52. data/commands/rhoconnect/start.rb +74 -16
  53. data/commands/rhoconnect/startbg.rb +1 -1
  54. data/commands/rhoconnect/startdebug.rb +1 -1
  55. data/commands/rhoconnect/stop.rb +13 -1
  56. data/commands/rhoconnect/web.rb +5 -5
  57. data/commands/rhoconnect_console/console.rb +7 -5
  58. data/commands/{rhoconnect → rhoconnect_spec}/spec.rb +0 -0
  59. data/commands/rhoconnect_war/war.rb +9 -9
  60. data/commands/utilities/blank_app.ru +56 -0
  61. data/commands/utilities/redis_runner.rb +54 -19
  62. data/doc/authentication.txt +80 -6
  63. data/doc/blob-sync.txt +104 -97
  64. data/doc/bulk-sync.txt +1 -1
  65. data/doc/client-java.txt +3 -3
  66. data/doc/client-objc.txt +2 -2
  67. data/doc/client.txt +4 -4
  68. data/doc/command-line.txt +105 -200
  69. data/doc/data-partitioning.txt +40 -0
  70. data/doc/deploying.txt +249 -77
  71. data/doc/extending-rhoconnect-server.txt +40 -57
  72. data/doc/heroku-addon.txt +2 -0
  73. data/doc/install.txt +45 -95
  74. data/doc/introduction.txt +1 -1
  75. data/doc/java-plugin.txt +365 -190
  76. data/doc/metadata.txt +1 -1
  77. data/doc/migration.txt +108 -142
  78. data/doc/preparing-production.txt +1 -1
  79. data/doc/push-backend-setup.txt +2 -0
  80. data/doc/push-client-setup-android.txt +78 -0
  81. data/doc/push-client-setup-bb.txt +81 -0
  82. data/doc/push-client-setup-ios.txt +70 -0
  83. data/doc/push-client-setup-rps.txt +200 -0
  84. data/doc/push-client-setup.txt +63 -66
  85. data/doc/push-server-setup.txt +67 -40
  86. data/doc/push-testing.txt +29 -0
  87. data/doc/push.txt +21 -6
  88. data/doc/rest-api.txt +128 -55
  89. data/doc/rhoconnect-redis-stack.txt +120 -0
  90. data/doc/settings.txt +4 -12
  91. data/doc/source-adapters-intro.txt +28 -0
  92. data/doc/source-adapters.txt +235 -272
  93. data/doc/stats-middleware.txt +9 -29
  94. data/doc/supported-platforms.txt +21 -30
  95. data/doc/testing.txt +40 -42
  96. data/doc/tutorial.txt +72 -57
  97. data/examples/simple/Gemfile +1 -1
  98. data/examples/simple/application.rb +4 -5
  99. data/examples/simple/my_server.rb +2 -2
  100. data/examples/simple/settings/settings.yml +1 -1
  101. data/generators/rhoconnect.rb +151 -50
  102. data/generators/templates/application/Gemfile +1 -1
  103. data/generators/templates/application/Rakefile +3 -3
  104. data/generators/templates/application/config.ru +1 -4
  105. data/generators/templates/application/controllers/application_controller.rb +17 -0
  106. data/generators/templates/application/controllers/js/application_controller.js +14 -0
  107. data/generators/templates/application/controllers/ruby/application_controller.rb +17 -0
  108. data/generators/templates/application/package.json +8 -0
  109. data/generators/templates/application/rcgemfile +2 -5
  110. data/generators/templates/application/settings/settings.yml +3 -3
  111. data/generators/templates/application/spec/application_controller_spec.rb +23 -0
  112. data/generators/templates/application/spec/js_spec.rb +25 -0
  113. data/generators/templates/application/spec/spec_helper.rb +21 -7
  114. data/generators/templates/source/controllers/js/controller.js +7 -0
  115. data/generators/templates/source/controllers/ruby/controller.rb +8 -0
  116. data/generators/templates/source/controllers/ruby/controller_spec.rb +27 -0
  117. data/generators/templates/source/models/js/model.js +46 -0
  118. data/generators/templates/source/{source_adapter.rb → models/ruby/model.rb} +15 -10
  119. data/generators/templates/source/{source_spec.rb → models/ruby/model_spec.rb} +1 -1
  120. data/install.sh +5 -5
  121. data/installer/unix-like/create_texts.rb +2 -2
  122. data/installer/unix-like/rho_connect_install_constants.rb +2 -2
  123. data/installer/unix-like/rho_connect_install_utilities.rb +1 -1
  124. data/installer/utils/constants.rb +4 -4
  125. data/js-adapters/ballroom.js +216 -0
  126. data/js-adapters/node.rb +52 -0
  127. data/js-adapters/node_channel.rb +181 -0
  128. data/js-adapters/request.js +27 -0
  129. data/js-adapters/response.js +57 -0
  130. data/js-adapters/rhoconnect_helpers.js +60 -0
  131. data/js-adapters/router.js +60 -0
  132. data/js-adapters/server.js +5 -0
  133. data/lib/rhoconnect/api/app/ans_login.rb +3 -3
  134. data/lib/rhoconnect/api/app/bulk_data.rb +10 -10
  135. data/lib/rhoconnect/api/app/fast_delete.rb +11 -10
  136. data/lib/rhoconnect/api/app/fast_insert.rb +11 -10
  137. data/lib/rhoconnect/api/app/fast_update.rb +11 -10
  138. data/lib/rhoconnect/api/app/login.rb +5 -5
  139. data/lib/rhoconnect/api/app/push_deletes.rb +12 -11
  140. data/lib/rhoconnect/api/app/push_objects.rb +12 -11
  141. data/lib/rhoconnect/api/app/query.rb +8 -7
  142. data/lib/rhoconnect/api/app/queue_updates.rb +98 -94
  143. data/lib/rhoconnect/api/app/search.rb +8 -7
  144. data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -5
  145. data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -8
  146. data/lib/rhoconnect/api/client/create.rb +7 -7
  147. data/lib/rhoconnect/api/client/get_client_params.rb +4 -4
  148. data/lib/rhoconnect/api/client/list_client_docs.rb +17 -17
  149. data/lib/rhoconnect/api/client/register.rb +12 -12
  150. data/lib/rhoconnect/api/client/reset.rb +5 -5
  151. data/lib/rhoconnect/api/readstate/set_refresh_time.rb +9 -9
  152. data/lib/rhoconnect/api/source/get_source_params.rb +4 -4
  153. data/lib/rhoconnect/api/source/list_sources.rb +16 -16
  154. data/lib/rhoconnect/api/source/update_source_params.rb +6 -6
  155. data/lib/rhoconnect/api/store/get_db_doc.rb +4 -4
  156. data/lib/rhoconnect/api/store/set_db_doc.rb +7 -7
  157. data/lib/rhoconnect/api/system/get_adapter.rb +4 -4
  158. data/lib/rhoconnect/api/system/get_license_info.rb +8 -8
  159. data/lib/rhoconnect/api/system/login.rb +15 -15
  160. data/lib/rhoconnect/api/system/reset.rb +11 -11
  161. data/lib/rhoconnect/api/system/save_adapter.rb +4 -4
  162. data/lib/rhoconnect/api/system/stats.rb +22 -22
  163. data/lib/rhoconnect/api/user/create_user.rb +7 -7
  164. data/lib/rhoconnect/api/user/delete_client.rb +6 -6
  165. data/lib/rhoconnect/api/user/delete_user.rb +11 -10
  166. data/lib/rhoconnect/api/user/list_clients.rb +4 -4
  167. data/lib/rhoconnect/api/user/list_source_docs.rb +10 -10
  168. data/lib/rhoconnect/api/user/list_users.rb +3 -3
  169. data/lib/rhoconnect/api/user/ping.rb +3 -3
  170. data/lib/rhoconnect/api/user/show_user.rb +3 -3
  171. data/lib/rhoconnect/api/user/update_user.rb +5 -5
  172. data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -5
  173. data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -10
  174. data/lib/rhoconnect/api_token.rb +5 -6
  175. data/lib/rhoconnect/app.rb +6 -46
  176. data/lib/rhoconnect/application/init.rb +5 -2
  177. data/lib/rhoconnect/async.rb +76 -39
  178. data/lib/rhoconnect/bulk_data/bulk_data.rb +6 -4
  179. data/lib/rhoconnect/client.rb +59 -9
  180. data/lib/rhoconnect/condition/admin_required.rb +27 -0
  181. data/lib/rhoconnect/condition/client_required.rb +50 -0
  182. data/lib/rhoconnect/condition/login_required.rb +22 -0
  183. data/lib/rhoconnect/condition/source_required.rb +49 -0
  184. data/lib/rhoconnect/condition/verbs.rb +17 -0
  185. data/lib/rhoconnect/condition/verify_success.rb +19 -0
  186. data/lib/rhoconnect/controller/app_base.rb +74 -0
  187. data/lib/rhoconnect/controller/base.rb +68 -0
  188. data/lib/rhoconnect/controller/clients_controller.rb +79 -0
  189. data/lib/rhoconnect/controller/dynamic_adapter_controller.rb +93 -0
  190. data/lib/rhoconnect/controller/js_base.rb +124 -0
  191. data/lib/rhoconnect/controller/read_state_controller.rb +22 -0
  192. data/lib/rhoconnect/controller/source_adapter_base.rb +14 -0
  193. data/lib/rhoconnect/controller/sources_controller.rb +44 -0
  194. data/lib/rhoconnect/controller/store_controller.rb +25 -0
  195. data/lib/rhoconnect/controller/system_controller.rb +67 -0
  196. data/lib/rhoconnect/controller/users_controller.rb +99 -0
  197. data/lib/rhoconnect/db_adapter.rb +1 -3
  198. data/lib/rhoconnect/document.rb +159 -50
  199. data/lib/rhoconnect/handler/authenticate/execute_methods.rb +77 -0
  200. data/lib/rhoconnect/handler/authenticate/runner.rb +49 -0
  201. data/lib/rhoconnect/handler/authenticate.rb +3 -0
  202. data/lib/rhoconnect/handler/bulk_data.rb +28 -0
  203. data/lib/rhoconnect/handler/changes/engine.rb +271 -0
  204. data/lib/rhoconnect/handler/changes/execute_methods.rb +88 -0
  205. data/lib/rhoconnect/handler/changes/pass_through_runner.rb +11 -0
  206. data/lib/rhoconnect/handler/changes/runner.rb +53 -0
  207. data/lib/rhoconnect/handler/changes.rb +31 -0
  208. data/lib/rhoconnect/handler/helpers/auth_method.rb +29 -0
  209. data/lib/rhoconnect/handler/helpers/binding.rb +18 -0
  210. data/lib/rhoconnect/handler/helpers/bulk_data.rb +53 -0
  211. data/lib/rhoconnect/handler/helpers/source_job.rb +14 -0
  212. data/lib/rhoconnect/handler/helpers.rb +4 -0
  213. data/lib/rhoconnect/handler/plugin_callbacks/execute_methods.rb +99 -0
  214. data/lib/rhoconnect/handler/plugin_callbacks/runner.rb +28 -0
  215. data/lib/rhoconnect/handler/plugin_callbacks.rb +67 -0
  216. data/lib/rhoconnect/handler/query/engine.rb +93 -0
  217. data/lib/rhoconnect/handler/query/execute_methods.rb +21 -0
  218. data/lib/rhoconnect/handler/query/pass_through_runner.rb +35 -0
  219. data/lib/rhoconnect/handler/query/runner.rb +270 -0
  220. data/lib/rhoconnect/handler/query.rb +19 -0
  221. data/lib/rhoconnect/handler/search/engine.rb +60 -0
  222. data/lib/rhoconnect/handler/search/execute_methods.rb +32 -0
  223. data/lib/rhoconnect/handler/search/pass_through_runner.rb +18 -0
  224. data/lib/rhoconnect/handler/search/runner.rb +104 -0
  225. data/lib/rhoconnect/handler/search.rb +26 -0
  226. data/lib/rhoconnect/handler/sync.rb +29 -0
  227. data/lib/rhoconnect/jobs/source_job.rb +13 -4
  228. data/lib/rhoconnect/js_adapter.rb +79 -0
  229. data/lib/rhoconnect/license.rb +10 -2
  230. data/lib/rhoconnect/middleware/current_user.rb +14 -1
  231. data/lib/rhoconnect/middleware/helpers.rb +10 -93
  232. data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +1 -1
  233. data/lib/rhoconnect/model/base.rb +229 -0
  234. data/lib/rhoconnect/model/dynamic_adapter_model.rb +90 -0
  235. data/lib/rhoconnect/model/js_base.rb +121 -0
  236. data/lib/rhoconnect/ping/android.rb +1 -1
  237. data/lib/rhoconnect/predefined_adapters/bench_adapter.rb +7 -4
  238. data/lib/rhoconnect/read_state.rb +3 -3
  239. data/lib/rhoconnect/server.rb +159 -190
  240. data/lib/rhoconnect/source.rb +100 -11
  241. data/lib/rhoconnect/stats/record.rb +10 -10
  242. data/lib/rhoconnect/store.rb +905 -591
  243. data/lib/rhoconnect/{model.rb → store_orm.rb} +53 -115
  244. data/lib/rhoconnect/tasks.rb +18 -4
  245. data/lib/rhoconnect/test_methods.rb +30 -17
  246. data/lib/rhoconnect/user.rb +35 -17
  247. data/lib/rhoconnect/utilities.rb +1 -1
  248. data/lib/rhoconnect/version.rb +2 -2
  249. data/lib/rhoconnect/web-console/server.rb +29 -14
  250. data/lib/rhoconnect/web-console/views/home.js +10 -10
  251. data/lib/rhoconnect/web-console/views/new_ping.js +1 -1
  252. data/lib/rhoconnect.rb +120 -51
  253. data/rhoconnect.gemspec +4 -3
  254. data/spec/api/api_helper.rb +1 -6
  255. data/spec/api/app/fast_delete_spec.rb +4 -4
  256. data/spec/api/app/fast_insert_spec.rb +4 -4
  257. data/spec/api/app/fast_update_spec.rb +8 -8
  258. data/spec/api/app/push_deletes_spec.rb +2 -2
  259. data/spec/api/app/push_objects_spec.rb +5 -5
  260. data/spec/api/client/client_get_db_doc_spec.rb +6 -4
  261. data/spec/api/client/client_set_db_doc_spec.rb +3 -2
  262. data/spec/api/client/get_client_params_spec.rb +14 -0
  263. data/spec/api/client/list_client_docs_spec.rb +30 -20
  264. data/spec/api/client/reset_spec.rb +36 -0
  265. data/spec/api/source/get_source_params_spec.rb +23 -17
  266. data/spec/api/system/get_license_info_spec.rb +0 -20
  267. data/spec/api/system/login_spec.rb +8 -0
  268. data/spec/api/system/reset_spec.rb +0 -1
  269. data/spec/api/system/stats_spec.rb +5 -5
  270. data/spec/api/user/create_user_spec.rb +14 -6
  271. data/spec/api/user/delete_user_spec.rb +20 -18
  272. data/spec/api/user/list_users_spec.rb +5 -6
  273. data/spec/api/user/update_user_spec.rb +5 -4
  274. data/spec/apps/rhotestapp/config.ru +16 -1
  275. data/spec/apps/rhotestapp/controllers/js/js_sample_controller.js +23 -0
  276. data/spec/apps/rhotestapp/controllers/js/sample2_controller.js +32 -0
  277. data/spec/apps/rhotestapp/controllers/ruby/application_controller.rb +21 -0
  278. data/spec/apps/rhotestapp/controllers/ruby/sample_adapter_controller.rb +8 -0
  279. data/spec/apps/rhotestapp/models/js/js_sample.js +55 -0
  280. data/spec/apps/rhotestapp/models/js/sample2.js +25 -0
  281. data/spec/apps/rhotestapp/{sources → models/ruby}/base_adapter.rb +0 -0
  282. data/spec/apps/rhotestapp/{sources → models/ruby}/fixed_schema_adapter.rb +0 -0
  283. data/spec/apps/rhotestapp/{sources → models/ruby}/other_adapter.rb +0 -0
  284. data/spec/apps/rhotestapp/{sources → models/ruby}/sample_adapter.rb +0 -0
  285. data/spec/apps/rhotestapp/{sources → models/ruby}/simple_adapter.rb +2 -2
  286. data/spec/apps/rhotestapp/{sources → models/ruby}/sub_adapter.rb +0 -0
  287. data/spec/apps/rhotestapp/settings/settings.yml +0 -1
  288. data/spec/bulk_data/bulk_data_spec.rb +20 -5
  289. data/spec/cli/cli_spec.rb +83 -0
  290. data/spec/client_spec.rb +20 -17
  291. data/spec/client_sync_spec.rb +244 -406
  292. data/spec/controllers/js_base_spec.rb +89 -0
  293. data/spec/doc/doc_spec.rb +18 -18
  294. data/spec/document_spec.rb +29 -13
  295. data/spec/dynamic_adapter_spec.rb +6 -6
  296. data/spec/generator/generator_spec.rb +7 -4
  297. data/spec/jobs/bulk_data_job_spec.rb +14 -10
  298. data/spec/jobs/source_job_spec.rb +8 -8
  299. data/spec/license_spec.rb +5 -2
  300. data/spec/models/js_model_spec.rb +39 -0
  301. data/spec/node_spec.rb +42 -0
  302. data/spec/perf/store_perf_spec.rb +67 -12
  303. data/spec/ping/android_spec.rb +1 -1
  304. data/spec/read_state_spec.rb +1 -1
  305. data/spec/rhoconnect_spec.rb +1 -1
  306. data/spec/server/cors_spec.rb +14 -18
  307. data/spec/server/server_spec.rb +265 -88
  308. data/spec/server/stats_spec.rb +1 -1
  309. data/spec/source_adapter_spec.rb +54 -27
  310. data/spec/source_spec.rb +8 -3
  311. data/spec/source_sync_spec.rb +538 -468
  312. data/spec/spec_helper.rb +35 -4
  313. data/spec/stats/record_spec.rb +10 -10
  314. data/spec/{model_spec.rb → store_orm_spec.rb} +56 -54
  315. data/spec/store_spec.rb +159 -179
  316. data/spec/support/shared_examples.rb +36 -27
  317. data/spec/sync_states_spec.rb +40 -33
  318. data/spec/test_methods_spec.rb +18 -14
  319. data/spec/user_spec.rb +17 -30
  320. metadata +156 -52
  321. data/bench/benchapp/application.rb +0 -39
  322. data/bench/blobapp/application.rb +0 -44
  323. data/commands/rhoconnect/clean_start.rb +0 -9
  324. data/commands/rhoconnect/create_user.rb +0 -18
  325. data/commands/rhoconnect/delete_device.rb +0 -9
  326. data/commands/rhoconnect/delete_user.rb +0 -8
  327. data/commands/rhoconnect/reset.rb +0 -16
  328. data/commands/rhoconnect/reset_refresh.rb +0 -11
  329. data/generators/templates/application/application.rb +0 -43
  330. data/lib/rhoconnect/client_sync.rb +0 -434
  331. data/lib/rhoconnect/dynamic_adapter.rb +0 -91
  332. data/lib/rhoconnect/middleware/admin_user.rb +0 -23
  333. data/lib/rhoconnect/middleware/current_request.rb +0 -16
  334. data/lib/rhoconnect/middleware/login_required.rb +0 -22
  335. data/lib/rhoconnect/source_adapter.rb +0 -132
  336. data/lib/rhoconnect/source_sync.rb +0 -464
  337. data/spec/apps/rhotestapp/application.rb +0 -23
@@ -4,96 +4,111 @@ require 'templater'
4
4
  module Rhoconnect
5
5
  extend Templater::Manifold
6
6
  extend Rhoconnect
7
-
7
+
8
8
  desc <<-DESC
9
9
  Rhoconnect generator
10
10
  DESC
11
-
11
+
12
12
  class BaseGenerator < Templater::Generator
13
13
  def class_name
14
14
  name.gsub('-', '_').camel_case
15
15
  end
16
-
16
+
17
17
  def underscore_name
18
18
  Rhoconnect.under_score(name)
19
19
  end
20
20
 
21
21
  def gem_version
22
22
  VERSION
23
- end
24
-
23
+ end
24
+
25
+ # Callback method to run ERB on destination file
26
+ def run_erb(action)
27
+ template = ERB.new(File.read(action.destination))
28
+ File.open(action.destination, "w") { |f| f << template.result(binding) }
29
+ end
30
+
31
+ def self.install_js_option(klass)
32
+ klass.option :js, :required => false, :default => false, :desc => "generate JavaScript code", :as => :boolean
33
+ end
34
+
35
+ def self.install_app_options(klass)
36
+ klass.first_argument :name, :required => true, :desc => "application name"
37
+ install_js_option(klass)
38
+ end
39
+
40
+ def self.install_source_options(klass)
41
+ klass.first_argument :name, :required => true, :desc => "source name"
42
+ install_js_option(klass)
43
+ end
44
+
25
45
  alias_method :module_name, :class_name
26
46
  end
27
-
47
+
28
48
  class AppGenerator < BaseGenerator
49
+ install_app_options(self)
50
+
29
51
  def self.source_root
30
52
  File.join(File.dirname(__FILE__), 'templates', 'application')
31
53
  end
32
-
54
+
33
55
  desc <<-DESC
34
56
  Generates a new rhoconnect application.
35
-
57
+
36
58
  Required:
37
59
  name - application name
38
60
  DESC
39
-
40
- first_argument :name, :required => true, :desc => "application name"
41
-
42
- template :configru do |template|
61
+
62
+ # 'template' does not work under jruby. Using 'file' and after hook instead
63
+ file :configru, :after => :run_erb do |template|
43
64
  require 'securerandom' rescue nil
44
65
  @secret = SecureRandom.hex(64) rescue '<changeme>'
45
66
  template.source = 'config.ru'
46
67
  template.destination = "#{name}/config.ru"
47
- end
48
-
68
+ end
69
+
49
70
  template :gitignore do |template|
50
71
  template.source = 'gitignore'
51
72
  template.destination = "#{name}/.gitignore"
52
73
  end
53
-
74
+
54
75
  template :settings do |template|
55
76
  template.source = 'settings/settings.yml'
56
77
  template.destination = "#{name}/settings/settings.yml"
57
78
  end
58
-
79
+
59
80
  template :license do |template|
60
81
  template.source = 'settings/license.key'
61
82
  template.destination = "#{name}/settings/license.key"
62
83
  end
63
-
64
- template :application do |template|
65
- template.source = 'application.rb'
66
- template.destination = "#{name}/application.rb"
67
- end
68
-
84
+
69
85
  template :rakefile do |template|
70
86
  template.source = 'Rakefile'
71
87
  template.destination = "#{name}/Rakefile"
72
88
  end
73
-
74
- template :gemfile do |template|
75
- template.source = 'Gemfile'
76
- template.destination = "#{name}/Gemfile"
89
+
90
+ # 'template' does not work under jruby. Using 'file' and after hook instead
91
+ file :gemfile, :after => :run_erb do |file|
92
+ file.source = 'Gemfile'
93
+ file.destination = "#{name}/Gemfile"
77
94
  end
78
-
95
+
79
96
  template :gemfile_app do |template|
80
97
  template.source = 'rcgemfile'
81
98
  template.destination = "#{name}/.rcgemfile"
82
99
  end
83
100
 
84
- template :spec_helper do |template|
85
- template.source = 'spec/spec_helper.rb'
86
- template.destination = "#{name}/spec/spec_helper.rb"
87
- end
88
-
89
101
  empty_directory :public do |dir|
90
102
  dir.destination = File.join("#{name}", 'public')
91
103
  end
92
104
 
105
+ invoke :js_app, :js => true
106
+ invoke :ruby_app, :js => false
107
+
93
108
  def after_run
94
109
  install_gems_note = <<_BUNDLE_INSTALL_
95
110
 
96
- In the future, to ensure that all the dependencies in your rhoconnect application
111
+ In the future, to ensure that all the dependencies in your rhoconnect application
97
112
  are available execute these commands:
98
113
  cd #{name} && bundle install
99
114
 
@@ -114,49 +129,135 @@ _RUN_BUNDLER
114
129
  puts install_gems_note
115
130
  end
116
131
  end
117
-
132
+
133
+ class RubyAppGenerator < AppGenerator
134
+ install_app_options(self)
135
+
136
+ template :application do |template|
137
+ template.source = 'controllers/ruby/application_controller.rb'
138
+ template.destination = "#{name}/controllers/ruby/application_controller.rb"
139
+ end
140
+
141
+ template :application_spec do |template|
142
+ template.source = 'spec/application_controller_spec.rb'
143
+ template.destination = "#{name}/spec/controllers/ruby/application_controller_spec.rb"
144
+ end
145
+
146
+ template :spec_helper do |template|
147
+ template.source = 'spec/spec_helper.rb'
148
+ template.destination = "#{name}/spec/spec_helper.rb"
149
+ end
150
+ end
151
+
152
+ class JsAppGenerator < AppGenerator
153
+ install_app_options(self)
154
+
155
+ file :packagejson, :after => :npm_install do |template|
156
+ template.source = 'package.json'
157
+ template.destination = "#{name}/package.json"
158
+ end
159
+
160
+ template :application do |template|
161
+ template.source = 'controllers/js/application_controller.js'
162
+ template.destination = "#{name}/controllers/js/application_controller.js"
163
+ end
164
+
165
+ def npm_install(action)
166
+ npm_install_note = <<_NPM_INSTALL_
167
+
168
+ In the future, to ensure that all the JavaScript dependencies in your
169
+ rhoconnect application are available execute these commands:
170
+ cd #{name} && npm install
171
+
172
+ _NPM_INSTALL_
173
+ puts npm_install_note
174
+ FileUtils.chdir(name)
175
+ system("npm install")
176
+ FileUtils.chdir('..')
177
+ end
178
+ end
179
+
118
180
  class SourceGenerator < BaseGenerator
181
+ install_source_options(self)
182
+
119
183
  def self.source_root
120
184
  File.join(File.dirname(__FILE__), 'templates', 'source')
121
185
  end
122
186
 
123
187
  desc <<-DESC
124
- Generates a new source adapter.
125
-
188
+ Generates a new source adapter (Controller/Model pair).
189
+
126
190
  Required:
127
- name - source name(i.e. product)
191
+ name - source name (i.e. product)
128
192
  DESC
129
193
 
130
- first_argument :name, :required => true, :desc => "source name"
194
+ invoke :ruby_source, :js => false
195
+ invoke :js_source, :js => true
196
+ end
197
+
198
+ class RubySourceGenerator < SourceGenerator
199
+ install_source_options(self)
131
200
 
132
- template :source do |template|
133
- template.source = 'source_adapter.rb'
134
- template.destination = "sources/#{underscore_name}.rb"
201
+ # 'template' does not work under jruby. Using 'file' and after hook instead
202
+ file :model, :after => :run_erb do |file|
203
+ file.source = 'models/ruby/model.rb'
204
+ file.destination = "models/ruby/#{underscore_name}.rb"
135
205
  settings_file = File.join(@destination_root,'settings','settings.yml')
136
206
  settings = YAML.load_file(settings_file)
137
207
  settings[:sources] ||= {}
138
208
  settings[:sources][class_name] = {:poll_interval => 300}
139
- File.open(settings_file, 'w' ) do |file|
140
- file.write "#Sources" + {:sources => settings[:sources]}.to_yaml[3..-1]
209
+ File.open(settings_file, 'w' ) do |f|
210
+ f.write "#Sources" + {:sources => settings[:sources]}.to_yaml[3..-1]
141
211
  envs = {}
142
212
  [:development,:test,:production].each do |env|
143
213
  envs[env] = settings[env]
144
214
  end
145
- file.write envs.to_yaml[3..-1]
215
+ f.write envs.to_yaml[3..-1]
146
216
  # write all other settings
147
217
  [:development, :test, :production, :sources].each do |key|
148
218
  settings.delete(key)
149
219
  end
150
- file.write settings.to_yaml[3..-1] unless settings.empty?
220
+ f.write settings.to_yaml[3..-1] unless settings.empty?
151
221
  end
152
222
  end
153
-
154
- template :source_spec do |template|
155
- template.source = 'source_spec.rb'
156
- template.destination = "spec/sources/#{underscore_name}_spec.rb"
223
+
224
+ file :controller, :after => :run_erb do |file|
225
+ file.source = 'controllers/ruby/controller.rb'
226
+ file.destination = "controllers/ruby/#{underscore_name}_controller.rb"
227
+ end
228
+
229
+ # 'template' does not work under jruby. Using 'file' and after hook instead
230
+ file :model_spec, :after => :run_erb do |file|
231
+ file.source = 'models/ruby/model_spec.rb'
232
+ file.destination = "spec/models/ruby/#{underscore_name}_spec.rb"
233
+ end
234
+
235
+ # 'template' does not work under jruby. Using 'file' and after hook instead
236
+ file :controller_spec, :after => :run_erb do |file|
237
+ file.source = 'controllers/ruby/controller_spec.rb'
238
+ file.destination = "spec/controllers/ruby/#{underscore_name}_controller_spec.rb"
157
239
  end
158
240
  end
159
-
241
+
242
+ class JsSourceGenerator < SourceGenerator
243
+ install_source_options(self)
244
+
245
+ file :model, :after => :run_erb do |file|
246
+ file.source = 'models/js/model.js'
247
+ file.destination = "models/js/#{underscore_name}.js"
248
+ end
249
+
250
+ file :controller, :after => :run_erb do |file|
251
+ file.source = 'controllers/js/controller.js'
252
+ file.destination = "controllers/js/#{underscore_name}_controller.js"
253
+ end
254
+ end
255
+
160
256
  add :app, AppGenerator
257
+ add_private :ruby_app, RubyAppGenerator
258
+ add_private :js_app, JsAppGenerator
259
+
161
260
  add :source, SourceGenerator
261
+ add_private :ruby_source, RubySourceGenerator
262
+ add_private :js_source, JsSourceGenerator
162
263
  end
@@ -1,8 +1,8 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'rhoconnect', '<%=gem_version%>'
4
- gemfile_path = File.join(File.dirname(__FILE__), ".rcgemfile")
5
4
 
5
+ gemfile_path = File.join(File.dirname(__FILE__), ".rcgemfile")
6
6
  begin
7
7
  eval(IO.read(gemfile_path))
8
8
  rescue Exception => e
@@ -9,9 +9,9 @@ ROOT_PATH = File.expand_path(File.dirname(__FILE__))
9
9
  task 'resque:setup' do
10
10
  # The number of redis connections you want a job to have
11
11
  Rhoconnect.connection_pool_size = 1
12
- require './application'
13
-
12
+ require 'rhoconnect/application/init'
13
+
14
14
  Resque.after_fork do
15
- Store.db.client.reconnect
15
+ Store.reconnect
16
16
  end
17
17
  end
@@ -12,8 +12,5 @@ Rhoconnect::Server.set :secret, '<%= @secret %>'
12
12
  # uncomment the following line to disable Rhoconnect Front-end console
13
13
  #Rhoconnect.disable_rc_console = true
14
14
 
15
- # Load RhoConnect application
16
- require './application'
17
-
18
15
  # run RhoConnect Application
19
- run Rhoconnect.app
16
+ run Rhoconnect.app
@@ -0,0 +1,17 @@
1
+ class ApplicationController < Rhoconnect::Controller::AppBase
2
+ register Rhoconnect::EndPoint
3
+
4
+ post "/login", :rc_handler => :authenticate,
5
+ :deprecated_route => {:verb => :post, :url => ['/application/clientlogin', '/api/application/clientlogin']} do
6
+ login = params[:login]
7
+ password = params[:password]
8
+ true # do some interesting authentication here...
9
+ end
10
+
11
+ get "/rps_login", :rc_handler => :rps_authenticate,
12
+ :login_required => true do
13
+ login = params[:login]
14
+ password = params[:password]
15
+ true # optionally handle rhoconnect push authentication...
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ var app = require("ballroom");
2
+ app.controllerName("Application");
3
+
4
+ app.post("/login",{"rc_handler":"authenticate"}, function(req,resp){
5
+ var login = req.params.login;
6
+ var password = req.params.password;
7
+ resp.send(true);
8
+ });
9
+
10
+ app.get("/rps_login",{"rc_handler":"rps_authenticate"}, function(req,resp){
11
+ var login = req.params.login;
12
+ var password = req.params.password;
13
+ resp.send(true);
14
+ });
@@ -0,0 +1,17 @@
1
+ class ApplicationController < Rhoconnect::Controller::AppBase
2
+ register Rhoconnect::EndPoint
3
+
4
+ post "/login", :rc_handler => :authenticate,
5
+ :deprecated_route => {:verb => :post, :url => ['/application/clientlogin', '/api/application/clientlogin']} do
6
+ login = params[:login]
7
+ password = params[:password]
8
+ true # do some interesting authentication here...
9
+ end
10
+
11
+ get "/rps_login", :rc_handler => :rps_authenticate,
12
+ :login_required => true do
13
+ login = params[:login]
14
+ password = params[:password]
15
+ true # optionally handle rhoconnect push authentication...
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "name" : "rhoconnect",
3
+ "version" :"1.0.0",
4
+ "main": "rhoconnect",
5
+ "dependencies": {
6
+ "redis" : "*"
7
+ }
8
+ }
@@ -1,9 +1,6 @@
1
1
  # Rhoconnect app runtime dependencies
2
2
  # DO NOT edit this file unless you know what are you doing!
3
3
 
4
- # Helps with some of the limitations of green threads, not needed in ruby 1.9.x
5
- gem 'SystemTimer', '~> 1.2.3', :platforms => :ruby_18
6
-
7
4
  # v0.7.x removes Process.fork, need this version for now
8
5
  gem 'win32-process', '= 0.6.6', :platforms => [:mswin, :mingw]
9
6
 
@@ -25,8 +22,7 @@ platforms :jruby do
25
22
  gem 'jdbc-sqlite3', ">= 3.7.2"
26
23
  gem 'dbi', ">= 0.4.5"
27
24
  gem 'dbd-jdbc', ">= 0.1.4"
28
- gem 'jruby-openssl', ">= 0.7.4"
29
- gem 'trinidad'
25
+ gem 'puma', "~> 1.6.0"
30
26
  gem 'warbler'
31
27
  end
32
28
 
@@ -41,4 +37,5 @@ group :test do
41
37
  gem 'rspec', '~> 2.10.0'
42
38
  gem 'rack-test', '>= 0.5.3', :require => "rack/test"
43
39
  gem 'rhomobile-debug', ">= 1.0.2"
40
+ gem 'capybara'
44
41
  end
@@ -3,17 +3,17 @@
3
3
  :development:
4
4
  :licensefile: settings/license.key
5
5
  :redis: localhost:6379
6
- :syncserver: http://localhost:9292/api/application/
6
+ :syncserver: http://localhost:9292
7
7
  :push_server: http://someappname@localhost:8675/
8
8
  :api_token: my-rhoconnect-token
9
9
  :test:
10
10
  :licensefile: settings/license.key
11
11
  :redis: localhost:6379
12
- :syncserver: http://localhost:9292/api/application/
12
+ :syncserver: http://localhost:9292
13
13
  :push_server: http://someappname@localhost:8675/
14
14
  :api_token: my-rhoconnect-token
15
15
  :production:
16
16
  :licensefile: settings/license.key
17
17
  :redis: localhost:6379
18
- :syncserver: http://localhost:9292/api/application/
18
+ :syncserver: http://localhost:9292
19
19
  :push_server: http://someappname@localhost:8675/
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__),'..','..','spec_helper')
2
+
3
+ describe "ApplicationController" do
4
+ it_should_behave_like "SpecHelper" do
5
+ include Rack::Test::Methods
6
+ include Rhoconnect
7
+
8
+ def app
9
+ @app = Rack::URLMap.new Rhoconnect.url_map
10
+ end
11
+
12
+ it "should process ApplicationController /login" do
13
+ post "/rc/#{Rhoconnect::API_VERSION}/app/login", {"login" => 'testuser', "password" => ''}.to_json,
14
+ {'CONTENT_TYPE'=>'application/json; charset=UTF-8'}
15
+ last_response.status.should == 200
16
+ end
17
+
18
+ it "should process ApplicationController /rps_login" do
19
+ pending
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__),'..','spec_helper')
2
+
3
+ describe "<%=class_name%>", :type => :feature do
4
+ it_should_behave_like "SpecHelper" do
5
+ before :each do
6
+ setup_test_for '<%=class_name%>','testuser'
7
+ end
8
+
9
+ it "queries <%=class_name%>" do
10
+
11
+ end
12
+
13
+ it "creates <%=class_name%>" do
14
+
15
+ end
16
+
17
+ it "updates <%=class_name%>" do
18
+
19
+ end
20
+
21
+ it "deletes <%=class_name%>" do
22
+
23
+ end
24
+ end
25
+ end
@@ -13,17 +13,31 @@ rescue LoadError
13
13
  end
14
14
 
15
15
  $:.unshift File.join(File.dirname(__FILE__), "..")
16
- # Load our rhoconnect application
17
- require 'application'
18
16
  include Rhoconnect
19
-
17
+ require 'rhoconnect/application/init'
20
18
  require 'rhoconnect/test_methods'
21
19
 
20
+ require 'capybara'
21
+ require 'capybara/dsl'
22
+
23
+ Capybara.app = Sinatra::Application
24
+
25
+ RSpec.configure do |config|
26
+ config.include Capybara
27
+ end
28
+
22
29
  shared_examples_for "SpecHelper" do
23
30
  include Rhoconnect::TestMethods
24
-
31
+
25
32
  before(:each) do
26
- Store.db.flushdb
27
- Application.initializer(ROOT_PATH)
28
- end
33
+ Store.create
34
+ Store.flush_all
35
+ Rhoconnect.bootstrap(ROOT_PATH)
36
+
37
+ # setup server's test settings
38
+ Rhoconnect::Server.set :environment, :test
39
+ Rhoconnect::Server.set :run, false
40
+ Rhoconnect::Server.set :use_async_model, false
41
+ Rhoconnect::Server.set :secret, "secure!"
42
+ end
29
43
  end
@@ -0,0 +1,7 @@
1
+ var app = require("ballroom");
2
+ var helpers = require("rhoconnect_helpers");
3
+
4
+ app.controllerName("<%=class_name%>");
5
+ app.registerHandler("sync");
6
+
7
+ // Add your custom routes here
@@ -0,0 +1,8 @@
1
+ class <%=class_name%>Controller < Rhoconnect::Controller::Base
2
+ register Rhoconnect::EndPoint
3
+
4
+ # register SYNC routes
5
+ register Rhoconnect::Handler::Sync
6
+
7
+ # add your custom routes here
8
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__),'..','..','spec_helper')
2
+
3
+ describe "<%=class_name%>Controller" do
4
+ it_should_behave_like "SpecHelper" do
5
+ include Rack::Test::Methods
6
+ include Rhoconnect
7
+
8
+ def app
9
+ @app = Rack::URLMap.new Rhoconnect.url_map
10
+ end
11
+
12
+ before(:each) do
13
+ setup_test_for <%=class_name%>,'testuser'
14
+ # login user to establish session cookie before each test
15
+ post "/rc/#{Rhoconnect::API_VERSION}/app/login", {"login" => 'testuser', "password" => ''}.to_json, {'CONTENT_TYPE'=>'application/json; charset=UTF-8'}
16
+ last_response.status.should == 200
17
+ end
18
+
19
+ it "should process <%=class_name%>Controller GET" do
20
+ pending
21
+ end
22
+
23
+ it "should process <%=class_name%>Controller POST" do
24
+ pending
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ var <%=class_name%> = function() {
2
+
3
+ this.login = function(resp){
4
+ // TODO: Login to your data source here if necessary
5
+ resp.send(true);
6
+ };
7
+
8
+ this.query = function(resp){
9
+ var result = {};
10
+ // TODO: Query your backend data source and assign the records
11
+ // to a nested hash structure. Then return your result.
12
+ // For example:
13
+ //
14
+ // {
15
+ // "1": {"name": "Acme", "industry": "Electronics"},
16
+ // "2": {"name": "Best", "industry": "Software"}
17
+ // }
18
+ resp.send(result);
19
+ };
20
+
21
+ this.create = function(resp){
22
+ // TODO: Create a new record in your backend data source. Then
23
+ // return the result.
24
+ resp.send('someId');
25
+ };
26
+
27
+ this.update = function(resp){
28
+ // TODO: Update an existing record in your backend data source.
29
+ // Then return the result.
30
+ resp.send(true);
31
+ };
32
+
33
+ this.del = function(resp){
34
+ // TODO: Delete an existing record in your backend data source
35
+ // if applicable. Be sure to have a hash key and value for
36
+ // "object" and return the result.
37
+ resp.send(true);
38
+ };
39
+
40
+ this.logoff = function(resp){
41
+ // TODO: Logout from the data source if necessary.
42
+ resp.send(true);
43
+ };
44
+ };
45
+
46
+ module.exports = new <%=class_name%>();
@@ -1,4 +1,4 @@
1
- class <%=class_name%> < SourceAdapter
1
+ class <%=class_name%> < Rhoconnect::Model::Base
2
2
  def initialize(source)
3
3
  super(source)
4
4
  end
@@ -14,16 +14,9 @@ class <%=class_name%> < SourceAdapter
14
14
  # "1"=>{"name"=>"Acme", "industry"=>"Electronics"},
15
15
  # "2"=>{"name"=>"Best", "industry"=>"Software"}
16
16
  # }
17
- raise SourceAdapterException.new("Please provide some code to read records from the backend data source")
17
+ raise Rhoconnect::Model::Exception.new("Please provide some code to read records from the backend data source")
18
18
  end
19
-
20
- def sync
21
- # Manipulate @result before it is saved, or save it
22
- # yourself using the Rhoconnect::Store interface.
23
- # By default, super is called below which simply saves @result
24
- super
25
- end
26
-
19
+
27
20
  def create(create_hash)
28
21
  # TODO: Create a new record in your backend data source
29
22
  raise "Please provide some code to create a single record in the backend data source using the create_hash"
@@ -44,4 +37,16 @@ class <%=class_name%> < SourceAdapter
44
37
  def logoff
45
38
  # TODO: Logout from the data source if necessary
46
39
  end
40
+
41
+ # Calling super here returns rack tempfile path:
42
+ # i.e. /var/folders/J4/J4wGJ-r6H7S313GEZ-Xx5E+++TI
43
+ # Note: This tempfile is removed when server stops or crashes...
44
+ # See http://rack.rubyforge.org/doc/Multipart.html for more info
45
+ #
46
+ # Uncomment this code and override it by creating a copy of the file somewhere
47
+ # and returning the path to that file (then don't call super!):
48
+ # i.e. /mnt/myimages/soccer.png
49
+ #def store_blob(object,field_name,blob)
50
+ # super #=> returns blob[:tempfile]
51
+ #end
47
52
  end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__),'..','spec_helper')
1
+ require File.join(File.dirname(__FILE__),'..','..','spec_helper')
2
2
 
3
3
  describe "<%=class_name%>" do
4
4
  it_should_behave_like "SpecHelper" do