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,38 @@
1
+ # :enddoc:
2
+
3
+ # alter the configuration class slightly.
4
+ Rails::Application::Configuration.class_eval do
5
+
6
+ # redefine the 'database_configuration' method to provide defaults for test & development.
7
+ alias :barkest_core_original_database_configuration :database_configuration
8
+
9
+ def database_configuration
10
+ begin
11
+ barkest_core_original_database_configuration
12
+ rescue => e
13
+ # unless we are simply missing the 'database.yml' file, re-raise the error.
14
+ # Also raise the error if we are not in test or development. The file
15
+ # really should be supplied for production.
16
+ raise e unless e.inspect.include?('No such file -') && (Rails.env.test? || Rails.env.development?)
17
+
18
+ default =
19
+ {
20
+ 'adapter' => 'sqlite3',
21
+ 'pool' => 5,
22
+ 'timeout' => 5000
23
+ }
24
+
25
+ Rails.logger.warn "Providing default database configuration for #{Rails.env} environment." unless Rails.logger.nil?
26
+ puts "\nWARNING: Default database connection in use.\n" if Rails.env.test? || Rails.logger.nil?
27
+
28
+ # only provide defaults for development and test.
29
+ {
30
+ 'test' => default.merge(database: 'db/test.sqlite3'),
31
+ 'development' => default.merge(database: 'db/development.sqlite3')
32
+ }
33
+ end
34
+ end
35
+
36
+
37
+
38
+ end
@@ -0,0 +1,50 @@
1
+ # a minor extension for the application class.
2
+ Rails::Application.class_eval do
3
+
4
+ ##
5
+ # Is the rails server running?
6
+ def running?
7
+ path = File.join(Rails.root, 'tmp/pids/server.pid')
8
+ pid = File.exist?(path) ? File.read(path).to_i : -1
9
+ server_running = true
10
+ begin
11
+ Process.getpgid pid
12
+ rescue Errno::ESRCH
13
+ server_running = false
14
+ end
15
+ server_running
16
+ end
17
+
18
+ ##
19
+ # Gets the application name.
20
+ #
21
+ # This should be overridden in your +application.rb+ file.
22
+ def app_name
23
+ 'BarkerEST'
24
+ end
25
+
26
+ ##
27
+ # Gets the application version.
28
+ #
29
+ # This should be overridden in your +application.rb+ file.
30
+ def app_version
31
+ '0.0.1'
32
+ end
33
+
34
+ ##
35
+ # Gets the company responsible for the application.
36
+ #
37
+ # This should be overridden in your +application.rb+ file.
38
+ def app_company
39
+ 'BarkerEST'
40
+ end
41
+
42
+ ##
43
+ # Gets the application name and version.
44
+ #
45
+ # This can be overridden in your +application.rb+ file if you want a different behavior.
46
+ def app_info
47
+ "#{app_name} v#{app_version}"
48
+ end
49
+
50
+ end
@@ -0,0 +1,157 @@
1
+ require 'axlsx'
2
+ require 'axlsx_rails'
3
+
4
+ # :nodoc:
5
+ module Axlsx
6
+
7
+ ##
8
+ # The Package class is used to manage the Excel file in memory.
9
+ class Package
10
+
11
+ ##
12
+ # Creates a simple workbook with one sheet.
13
+ #
14
+ # Predefines multiple styles that can be used to format cells.
15
+ # The +sheet+ and +styles+ are yielded to the provided block.
16
+ #
17
+ # See Axlsx::Workbook#predefined_styles for a list of predefined styles.
18
+ #
19
+ def simple(name = nil)
20
+ workbook.add_worksheet(name: name || 'Sheet 1') do |sheet|
21
+ yield sheet, workbook.predefined_styles if block_given?
22
+ sheet.add_row
23
+ end
24
+ end
25
+
26
+ alias :barkest_core_original_workbook :workbook
27
+
28
+ # :nodoc:
29
+ def workbook
30
+ @workbook ||= Workbook.new
31
+ @workbook.package = self
32
+ yield @workbook if block_given?
33
+ @workbook
34
+ end
35
+
36
+ end
37
+
38
+ ##
39
+ # The Workbook class is used to manage the Excel file in memory.
40
+ class Workbook
41
+
42
+ attr_accessor :package
43
+
44
+ ##
45
+ # Gets the predefined style list.
46
+ #
47
+ # The +predefined_styles+ hash contains :bold, :date, :float, :integer, :percent, :currency, :text, :wrapped, and :normal
48
+ # styles for you to use.
49
+ #
50
+ def predefined_styles
51
+ @predefined_styles ||=
52
+ begin
53
+ tmp = {}
54
+ styles do |s|
55
+ tmp = {
56
+ bold: s.add_style(b: true, alignment: { vertical: :top }),
57
+ date: s.add_style(format_code: 'mm/dd/yyyy', alignment: { vertical: :top }),
58
+ float: s.add_style(format_code: '#,##0.00', alignment: { vertical: :top }),
59
+ integer: s.add_style(format_code: '#,##0', alignment: { vertical: :top }),
60
+ percent: s.add_style(num_fmt: 9, alignment: { vertical: :top }),
61
+ currency: s.add_style(num_fmt: 7, alignment: { vertical: :top }),
62
+ text: s.add_style(format_code: '@', alignment: { vertical: :top }),
63
+ wrapped: s.add_style(alignment: { wrap_text: true, vertical: :top }),
64
+ normal: s.add_style(alignment: { vertical: :top })
65
+ }
66
+ end
67
+ tmp
68
+ end
69
+ end
70
+ end
71
+
72
+
73
+ # :nodoc:
74
+ class Cell
75
+
76
+ alias :barkest_core_original_cast_value :cast_value
77
+
78
+ # Fix the conversion of Date/Time values.
79
+ # :nodoc:
80
+ def cast_value(v)
81
+ return nil if v.nil?
82
+ if @type == :date
83
+ self.style = STYLE_DATE if self.style == 0
84
+ v
85
+ elsif (@type == :time && v.is_a?(Time)) || (@type == :time && v.respond_to?(:to_time))
86
+ self.style = STYLE_DATE if self.style == 0
87
+ # one simple little fix. I DO NOT WANT TIME IN LOCAL TIME!
88
+ unless v.is_a?(Time)
89
+ v = v.respond_to?(:to_time) ? v.to_time : v
90
+ end
91
+ v
92
+ elsif @type == :float
93
+ v.to_f
94
+ elsif @type == :integer
95
+ v.to_i
96
+ elsif @type == :boolean
97
+ v ? 1 : 0
98
+ elsif @type == :iso_8601
99
+ #consumer is responsible for ensuring the iso_8601 format when specifying this type
100
+ v
101
+ else
102
+ @type = :string
103
+ # TODO find a better way to do this as it accounts for 30% of
104
+ # processing time in benchmarking...
105
+ Axlsx::trust_input ? v.to_s : ::CGI.escapeHTML(v.to_s)
106
+ end
107
+ end
108
+ end
109
+
110
+ ##
111
+ # The Worksheet class is used to manage the Excel file in memory.
112
+ class Worksheet
113
+
114
+ ##
115
+ # Adds a row to the worksheet with combined data.
116
+ #
117
+ # Currently we support specifying the +values+, +styles+, and +types+ using this method.
118
+ #
119
+ # The +row_data+ value should be an array of arrays.
120
+ # Each subarray represents a value in the row with up to three values specifying the +value+, +style+, and +type+.
121
+ # Value is the only item required.
122
+ # [['Value 1', :bold, :string], ['Value 2'], ['Value 3', nil, :string]]
123
+ #
124
+ # In fact, if a subarray is replaced by a value, it is treated the same as an array only containing that value.
125
+ # [['Value 1', :bold, :string], 'Value 2', ['Value 3', nil, :string]]
126
+ #
127
+ # The +keys+ parameter defines the location of the data elements within the sub arrays.
128
+ # The default would be [ :value, :style, :type ]. If your array happens to have additional data or data arranged
129
+ # in a different format, you can set this to anything you like to get the method to process your data
130
+ # appropriately.
131
+ # keys = [ :ignored, :value, :ignored, :ignored, :style, :ignored, :type ]
132
+ #
133
+ # Styles can be specified as a symbol to use the predefined styles, or as a style object you created.
134
+ #
135
+ def add_combined_row(row_data, keys = [ :value, :style, :type ])
136
+ val_index = keys.index(:value) || keys.index('value')
137
+ style_index = keys.index(:style) || keys.index('style')
138
+ type_index = keys.index(:type) || keys.index('type')
139
+
140
+ raise ArgumentError.new('Missing :value key') unless val_index
141
+ values = row_data.map{|v| v.is_a?(Array) ? v[val_index] : v }
142
+ styles = style_index ? row_data.map{ |v| v.is_a?(Array) ? v[style_index] : nil } : []
143
+ types = type_index ? row_data.map{ |v| v.is_a?(Array) ? v[type_index] : nil } : []
144
+
145
+ # allows specifying the style as just a symbol.
146
+ styles.each_with_index do |style,index|
147
+ if style.is_a?(String) || style.is_a?(Symbol)
148
+ styles[index] = workbook.predefined_styles[style.to_sym]
149
+ end
150
+ end
151
+
152
+ add_row values, style: styles, types: types
153
+ end
154
+
155
+ end
156
+
157
+ end
@@ -0,0 +1,107 @@
1
+ require 'active_record/fixtures'
2
+
3
+ # Add a few enhancements to FixtureSet that provide a method to define load and purge orders.
4
+ ActiveRecord::FixtureSet.class_eval do
5
+
6
+ class << self
7
+ alias :barkest_core_original_create_fixtures :create_fixtures
8
+ end
9
+
10
+ ##
11
+ # Determines the fixtures that will be loaded first.
12
+ #
13
+ # Arguments can either be just table names or a hash of table names with indexes.
14
+ # If just table names, then the tables are inserted at the end of the list.
15
+ # If a hash, then the value is the index you want the table to appear in the load list.
16
+ #
17
+ # BarkestCore tables are pre-indexed to load before any other tables.
18
+ #
19
+ # Usage:
20
+ # ActiveRecord::FixtureSet.load_first :table_1, :table_2
21
+ # ActiveRecord::FixtureSet.load_first :table_1 => 0, :table_2 => 1
22
+ def self.load_first(*args)
23
+ priority_list = %w(access_groups users)
24
+
25
+ @load_first ||= priority_list
26
+
27
+ unless args.blank?
28
+ args.each do |arg|
29
+ if arg.is_a?(Hash)
30
+ arg.each do |fix,order|
31
+ fix = fix.to_s
32
+ order += priority_list.length
33
+ if order >= @load_first.length
34
+ @load_first << fix unless @load_first.include?(fix)
35
+ else
36
+ @load_first.insert(order, fix) unless @load_first.include?(fix)
37
+ end
38
+ end
39
+ else
40
+ fix = arg.to_s
41
+ @load_first << fix unless @load_first.include?(fix)
42
+ end
43
+ end
44
+ end
45
+
46
+ @load_first
47
+ end
48
+
49
+ ##
50
+ # Determines the fixtures that will purged first.
51
+ #
52
+ # Arguments can either be just table names or a hash of table names with indexes.
53
+ # If just table names then the tables are inserted at the beginning of the list.
54
+ # If a hash, then the value is the index you want the table to appear in the purge list.
55
+ #
56
+ # BarkestCore tables are pre-indexed to be purged after any other tables added to this list.
57
+ #
58
+ # Usage:
59
+ # ActiveRecord::FixtureSet.purge_first :table_1, :table_2
60
+ # ActiveRecord::FixtureSet.purge_first :table_1 => 0, :table_2 => 1
61
+ def self.purge_first(*args)
62
+ priority_list = %w(ldap_access_groups access_group_user_members access_group_group_members user_login_histories users access_groups)
63
+
64
+ @purge_first ||= priority_list
65
+
66
+ unless args.blank?
67
+ args.reverse.each do |arg|
68
+ if arg.is_a?(Hash)
69
+ arg.each do |fix,order|
70
+ fix = fix.to_s
71
+ if order <= 0
72
+ @purge_first.insert(0, fix) unless @purge_first.include?(fix)
73
+ elsif order >= @purge_first.length - priority_list.length
74
+ @purge_first.insert(@purge_first.length - priority_list.length, fix) unless @purge_first.include?(fix)
75
+ else
76
+ @purge_first.insert(order, fix) unless @purge_first.include?(fix)
77
+ end
78
+ end
79
+ else
80
+ fix = arg.to_s
81
+ @purge_first.insert(0, fix) unless @purge_first.include?(fix)
82
+ end
83
+ end
84
+ end
85
+
86
+ @purge_first
87
+ end
88
+
89
+ # :nodoc:
90
+ def self.create_fixtures(fixtures_dir, fixture_set_names, *args)
91
+
92
+ # delete all fixtures that have been added to purge_first
93
+ purge_first.each do |fix|
94
+ fix = const_get(fix.singularize.camelcase)
95
+ if fix && fix.respond_to?(:delete_all)
96
+ fix.delete_all
97
+ end
98
+ end
99
+
100
+ reset_cache
101
+
102
+ # if we are adding any of the prioritized fixtures, make them go first, followed by any other fixtures.
103
+ fixture_set_names = load_first & fixture_set_names | fixture_set_names
104
+
105
+ barkest_core_original_create_fixtures fixtures_dir, fixture_set_names, *args
106
+ end
107
+ end
@@ -0,0 +1,271 @@
1
+ require 'io/console'
2
+ require 'rails/generators'
3
+
4
+ Rails::Generators::Base.class_eval do
5
+
6
+ protected
7
+
8
+ def erb_read(file)
9
+ ERB.new(File.read(file), 0).result
10
+ end
11
+
12
+ def tell(message, color = nil)
13
+ open = ''
14
+ close = ''
15
+ if color
16
+ open = "\033[0"
17
+ close = "\033[0m"
18
+ open += case color.to_sym
19
+ when :black
20
+ ';30'
21
+ when :dark_grey, :dark_gray
22
+ ';30;1'
23
+ when :red, :dark_red
24
+ ';31'
25
+ when :bright_red
26
+ ';31;1'
27
+ when :green, :dark_green
28
+ ';32'
29
+ when :bright_green
30
+ ';32;1'
31
+ when :gold, :dark_yellow
32
+ ';33'
33
+ when :yellow
34
+ ';33;1'
35
+ when :dark_blue
36
+ ';34'
37
+ when :blue
38
+ ';34;1'
39
+ when :dark_magenta, :violet, :purple
40
+ ';35'
41
+ when :magenta, :pink
42
+ ';35;1'
43
+ when :dark_cyan, :teal
44
+ ';36'
45
+ when :cyan, :aqua
46
+ ';36;1'
47
+ when :light_gray, :gray, :light_grey, :grey
48
+ ';37'
49
+ when :white
50
+ ';37;1'
51
+ when :bold
52
+ ';1'
53
+ else
54
+ ''
55
+ end + 'm'
56
+
57
+ end
58
+
59
+ puts open + message + close unless options.quiet?
60
+ end
61
+
62
+ def ask_for_bool(question, default = false)
63
+ return default if options.quiet?
64
+
65
+ print "#{trimq(question)} [#{default ? 'Y/n' : 'y/N'}]? "
66
+
67
+ if options.force?
68
+ puts default ? 'Y' : 'N'
69
+ return default
70
+ end
71
+
72
+ answer = STDIN.gets.strip.upcase[0]
73
+
74
+ return default if answer.blank?
75
+
76
+ answer == 'Y'
77
+ end
78
+
79
+ def ask_for_string(question, default = '', valid = nil)
80
+ return default if options.quiet?
81
+
82
+ loop do
83
+ print "#{trimq(question)} [#{default}] (. to clear)? "
84
+
85
+ if options.force?
86
+ puts default.to_s
87
+ return default
88
+ end
89
+
90
+ answer = STDIN.gets.strip
91
+
92
+ return '' if answer == '.'
93
+ return default if answer.blank?
94
+
95
+ if valid && valid.respond_to?(:call)
96
+ return answer if valid.call(answer)
97
+ elsif valid && valid.respond_to?(:include?)
98
+ return answer if valid.include?(answer)
99
+ else
100
+ return answer
101
+ end
102
+
103
+ puts "Entered value (#{answer}) is invalid."
104
+ unless valid.respond_to?(:call)
105
+ puts "Valid values are #{valid.inspect}."
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ def ask_for_int(question, default = 0, valid = nil)
112
+ return default if options.quiet?
113
+
114
+ loop do
115
+ print "#{question} [#{default}]? "
116
+
117
+ if options.force?
118
+ puts default.to_s
119
+ return default
120
+ end
121
+
122
+ answer = STDIN.gets.strip
123
+
124
+ return default if answer.blank?
125
+
126
+ answer = answer.to_i
127
+
128
+ if valid && valid.respond_to?(:call)
129
+ return answer if valid.call(answer)
130
+ elsif valid && valid.respond_to?(:include?)
131
+ return answer if valid.include?(answer)
132
+ else
133
+ return answer
134
+ end
135
+
136
+ puts "Entered value (#{answer}) is invalid."
137
+ unless valid.respond_to?(:call)
138
+ puts "Valid values are #{valid.inspect}."
139
+ end
140
+ end
141
+ end
142
+
143
+ def ask_for_secret(question, default = '')
144
+ return default if options.quiet?
145
+
146
+ print "#{question} [enter to keep, . to clear]: "
147
+
148
+ if options.force?
149
+ puts ''
150
+ return default
151
+ end
152
+
153
+ loop do
154
+ answer1 = STDIN.noecho(&:gets).strip
155
+ puts ''
156
+
157
+ return '' if answer1 == '.'
158
+ return default if answer1.blank?
159
+
160
+ print 'Enter again to confirm: '
161
+ answer2 = STDIN.noecho(&:gets).strip
162
+ puts ''
163
+
164
+ return answer1 if answer2 == answer1
165
+
166
+ puts 'Confirmation does not match!'
167
+ print 'Please try again: '
168
+ end
169
+ end
170
+
171
+ def configure_the(what, config_file, attributes, hash_key, defaults, *optional_levels)
172
+ tell '=' * 79
173
+ if ask_for_bool("Would you like to configure #{what.pluralize}?", true)
174
+ current_config = File.exist?(config_file) ? YAML.load_file(config_file) : {}
175
+ levels = ([''] + (optional_levels || [])).uniq
176
+ levels.each do |level|
177
+ if level.blank? || ask_for_bool("Would you like to configure a #{level} #{what.singularize} configuration?", false)
178
+ current_config[level] ||= {} unless level.blank?
179
+
180
+ env_list = %w(test development production)
181
+
182
+ unless level.blank?
183
+ level,_,envs = level.partition('[')
184
+ unless envs.blank?
185
+ env_list = envs.partition(']').first.strip.split(' ')
186
+ end
187
+ end
188
+
189
+ last_env = nil
190
+ env_list.each do |env|
191
+ tell "Configure the '#{level.blank? ? '' : (level + ':')}#{env}' environment."
192
+ tell '-' * 79
193
+
194
+ cur_env = level.blank? ? env : "#{level}_#{env}"
195
+
196
+ current = (current_config[cur_env] || {}).dup
197
+
198
+ if current.blank? || ask_for_bool("Do you want to make changes to the '#{cur_env}' environment?", false)
199
+ if last_env
200
+ if ask_for_bool("Would you like to use the configuration from the '#{last_env}' environment to start?", false)
201
+ current = (current_config[last_env] || {}).dup
202
+ end
203
+ end
204
+ current = input_attributes(current, attributes, defaults, hash_key)
205
+ end
206
+
207
+ current_config[cur_env] = current
208
+
209
+ tell '-' * 79
210
+
211
+ last_env = cur_env
212
+ end
213
+ end
214
+ end
215
+
216
+ perform "> creating '#{config_file}'..." do
217
+ File.write config_file, current_config.to_yaml
218
+ end
219
+ end
220
+ end
221
+
222
+ def perform(message, &block)
223
+ tell message + (options.pretend? ? ' [pretend]' : ''), :teal
224
+ block.call unless options.pretend?
225
+ end
226
+
227
+ def input_attributes(target_hash, attribute_list, defaults, hash_key = nil)
228
+ attribute_list.each do |data|
229
+ if data.is_a?(Hash)
230
+ if hash_key && target_hash[hash_key] && data[target_hash[hash_key]].is_a?(Array)
231
+ target_hash = input_attributes(target_hash, data[target_hash[hash_key]], defaults, hash_key)
232
+ end
233
+ elsif data.is_a?(Array)
234
+ field,asker,valid,label,default_override = data
235
+ label ||= field
236
+ def_val = if target_hash[field].nil?
237
+ if default_override.nil?
238
+ defaults[field]
239
+ else
240
+ default_override
241
+ end
242
+ else
243
+ target_hash[field]
244
+ end
245
+
246
+ answer = if valid
247
+ send(asker, label, def_val, valid)
248
+ else
249
+ send(asker, label, def_val)
250
+ end
251
+
252
+ target_hash[field] = answer
253
+ end
254
+ end
255
+ target_hash
256
+ end
257
+
258
+
259
+ private
260
+
261
+ def trimq(question)
262
+ question = question.to_s.strip
263
+ if question[-1] == '?' || question[-1] == ':'
264
+ question = question[0...-1]
265
+ end
266
+ question
267
+ end
268
+
269
+
270
+
271
+ end