barkest_core 1.5.3.0

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 (308) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/Gemfile +22 -0
  4. data/Gemfile.lock +254 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +364 -0
  7. data/Rakefile +37 -0
  8. data/app/assets/fonts/barkest_core/ArchivoNarrow-Bold.ttf +0 -0
  9. data/app/assets/fonts/barkest_core/ArchivoNarrow-BoldItalic.ttf +0 -0
  10. data/app/assets/fonts/barkest_core/ArchivoNarrow-Italic.ttf +0 -0
  11. data/app/assets/fonts/barkest_core/ArchivoNarrow-Regular.ttf +0 -0
  12. data/app/assets/images/barkest_core/.keep +0 -0
  13. data/app/assets/images/barkest_core/barcode-B.svg +181 -0
  14. data/app/assets/javascripts/barkest_core/.keep +0 -0
  15. data/app/assets/javascripts/barkest_core/application.js +22 -0
  16. data/app/assets/javascripts/barkest_core/bootstrap-datepicker.js +1800 -0
  17. data/app/assets/javascripts/barkest_core/field_init.js +7 -0
  18. data/app/assets/javascripts/barkest_core/jquery.doubleScroll.js +112 -0
  19. data/app/assets/javascripts/barkest_core/masked_edit.js +25 -0
  20. data/app/assets/javascripts/barkest_core/system_status.js.erb +201 -0
  21. data/app/assets/stylesheets/barkest_core/.keep +0 -0
  22. data/app/assets/stylesheets/barkest_core/application.css +17 -0
  23. data/app/assets/stylesheets/barkest_core/custom.css.scss +264 -0
  24. data/app/assets/stylesheets/barkest_core/datepicker3.css +790 -0
  25. data/app/controllers/.keep +0 -0
  26. data/app/controllers/access_groups_controller.rb +74 -0
  27. data/app/controllers/account_activations_controller.rb +29 -0
  28. data/app/controllers/application_controller.rb +5 -0
  29. data/app/controllers/barkest_core/application_controller_base.rb +113 -0
  30. data/app/controllers/barkest_core/engine_controller_base.rb +15 -0
  31. data/app/controllers/barkest_core/testsub_controller.rb +21 -0
  32. data/app/controllers/contact_controller.rb +32 -0
  33. data/app/controllers/log_view_controller.rb +31 -0
  34. data/app/controllers/password_resets_controller.rb +126 -0
  35. data/app/controllers/sessions_controller.rb +64 -0
  36. data/app/controllers/status_controller.rb +150 -0
  37. data/app/controllers/system_config_controller.rb +238 -0
  38. data/app/controllers/system_update_controller.rb +164 -0
  39. data/app/controllers/test_access_controller.rb +44 -0
  40. data/app/controllers/test_report_controller.rb +75 -0
  41. data/app/controllers/users_controller.rb +218 -0
  42. data/app/helpers/.keep +0 -0
  43. data/app/helpers/barkest_core/application_helper.rb +134 -0
  44. data/app/helpers/barkest_core/form_helper.rb +469 -0
  45. data/app/helpers/barkest_core/html_helper.rb +70 -0
  46. data/app/helpers/barkest_core/misc_helper.rb +68 -0
  47. data/app/helpers/barkest_core/pdf_helper.rb +180 -0
  48. data/app/helpers/barkest_core/recaptcha_helper.rb +115 -0
  49. data/app/helpers/barkest_core/sessions_helper.rb +94 -0
  50. data/app/helpers/barkest_core/status_helper.rb +118 -0
  51. data/app/helpers/barkest_core/users_helper.rb +32 -0
  52. data/app/mailers/.keep +0 -0
  53. data/app/mailers/application_mailer.rb +5 -0
  54. data/app/mailers/barkest_core/application_mailer_base.rb +30 -0
  55. data/app/mailers/barkest_core/contact_form.rb +20 -0
  56. data/app/mailers/barkest_core/user_mailer.rb +44 -0
  57. data/app/models/.keep +0 -0
  58. data/app/models/access_group.rb +121 -0
  59. data/app/models/access_group_group_member.rb +13 -0
  60. data/app/models/access_group_user_member.rb +11 -0
  61. data/app/models/barkest_core/auth_config.rb +95 -0
  62. data/app/models/barkest_core/authorize_failure.rb +7 -0
  63. data/app/models/barkest_core/contact_message.rb +37 -0
  64. data/app/models/barkest_core/database_config.rb +223 -0
  65. data/app/models/barkest_core/db_table.rb +21 -0
  66. data/app/models/barkest_core/email_config.rb +132 -0
  67. data/app/models/barkest_core/global_status.rb +267 -0
  68. data/app/models/barkest_core/log_entry.rb +101 -0
  69. data/app/models/barkest_core/log_view_options.rb +51 -0
  70. data/app/models/barkest_core/ms_sql_db_definition.rb +441 -0
  71. data/app/models/barkest_core/ms_sql_definition.rb +221 -0
  72. data/app/models/barkest_core/ms_sql_function.rb +423 -0
  73. data/app/models/barkest_core/not_logged_in.rb +7 -0
  74. data/app/models/barkest_core/pdf_table_builder.rb +407 -0
  75. data/app/models/barkest_core/self_update_config.rb +37 -0
  76. data/app/models/barkest_core/user_alert.rb +29 -0
  77. data/app/models/barkest_core/user_alert_generators.rb +58 -0
  78. data/app/models/barkest_core/user_manager.rb +404 -0
  79. data/app/models/barkest_core/work_path.rb +74 -0
  80. data/app/models/disable_user.rb +18 -0
  81. data/app/models/ldap_access_group.rb +15 -0
  82. data/app/models/system_config.rb +99 -0
  83. data/app/models/user.rb +405 -0
  84. data/app/models/user_login_history.rb +11 -0
  85. data/app/views/.keep +0 -0
  86. data/app/views/access_groups/_form.html.erb +19 -0
  87. data/app/views/access_groups/edit.html.erb +2 -0
  88. data/app/views/access_groups/index.html.erb +32 -0
  89. data/app/views/access_groups/new.html.erb +2 -0
  90. data/app/views/access_groups/show.html.erb +4 -0
  91. data/app/views/barkest_core/contact_form/contact.html.erb +16 -0
  92. data/app/views/barkest_core/contact_form/contact.text.erb +13 -0
  93. data/app/views/barkest_core/testsub/_links.html.erb +5 -0
  94. data/app/views/barkest_core/testsub/page1.html.erb +3 -0
  95. data/app/views/barkest_core/testsub/page2.html.erb +2 -0
  96. data/app/views/barkest_core/testsub/page3.html.erb +2 -0
  97. data/app/views/barkest_core/user_mailer/account_activation.html.erb +7 -0
  98. data/app/views/barkest_core/user_mailer/account_activation.text.erb +6 -0
  99. data/app/views/barkest_core/user_mailer/invalid_password_reset.html.erb +3 -0
  100. data/app/views/barkest_core/user_mailer/invalid_password_reset.text.erb +5 -0
  101. data/app/views/barkest_core/user_mailer/password_reset.html.erb +8 -0
  102. data/app/views/barkest_core/user_mailer/password_reset.text.erb +7 -0
  103. data/app/views/contact/index.html.erb +24 -0
  104. data/app/views/layouts/_footer_copyright.html.erb +1 -0
  105. data/app/views/layouts/_menu_admin.html.erb +5 -0
  106. data/app/views/layouts/_menu_anon.html.erb +0 -0
  107. data/app/views/layouts/_menu_auth.html.erb +3 -0
  108. data/app/views/layouts/_menu_footer.html.erb +1 -0
  109. data/app/views/layouts/_nav_logo.html.erb +1 -0
  110. data/app/views/layouts/application.html.erb +2 -0
  111. data/app/views/layouts/barkest_core/_application.html.erb +24 -0
  112. data/app/views/layouts/barkest_core/_footer.html.erb +18 -0
  113. data/app/views/layouts/barkest_core/_header.html.erb +38 -0
  114. data/app/views/layouts/barkest_core/_html_mailer.html.erb +11 -0
  115. data/app/views/layouts/barkest_core/_menu_account.html.erb +14 -0
  116. data/app/views/layouts/barkest_core/_menu_sample.html.erb +1 -0
  117. data/app/views/layouts/barkest_core/_messages.html.erb +4 -0
  118. data/app/views/layouts/barkest_core/_shim.html.erb +4 -0
  119. data/app/views/layouts/barkest_core/_subheader.html.erb +1 -0
  120. data/app/views/layouts/barkest_core/_text_mailer.text.erb +4 -0
  121. data/app/views/layouts/mailer.html.erb +1 -0
  122. data/app/views/layouts/mailer.text.erb +1 -0
  123. data/app/views/log_view/index.html.erb +100 -0
  124. data/app/views/password_resets/edit.html.erb +20 -0
  125. data/app/views/password_resets/new.html.erb +14 -0
  126. data/app/views/sessions/new.html.erb +27 -0
  127. data/app/views/shared/_error_messages.html.erb +29 -0
  128. data/app/views/shared/_generic_user_alert.html.erb +4 -0
  129. data/app/views/status/current.html.erb +34 -0
  130. data/app/views/status/test.html.erb +50 -0
  131. data/app/views/system_config/index.html.erb +25 -0
  132. data/app/views/system_config/show_auth.html.erb +28 -0
  133. data/app/views/system_config/show_database.html.erb +36 -0
  134. data/app/views/system_config/show_email.html.erb +21 -0
  135. data/app/views/system_config/show_self_update.html.erb +13 -0
  136. data/app/views/system_update/index.html.erb +31 -0
  137. data/app/views/system_update/new.html.erb +2 -0
  138. data/app/views/test_access/allow_anon.html.erb +2 -0
  139. data/app/views/test_access/require_admin.html.erb +2 -0
  140. data/app/views/test_access/require_group_x.html.erb +2 -0
  141. data/app/views/test_access/require_user.html.erb +2 -0
  142. data/app/views/test_report/index.csv.csvrb +23 -0
  143. data/app/views/test_report/index.html.erb +6 -0
  144. data/app/views/test_report/index.pdf.prawn +50 -0
  145. data/app/views/test_report/index.xlsx.axlsx +28 -0
  146. data/app/views/users/_user.html.erb +57 -0
  147. data/app/views/users/_user_details.html.erb +15 -0
  148. data/app/views/users/_user_details_for_list.html.erb +1 -0
  149. data/app/views/users/_user_form.html.erb +13 -0
  150. data/app/views/users/disable_confirm.html.erb +19 -0
  151. data/app/views/users/edit.html.erb +15 -0
  152. data/app/views/users/index.html.erb +9 -0
  153. data/app/views/users/new.html.erb +10 -0
  154. data/app/views/users/show.html.erb +46 -0
  155. data/bin/rails +12 -0
  156. data/config/routes.rb +3 -0
  157. data/db/migrate/20160617172539_create_access_groups.rb +10 -0
  158. data/db/migrate/20160617172725_create_users.rb +26 -0
  159. data/db/migrate/20160617172833_create_user_login_histories.rb +12 -0
  160. data/db/migrate/20160622151720_create_access_group_user_members.rb +9 -0
  161. data/db/migrate/20160622151925_create_access_group_group_members.rb +9 -0
  162. data/db/migrate/20160701005706_create_ldap_access_groups.rb +11 -0
  163. data/db/migrate/20161108155029_create_system_configs.rb +11 -0
  164. data/db/seeds/barkest_core_01_create_users.rb +42 -0
  165. data/db/seeds.rb +53 -0
  166. data/lib/barkest_core/concerns/association_with_defaults.rb +55 -0
  167. data/lib/barkest_core/concerns/boolean_parser.rb +88 -0
  168. data/lib/barkest_core/concerns/date_parser.rb +181 -0
  169. data/lib/barkest_core/concerns/email_tester.rb +55 -0
  170. data/lib/barkest_core/concerns/encrypted_fields.rb +156 -0
  171. data/lib/barkest_core/concerns/named_model.rb +73 -0
  172. data/lib/barkest_core/concerns/number_parser.rb +145 -0
  173. data/lib/barkest_core/concerns/utc_conversion.rb +60 -0
  174. data/lib/barkest_core/engine.rb +105 -0
  175. data/lib/barkest_core/extensions/active_record_extensions.rb +120 -0
  176. data/lib/barkest_core/extensions/application_configuration_extensions.rb +38 -0
  177. data/lib/barkest_core/extensions/application_extensions.rb +50 -0
  178. data/lib/barkest_core/extensions/axlsx_extenstions.rb +157 -0
  179. data/lib/barkest_core/extensions/fixture_set_extensions.rb +107 -0
  180. data/lib/barkest_core/extensions/generator_extensions.rb +271 -0
  181. data/lib/barkest_core/extensions/main_app_extensions.rb +35 -0
  182. data/lib/barkest_core/extensions/prawn_document_extensions.rb +367 -0
  183. data/lib/barkest_core/extensions/prawn_table_extensions.rb +131 -0
  184. data/lib/barkest_core/extensions/router_extensions.rb +106 -0
  185. data/lib/barkest_core/extensions/simple_formatter_extensions.rb +66 -0
  186. data/lib/barkest_core/extensions/test_case_extensions.rb +348 -0
  187. data/lib/barkest_core/extensions/time_extensions.rb +164 -0
  188. data/lib/barkest_core/handlers/csv_handler.rb +30 -0
  189. data/lib/barkest_core/version.rb +3 -0
  190. data/lib/barkest_core.rb +324 -0
  191. data/lib/generators/barkest/install_generator.rb +102 -0
  192. data/lib/generators/barkest_core/actions/01_patch_application_controller.rb +55 -0
  193. data/lib/generators/barkest_core/actions/02_patch_application_mailer.rb +56 -0
  194. data/lib/generators/barkest_core/actions/03_patch_assets.rb +62 -0
  195. data/lib/generators/barkest_core/actions/04_patch_layouts.rb +36 -0
  196. data/lib/generators/barkest_core/actions/05_patch_routes.rb +93 -0
  197. data/lib/generators/barkest_core/actions/06_patch_seeds.rb +60 -0
  198. data/lib/generators/barkest_core/actions/07_copy_migrations.rb +51 -0
  199. data/lib/generators/barkest_core/actions/08_configure_database.rb +52 -0
  200. data/lib/generators/barkest_core/actions/09_configure_secrets.rb +29 -0
  201. data/lib/generators/barkest_core/actions/99_patch_gitignore.rb +57 -0
  202. data/lib/generators/barkest_core/install_generator.rb +17 -0
  203. data/test/barkest_core_test.rb +83 -0
  204. data/test/controllers/access_groups_controller_test.rb +53 -0
  205. data/test/controllers/contact_controller_test.rb +10 -0
  206. data/test/controllers/sessions_controller_test.rb +10 -0
  207. data/test/controllers/users_controller_test.rb +10 -0
  208. data/test/dummy/.gitignore +10 -0
  209. data/test/dummy/README.rdoc +28 -0
  210. data/test/dummy/Rakefile +6 -0
  211. data/test/dummy/app/assets/images/.keep +0 -0
  212. data/test/dummy/app/assets/javascripts/application.js +14 -0
  213. data/test/dummy/app/assets/stylesheets/application.css +16 -0
  214. data/test/dummy/app/controllers/application_controller.rb +5 -0
  215. data/test/dummy/app/controllers/concerns/.keep +0 -0
  216. data/test/dummy/app/helpers/application_helper.rb +2 -0
  217. data/test/dummy/app/mailers/.keep +0 -0
  218. data/test/dummy/app/mailers/application_mailer.rb +3 -0
  219. data/test/dummy/app/models/.keep +0 -0
  220. data/test/dummy/app/models/concerns/.keep +0 -0
  221. data/test/dummy/app/views/layouts/application.html.erb +1 -0
  222. data/test/dummy/app/views/layouts/mailer.html.erb +1 -0
  223. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  224. data/test/dummy/app/views/system_config/show_fake.html.erb +3 -0
  225. data/test/dummy/bin/bundle +3 -0
  226. data/test/dummy/bin/rails +4 -0
  227. data/test/dummy/bin/rake +4 -0
  228. data/test/dummy/bin/setup +29 -0
  229. data/test/dummy/config/application.rb +27 -0
  230. data/test/dummy/config/boot.rb +5 -0
  231. data/test/dummy/config/environment.rb +5 -0
  232. data/test/dummy/config/environments/development.rb +47 -0
  233. data/test/dummy/config/environments/production.rb +79 -0
  234. data/test/dummy/config/environments/test.rb +44 -0
  235. data/test/dummy/config/initializers/assets.rb +11 -0
  236. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  237. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  238. data/test/dummy/config/initializers/db_updater_ext.rb +33 -0
  239. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  240. data/test/dummy/config/initializers/inflections.rb +16 -0
  241. data/test/dummy/config/initializers/mime_types.rb +4 -0
  242. data/test/dummy/config/initializers/session_store.rb +3 -0
  243. data/test/dummy/config/initializers/sys_config_ext.rb +12 -0
  244. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  245. data/test/dummy/config/locales/en.yml +23 -0
  246. data/test/dummy/config/routes.rb +60 -0
  247. data/test/dummy/config.ru +4 -0
  248. data/test/dummy/db/schema.rb +95 -0
  249. data/test/dummy/db/seeds/barkest_core_01_create_users.rb +42 -0
  250. data/test/dummy/db/seeds.rb +51 -0
  251. data/test/dummy/lib/assets/.keep +0 -0
  252. data/test/dummy/log/.keep +0 -0
  253. data/test/dummy/public/404.html +67 -0
  254. data/test/dummy/public/422.html +67 -0
  255. data/test/dummy/public/500.html +66 -0
  256. data/test/dummy/public/favicon.ico +0 -0
  257. data/test/dummy/sql/my_test_view.sql +3 -0
  258. data/test/fixtures/access_groups.yml +21 -0
  259. data/test/fixtures/users.yml +71 -0
  260. data/test/helpers/barkest_core/sessions_helper_test.rb +22 -0
  261. data/test/integration/access_group_mgmt_test.rb +33 -0
  262. data/test/integration/access_test.rb +24 -0
  263. data/test/integration/account_activations_access_test.rb +12 -0
  264. data/test/integration/contact_test.rb +98 -0
  265. data/test/integration/extra_partial_test.rb +41 -0
  266. data/test/integration/log_view_access_test.rb +12 -0
  267. data/test/integration/password_resets_test.rb +101 -0
  268. data/test/integration/reports_test.rb +53 -0
  269. data/test/integration/status_access_test.rb +27 -0
  270. data/test/integration/system_config_access_test.rb +24 -0
  271. data/test/integration/system_update_access_test.rb +19 -0
  272. data/test/integration/users_access_test.rb +34 -0
  273. data/test/integration/users_edit_test.rb +178 -0
  274. data/test/integration/users_index_test.rb +62 -0
  275. data/test/integration/users_login_test.rb +67 -0
  276. data/test/integration/users_signup_test.rb +54 -0
  277. data/test/mailers/.keep +0 -0
  278. data/test/mailers/barkest_core/contact_form_test.rb +28 -0
  279. data/test/mailers/barkest_core/user_mailer_test.rb +43 -0
  280. data/test/mailers/previews/barkest_core/contact_form_preview.rb +17 -0
  281. data/test/mailers/previews/barkest_core/user_mailer_preview.rb +26 -0
  282. data/test/models/access_group_group_member_test.rb +28 -0
  283. data/test/models/access_group_test.rb +114 -0
  284. data/test/models/access_group_user_member_test.rb +28 -0
  285. data/test/models/barkest_core/auth_config_test.rb +57 -0
  286. data/test/models/barkest_core/bool_parser_test.rb +28 -0
  287. data/test/models/barkest_core/contact_message_test.rb +61 -0
  288. data/test/models/barkest_core/database_config_test.rb +33 -0
  289. data/test/models/barkest_core/date_parser_test.rb +110 -0
  290. data/test/models/barkest_core/email_config_test.rb +57 -0
  291. data/test/models/barkest_core/global_status_test.rb +50 -0
  292. data/test/models/barkest_core/ms_sql_db_updater_test.rb +115 -0
  293. data/test/models/barkest_core/ms_sql_definition_test.rb +102 -0
  294. data/test/models/barkest_core/ms_sql_function_test.rb +131 -0
  295. data/test/models/barkest_core/number_parser_test.rb +29 -0
  296. data/test/models/barkest_core/self_update_config_test.rb +29 -0
  297. data/test/models/barkest_core/user_alert_test.rb +19 -0
  298. data/test/models/barkest_core/user_manager_test.rb +34 -0
  299. data/test/models/barkest_core/work_path_test.rb +26 -0
  300. data/test/models/disable_user_test.rb +27 -0
  301. data/test/models/generic_time_test.rb +66 -0
  302. data/test/models/ldap_access_group_test.rb +31 -0
  303. data/test/models/pdf_table_builder_test.rb +6 -0
  304. data/test/models/system_config_test.rb +78 -0
  305. data/test/models/user_login_history_test.rb +37 -0
  306. data/test/models/user_test.rb +130 -0
  307. data/test/test_helper.rb +63 -0
  308. metadata +798 -0
@@ -0,0 +1,7 @@
1
+ module BarkestCore
2
+ ##
3
+ # A simple wrapper around the standard error class signifying that a user is not logged in.
4
+ class NotLoggedIn < StandardError
5
+
6
+ end
7
+ end
@@ -0,0 +1,407 @@
1
+ module BarkestCore
2
+
3
+ ##
4
+ # A table builder to ease creation of tables in PDF documents.
5
+ #
6
+ class PdfTableBuilder
7
+
8
+ ##
9
+ # Creates a new table builder in the provided +document+.
10
+ #
11
+ # The options can specify both table options and :cell_style options.
12
+ # The :cell_style option should be a hash of styles for the cells in your table.
13
+ #
14
+ def initialize(document, options = {}, &block)
15
+ options ||= {}
16
+
17
+ @doc = document
18
+
19
+ @data = []
20
+ @col_offset = 0
21
+ @row_offset = 0
22
+ @col_start = 0
23
+ @in_row = false
24
+
25
+ @base_cell_options = { borders: [] }.merge(options[:cell_style] || { })
26
+ @options = options.except(:cell_style)
27
+
28
+ yield self if block_given?
29
+ end
30
+
31
+ ##
32
+ # Gets the cell options provided during the TableBuilder creation.
33
+ def base_cell_options
34
+ @base_cell_options
35
+ end
36
+
37
+ ##
38
+ # Gets the table options provided during the TableBuilder creation.
39
+ def table_options
40
+ @options
41
+ end
42
+
43
+ ##
44
+ # Generates the table array used by Prawn::Table.
45
+ def to_table
46
+ @doc.make_table(data, table_options)
47
+ end
48
+
49
+ ##
50
+ # Gets the current position in the table.
51
+ def position
52
+ [ @row_offset, @col_offset ]
53
+ end
54
+
55
+ ##
56
+ # Gets the current row in the table.
57
+ def current_row
58
+ @row_offset
59
+ end
60
+
61
+ ##
62
+ # Gets the current column in the table.
63
+ def current_column
64
+ @col_offset
65
+ end
66
+
67
+ ##
68
+ # Gets the last row in the table.
69
+ def last_row
70
+ @data.length - 1
71
+ end
72
+
73
+ ##
74
+ # Gets the last column in the table.
75
+ def last_column
76
+ max = 0
77
+ @data.each do |row|
78
+ max = row.length if max < row.length
79
+ end
80
+ max - 1
81
+ end
82
+
83
+ ##
84
+ # Builds data starting at the specified column.
85
+ #
86
+ # The +start_column+ is the first column you want to be building.
87
+ # When you start a new row inside of a build_column block, the new row
88
+ # starts at this same column.
89
+ def build_column(start_column = nil)
90
+ if block_given?
91
+ raise StandardError.new('build_column block called within row block') if @in_row
92
+ raise StandardError.new('build_column called without valid argument') unless start_column.is_a?(Numeric)
93
+
94
+ backup_col_start = @col_start
95
+ backup_col_offset = @col_offset
96
+ backup_row_offset = @row_offset
97
+ @col_start = start_column.to_i
98
+ @col_offset = @col_start
99
+ @row_offset = 0
100
+
101
+ yield
102
+
103
+ @col_start = backup_col_start
104
+ @col_offset = backup_col_offset
105
+ @row_offset = backup_row_offset
106
+ end
107
+ @col_start
108
+ end
109
+
110
+ ##
111
+ # Builds a row in the table.
112
+ #
113
+ # Valid options:
114
+ #
115
+ # row::
116
+ # Defines the row you want to start on. If not set, then it uses #current_row.
117
+ #
118
+ # Additional options are merged with the base cell options for this row.
119
+ #
120
+ # When it completes, the #current_row is set to 1 more than the row we started on.
121
+ #
122
+ def row(options = {}, &block)
123
+ raise StandardError.new('row called within row block') if @in_row
124
+
125
+ @in_row = true
126
+ @col_offset = @col_start
127
+ options = change_row(options || {})
128
+
129
+ @row_cell_options = @base_cell_options.merge(options)
130
+
131
+ fill_cells(@row_offset, @col_offset)
132
+
133
+ # skip placeholders when starting a new row.
134
+ if @data[@row_offset]
135
+ while @data[@row_offset][@col_offset] == :span_placeholder
136
+ @col_offset += 1
137
+ end
138
+ end
139
+
140
+ yield if block_given?
141
+
142
+ @in_row = false
143
+ @row_offset += 1
144
+ @row_cell_options = nil
145
+ end
146
+
147
+ ##
148
+ # Builds a subtable within the current row.
149
+ #
150
+ # The +cell_options+ are passed to the current cell.
151
+ # The +options+ are passed to the new TableBuilder.
152
+ #
153
+ def subtable(cell_options = {}, options = {}, &block)
154
+ raise StandardError.new('subtable called outside of row block') unless @in_row
155
+ cell cell_options || {} do
156
+ PdfTableBuilder.new(@doc, options || {}, &block).to_table
157
+ end
158
+ end
159
+
160
+ ##
161
+ # Creates a bold cell.
162
+ #
163
+ # See #cell for valid options.
164
+ #
165
+ def bold_cell(options = {}, &block)
166
+ cell({ font_style: :bold }.merge(options || {}), &block)
167
+ end
168
+
169
+ ##
170
+ # Creates an italicized cell.
171
+ #
172
+ # See #cell for valid options.
173
+ #
174
+ def italic_cell(options = {}, &block)
175
+ cell({ font_style: :italic }.merge(options || {}), &block)
176
+ end
177
+
178
+ ##
179
+ # Creates a bold-italic cell.
180
+ #
181
+ # See #cell for valid options.
182
+ #
183
+ def bold_italic_cell(options = {}, &block)
184
+ cell({ font_style: :bold_italic }.merge(options || {}), &block)
185
+ end
186
+
187
+ ##
188
+ # Creates an underlined cell.
189
+ #
190
+ # See #cell for valid options.
191
+ #
192
+ def underline_cell(options = {}, &block)
193
+ cell({ borders: [ :bottom ], border_width: 0.5 }.merge(options || {}), &block)
194
+ end
195
+
196
+ ##
197
+ # Creates multiple cells.
198
+ #
199
+ # Individual cells can be given options by prefixing the keys with 'cell_#' where # is the cell number (starting at 1).
200
+ #
201
+ # See #cell for valid options.
202
+ #
203
+ def cells(options = {}, &block)
204
+ cell_regex = /^cell_([0-9]+)_/
205
+
206
+ options ||= { }
207
+
208
+ result = block_given? ? yield : (options[:values] || [''])
209
+
210
+ cell_options = result.map { {} }
211
+ common_options = {}
212
+
213
+ options.each do |k,v|
214
+ # if the option starts with 'cell_#_' then apply it accordingly.
215
+ if (m = cell_regex.match(k.to_s))
216
+ k = k.to_s[m[0].length..-1].to_sym
217
+ cell_options[m[1].to_i - 1][k] = v
218
+
219
+ # the 'column' option applies only to the first cell.
220
+ elsif k == :column
221
+ cell_options[0][k] = v
222
+
223
+ # everything else applies to all cells, unless overridden explicitly.
224
+ elsif k != :values
225
+ common_options[k] = v
226
+ end
227
+ end
228
+
229
+ cell_options.each_with_index do |opt,idx|
230
+ cell common_options.merge(opt).merge( { value: result[idx] } )
231
+ end
232
+ end
233
+
234
+ ##
235
+ # Creates a pair of cells.
236
+ # The first cell is bold with the :key option and the second cell is normal with the :value option.
237
+ #
238
+ # Additional options can be specified as they are in #cells.
239
+ #
240
+ def key_value(options = {}, &block)
241
+ options ||= {}
242
+
243
+ if options[:key]
244
+ options[:values] ||= []
245
+ options[:values][0] = options[:key]
246
+ end
247
+ if options[:value]
248
+ options[:values] ||= []
249
+ options[:values][1] = options[:value]
250
+ end
251
+
252
+ options = {
253
+ cell_1_font_style: :bold
254
+ }.merge(options.except(:key, :value))
255
+
256
+ cells options, &block
257
+ end
258
+
259
+ ##
260
+ # Generates a cell in the current row.
261
+ #
262
+ # Valid options:
263
+ #
264
+ # value::
265
+ # The value to put in the cell, unless a code block is provided, in which case the result of the code block is used.
266
+ #
267
+ # rowspan::
268
+ # The number of rows for this cell to cover.
269
+ #
270
+ # colspan::
271
+ # The number of columns for this cell to cover.
272
+ #
273
+ # Additional options are embedded and passed on to Prawn::Table, see {Prawn PDF Table Manual}[http://prawnpdf.org/prawn-table-manual.pdf] for more information.
274
+ #
275
+ def cell(options = {}, &block)
276
+ raise StandardError.new('cell called outside of row block') unless @in_row
277
+
278
+ options = @row_cell_options.merge(options || {})
279
+
280
+ options = change_col(options)
281
+
282
+ result = block_given? ? yield : (options[:value] || '')
283
+
284
+ options.except!(:value)
285
+
286
+ set_cell(result, nil, nil, options)
287
+ end
288
+
289
+
290
+ private
291
+
292
+ def data
293
+ fix_row_widths
294
+ # remove all placeholders.
295
+ ret = @data.map do |row|
296
+ row.delete_if { |item| item == :span_placeholder }
297
+ end
298
+ # remove all empty rows.
299
+ ret.delete_if { |row| row.empty? }
300
+ end
301
+
302
+ def change_row(options)
303
+ if options[:row] && options[:row] >= 0
304
+ @row_offset = options[:row]
305
+ end
306
+ options.except(:row)
307
+ end
308
+
309
+ def change_col(options)
310
+ if options[:column] && options[:column] >= 0
311
+ @col_offset = @col_start + options[:column]
312
+ end
313
+ options.except(:column)
314
+ end
315
+
316
+ def fill_cells(row, col)
317
+ return unless row >= 0 && col >= 0
318
+
319
+ if @data.length <= row
320
+ @data += [[ (@row_cell_options || @base_cell_options).merge({content: ''}) ]] * (row - @data.length + 1)
321
+ end
322
+
323
+ if @data[row].length <= col
324
+ @data[row] += [ (@row_cell_options || @base_cell_options).merge({content: ''}) ] * (col - @data[row].length + 1)
325
+ end
326
+ end
327
+
328
+ def clear_cell(row, col)
329
+ fill_cells row, col
330
+
331
+ unless @data[row][col].blank?
332
+ raise StandardError.new('placeholders cannot be cleared') if @data[row][col] == :span_placeholder
333
+
334
+ if @data[row][col].is_a? Hash
335
+ options = @data[row][col][:options] || { }
336
+ rspan = options[:rowspan] || 1
337
+ cspan = options[:colspan] || 1
338
+
339
+ # clear all the cells covered by the previous value.
340
+ (0...rspan).each do |r|
341
+ (0...cspan).each do |c|
342
+ @data[row + r][col + c] = ''
343
+ end
344
+ end
345
+
346
+ else
347
+ @data[row][col] = ''
348
+ end
349
+ end
350
+ end
351
+
352
+ def set_cell(val, set_row = nil, set_col = nil, options = {})
353
+ row = set_row || @row_offset
354
+ col = set_col || @col_offset
355
+
356
+ clear_cell row, col
357
+
358
+ if options.empty?
359
+ @data[row][col] = val
360
+ else
361
+ @data[row][col] = options.merge({ content: val })
362
+ end
363
+
364
+ rspan = options[:rowspan] || 1
365
+ cspan = options[:colspan] || 1
366
+
367
+ # fill in placeholders for the spans.
368
+ (1...cspan).each do |c|
369
+ set_cell(:span_placeholder, row, col + c)
370
+ end
371
+ (1...rspan).each do |r|
372
+ (0...cspan).each do |c|
373
+ set_cell(:span_placeholder, row + r, col + c)
374
+ end
375
+ end
376
+
377
+ unless set_col
378
+ @col_offset += 1
379
+ # skip over placeholders to set the next column position.
380
+ while @data[row][@col_offset] == :span_placeholder
381
+ @col_offset += 1
382
+ end
383
+ end
384
+ end
385
+
386
+ # ensure that all 2nd level arrays are the same size.
387
+ def fix_row_widths
388
+
389
+ fill_cells(@row_offset - 1, 0)
390
+
391
+ max = 0
392
+
393
+ @data.each_with_index do |row|
394
+ max = row.length unless max >= row.length
395
+ end
396
+
397
+ @data.each_with_index do |row,idx|
398
+ if row.length < max
399
+ row = row + [ @base_cell_options.merge({content: ''}) ] * (max - row.length)
400
+ @data[idx] = row
401
+ end
402
+ end
403
+
404
+ end
405
+
406
+ end
407
+ end
@@ -0,0 +1,37 @@
1
+ module BarkestCore
2
+ class SelfUpdateConfig
3
+ include ActiveModel::Model
4
+ include ActiveModel::Validations
5
+
6
+ attr_accessor :host, :user, :password
7
+ attr_writer :port
8
+
9
+ validates :host, presence: true
10
+ validates :user, presence: true
11
+ validates :password, presence: true
12
+
13
+ def to_h
14
+ {
15
+ host: host.to_s,
16
+ port: port,
17
+ user: user.to_s,
18
+ password: password.to_s,
19
+ }
20
+ end
21
+
22
+ def port
23
+ @port ||= 22
24
+ val = @port.to_s.to_i
25
+ (1...65536).include?(val) ? val : 22
26
+ end
27
+
28
+ def save
29
+ SystemConfig.set :self_update, to_h, true
30
+ end
31
+
32
+ def SelfUpdateConfig.load
33
+ SelfUpdateConfig.new SystemConfig.get(:self_update)
34
+ end
35
+
36
+ end
37
+ end