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.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +254 -0
- data/MIT-LICENSE +20 -0
- data/README.md +364 -0
- data/Rakefile +37 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Bold.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-BoldItalic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Italic.ttf +0 -0
- data/app/assets/fonts/barkest_core/ArchivoNarrow-Regular.ttf +0 -0
- data/app/assets/images/barkest_core/.keep +0 -0
- data/app/assets/images/barkest_core/barcode-B.svg +181 -0
- data/app/assets/javascripts/barkest_core/.keep +0 -0
- data/app/assets/javascripts/barkest_core/application.js +22 -0
- data/app/assets/javascripts/barkest_core/bootstrap-datepicker.js +1800 -0
- data/app/assets/javascripts/barkest_core/field_init.js +7 -0
- data/app/assets/javascripts/barkest_core/jquery.doubleScroll.js +112 -0
- data/app/assets/javascripts/barkest_core/masked_edit.js +25 -0
- data/app/assets/javascripts/barkest_core/system_status.js.erb +201 -0
- data/app/assets/stylesheets/barkest_core/.keep +0 -0
- data/app/assets/stylesheets/barkest_core/application.css +17 -0
- data/app/assets/stylesheets/barkest_core/custom.css.scss +264 -0
- data/app/assets/stylesheets/barkest_core/datepicker3.css +790 -0
- data/app/controllers/.keep +0 -0
- data/app/controllers/access_groups_controller.rb +74 -0
- data/app/controllers/account_activations_controller.rb +29 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/barkest_core/application_controller_base.rb +113 -0
- data/app/controllers/barkest_core/engine_controller_base.rb +15 -0
- data/app/controllers/barkest_core/testsub_controller.rb +21 -0
- data/app/controllers/contact_controller.rb +32 -0
- data/app/controllers/log_view_controller.rb +31 -0
- data/app/controllers/password_resets_controller.rb +126 -0
- data/app/controllers/sessions_controller.rb +64 -0
- data/app/controllers/status_controller.rb +150 -0
- data/app/controllers/system_config_controller.rb +238 -0
- data/app/controllers/system_update_controller.rb +164 -0
- data/app/controllers/test_access_controller.rb +44 -0
- data/app/controllers/test_report_controller.rb +75 -0
- data/app/controllers/users_controller.rb +218 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/barkest_core/application_helper.rb +134 -0
- data/app/helpers/barkest_core/form_helper.rb +469 -0
- data/app/helpers/barkest_core/html_helper.rb +70 -0
- data/app/helpers/barkest_core/misc_helper.rb +68 -0
- data/app/helpers/barkest_core/pdf_helper.rb +180 -0
- data/app/helpers/barkest_core/recaptcha_helper.rb +115 -0
- data/app/helpers/barkest_core/sessions_helper.rb +94 -0
- data/app/helpers/barkest_core/status_helper.rb +118 -0
- data/app/helpers/barkest_core/users_helper.rb +32 -0
- data/app/mailers/.keep +0 -0
- data/app/mailers/application_mailer.rb +5 -0
- data/app/mailers/barkest_core/application_mailer_base.rb +30 -0
- data/app/mailers/barkest_core/contact_form.rb +20 -0
- data/app/mailers/barkest_core/user_mailer.rb +44 -0
- data/app/models/.keep +0 -0
- data/app/models/access_group.rb +121 -0
- data/app/models/access_group_group_member.rb +13 -0
- data/app/models/access_group_user_member.rb +11 -0
- data/app/models/barkest_core/auth_config.rb +95 -0
- data/app/models/barkest_core/authorize_failure.rb +7 -0
- data/app/models/barkest_core/contact_message.rb +37 -0
- data/app/models/barkest_core/database_config.rb +223 -0
- data/app/models/barkest_core/db_table.rb +21 -0
- data/app/models/barkest_core/email_config.rb +132 -0
- data/app/models/barkest_core/global_status.rb +267 -0
- data/app/models/barkest_core/log_entry.rb +101 -0
- data/app/models/barkest_core/log_view_options.rb +51 -0
- data/app/models/barkest_core/ms_sql_db_definition.rb +441 -0
- data/app/models/barkest_core/ms_sql_definition.rb +221 -0
- data/app/models/barkest_core/ms_sql_function.rb +423 -0
- data/app/models/barkest_core/not_logged_in.rb +7 -0
- data/app/models/barkest_core/pdf_table_builder.rb +407 -0
- data/app/models/barkest_core/self_update_config.rb +37 -0
- data/app/models/barkest_core/user_alert.rb +29 -0
- data/app/models/barkest_core/user_alert_generators.rb +58 -0
- data/app/models/barkest_core/user_manager.rb +404 -0
- data/app/models/barkest_core/work_path.rb +74 -0
- data/app/models/disable_user.rb +18 -0
- data/app/models/ldap_access_group.rb +15 -0
- data/app/models/system_config.rb +99 -0
- data/app/models/user.rb +405 -0
- data/app/models/user_login_history.rb +11 -0
- data/app/views/.keep +0 -0
- data/app/views/access_groups/_form.html.erb +19 -0
- data/app/views/access_groups/edit.html.erb +2 -0
- data/app/views/access_groups/index.html.erb +32 -0
- data/app/views/access_groups/new.html.erb +2 -0
- data/app/views/access_groups/show.html.erb +4 -0
- data/app/views/barkest_core/contact_form/contact.html.erb +16 -0
- data/app/views/barkest_core/contact_form/contact.text.erb +13 -0
- data/app/views/barkest_core/testsub/_links.html.erb +5 -0
- data/app/views/barkest_core/testsub/page1.html.erb +3 -0
- data/app/views/barkest_core/testsub/page2.html.erb +2 -0
- data/app/views/barkest_core/testsub/page3.html.erb +2 -0
- data/app/views/barkest_core/user_mailer/account_activation.html.erb +7 -0
- data/app/views/barkest_core/user_mailer/account_activation.text.erb +6 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.html.erb +3 -0
- data/app/views/barkest_core/user_mailer/invalid_password_reset.text.erb +5 -0
- data/app/views/barkest_core/user_mailer/password_reset.html.erb +8 -0
- data/app/views/barkest_core/user_mailer/password_reset.text.erb +7 -0
- data/app/views/contact/index.html.erb +24 -0
- data/app/views/layouts/_footer_copyright.html.erb +1 -0
- data/app/views/layouts/_menu_admin.html.erb +5 -0
- data/app/views/layouts/_menu_anon.html.erb +0 -0
- data/app/views/layouts/_menu_auth.html.erb +3 -0
- data/app/views/layouts/_menu_footer.html.erb +1 -0
- data/app/views/layouts/_nav_logo.html.erb +1 -0
- data/app/views/layouts/application.html.erb +2 -0
- data/app/views/layouts/barkest_core/_application.html.erb +24 -0
- data/app/views/layouts/barkest_core/_footer.html.erb +18 -0
- data/app/views/layouts/barkest_core/_header.html.erb +38 -0
- data/app/views/layouts/barkest_core/_html_mailer.html.erb +11 -0
- data/app/views/layouts/barkest_core/_menu_account.html.erb +14 -0
- data/app/views/layouts/barkest_core/_menu_sample.html.erb +1 -0
- data/app/views/layouts/barkest_core/_messages.html.erb +4 -0
- data/app/views/layouts/barkest_core/_shim.html.erb +4 -0
- data/app/views/layouts/barkest_core/_subheader.html.erb +1 -0
- data/app/views/layouts/barkest_core/_text_mailer.text.erb +4 -0
- data/app/views/layouts/mailer.html.erb +1 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/views/log_view/index.html.erb +100 -0
- data/app/views/password_resets/edit.html.erb +20 -0
- data/app/views/password_resets/new.html.erb +14 -0
- data/app/views/sessions/new.html.erb +27 -0
- data/app/views/shared/_error_messages.html.erb +29 -0
- data/app/views/shared/_generic_user_alert.html.erb +4 -0
- data/app/views/status/current.html.erb +34 -0
- data/app/views/status/test.html.erb +50 -0
- data/app/views/system_config/index.html.erb +25 -0
- data/app/views/system_config/show_auth.html.erb +28 -0
- data/app/views/system_config/show_database.html.erb +36 -0
- data/app/views/system_config/show_email.html.erb +21 -0
- data/app/views/system_config/show_self_update.html.erb +13 -0
- data/app/views/system_update/index.html.erb +31 -0
- data/app/views/system_update/new.html.erb +2 -0
- data/app/views/test_access/allow_anon.html.erb +2 -0
- data/app/views/test_access/require_admin.html.erb +2 -0
- data/app/views/test_access/require_group_x.html.erb +2 -0
- data/app/views/test_access/require_user.html.erb +2 -0
- data/app/views/test_report/index.csv.csvrb +23 -0
- data/app/views/test_report/index.html.erb +6 -0
- data/app/views/test_report/index.pdf.prawn +50 -0
- data/app/views/test_report/index.xlsx.axlsx +28 -0
- data/app/views/users/_user.html.erb +57 -0
- data/app/views/users/_user_details.html.erb +15 -0
- data/app/views/users/_user_details_for_list.html.erb +1 -0
- data/app/views/users/_user_form.html.erb +13 -0
- data/app/views/users/disable_confirm.html.erb +19 -0
- data/app/views/users/edit.html.erb +15 -0
- data/app/views/users/index.html.erb +9 -0
- data/app/views/users/new.html.erb +10 -0
- data/app/views/users/show.html.erb +46 -0
- data/bin/rails +12 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20160617172539_create_access_groups.rb +10 -0
- data/db/migrate/20160617172725_create_users.rb +26 -0
- data/db/migrate/20160617172833_create_user_login_histories.rb +12 -0
- data/db/migrate/20160622151720_create_access_group_user_members.rb +9 -0
- data/db/migrate/20160622151925_create_access_group_group_members.rb +9 -0
- data/db/migrate/20160701005706_create_ldap_access_groups.rb +11 -0
- data/db/migrate/20161108155029_create_system_configs.rb +11 -0
- data/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/db/seeds.rb +53 -0
- data/lib/barkest_core/concerns/association_with_defaults.rb +55 -0
- data/lib/barkest_core/concerns/boolean_parser.rb +88 -0
- data/lib/barkest_core/concerns/date_parser.rb +181 -0
- data/lib/barkest_core/concerns/email_tester.rb +55 -0
- data/lib/barkest_core/concerns/encrypted_fields.rb +156 -0
- data/lib/barkest_core/concerns/named_model.rb +73 -0
- data/lib/barkest_core/concerns/number_parser.rb +145 -0
- data/lib/barkest_core/concerns/utc_conversion.rb +60 -0
- data/lib/barkest_core/engine.rb +105 -0
- data/lib/barkest_core/extensions/active_record_extensions.rb +120 -0
- data/lib/barkest_core/extensions/application_configuration_extensions.rb +38 -0
- data/lib/barkest_core/extensions/application_extensions.rb +50 -0
- data/lib/barkest_core/extensions/axlsx_extenstions.rb +157 -0
- data/lib/barkest_core/extensions/fixture_set_extensions.rb +107 -0
- data/lib/barkest_core/extensions/generator_extensions.rb +271 -0
- data/lib/barkest_core/extensions/main_app_extensions.rb +35 -0
- data/lib/barkest_core/extensions/prawn_document_extensions.rb +367 -0
- data/lib/barkest_core/extensions/prawn_table_extensions.rb +131 -0
- data/lib/barkest_core/extensions/router_extensions.rb +106 -0
- data/lib/barkest_core/extensions/simple_formatter_extensions.rb +66 -0
- data/lib/barkest_core/extensions/test_case_extensions.rb +348 -0
- data/lib/barkest_core/extensions/time_extensions.rb +164 -0
- data/lib/barkest_core/handlers/csv_handler.rb +30 -0
- data/lib/barkest_core/version.rb +3 -0
- data/lib/barkest_core.rb +324 -0
- data/lib/generators/barkest/install_generator.rb +102 -0
- data/lib/generators/barkest_core/actions/01_patch_application_controller.rb +55 -0
- data/lib/generators/barkest_core/actions/02_patch_application_mailer.rb +56 -0
- data/lib/generators/barkest_core/actions/03_patch_assets.rb +62 -0
- data/lib/generators/barkest_core/actions/04_patch_layouts.rb +36 -0
- data/lib/generators/barkest_core/actions/05_patch_routes.rb +93 -0
- data/lib/generators/barkest_core/actions/06_patch_seeds.rb +60 -0
- data/lib/generators/barkest_core/actions/07_copy_migrations.rb +51 -0
- data/lib/generators/barkest_core/actions/08_configure_database.rb +52 -0
- data/lib/generators/barkest_core/actions/09_configure_secrets.rb +29 -0
- data/lib/generators/barkest_core/actions/99_patch_gitignore.rb +57 -0
- data/lib/generators/barkest_core/install_generator.rb +17 -0
- data/test/barkest_core_test.rb +83 -0
- data/test/controllers/access_groups_controller_test.rb +53 -0
- data/test/controllers/contact_controller_test.rb +10 -0
- data/test/controllers/sessions_controller_test.rb +10 -0
- data/test/controllers/users_controller_test.rb +10 -0
- data/test/dummy/.gitignore +10 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +14 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/mailers/application_mailer.rb +3 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/app/views/system_config/show_fake.html.erb +3 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +27 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +47 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/db_updater_ext.rb +33 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/sys_config_ext.rb +12 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/schema.rb +95 -0
- data/test/dummy/db/seeds/barkest_core_01_create_users.rb +42 -0
- data/test/dummy/db/seeds.rb +51 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/sql/my_test_view.sql +3 -0
- data/test/fixtures/access_groups.yml +21 -0
- data/test/fixtures/users.yml +71 -0
- data/test/helpers/barkest_core/sessions_helper_test.rb +22 -0
- data/test/integration/access_group_mgmt_test.rb +33 -0
- data/test/integration/access_test.rb +24 -0
- data/test/integration/account_activations_access_test.rb +12 -0
- data/test/integration/contact_test.rb +98 -0
- data/test/integration/extra_partial_test.rb +41 -0
- data/test/integration/log_view_access_test.rb +12 -0
- data/test/integration/password_resets_test.rb +101 -0
- data/test/integration/reports_test.rb +53 -0
- data/test/integration/status_access_test.rb +27 -0
- data/test/integration/system_config_access_test.rb +24 -0
- data/test/integration/system_update_access_test.rb +19 -0
- data/test/integration/users_access_test.rb +34 -0
- data/test/integration/users_edit_test.rb +178 -0
- data/test/integration/users_index_test.rb +62 -0
- data/test/integration/users_login_test.rb +67 -0
- data/test/integration/users_signup_test.rb +54 -0
- data/test/mailers/.keep +0 -0
- data/test/mailers/barkest_core/contact_form_test.rb +28 -0
- data/test/mailers/barkest_core/user_mailer_test.rb +43 -0
- data/test/mailers/previews/barkest_core/contact_form_preview.rb +17 -0
- data/test/mailers/previews/barkest_core/user_mailer_preview.rb +26 -0
- data/test/models/access_group_group_member_test.rb +28 -0
- data/test/models/access_group_test.rb +114 -0
- data/test/models/access_group_user_member_test.rb +28 -0
- data/test/models/barkest_core/auth_config_test.rb +57 -0
- data/test/models/barkest_core/bool_parser_test.rb +28 -0
- data/test/models/barkest_core/contact_message_test.rb +61 -0
- data/test/models/barkest_core/database_config_test.rb +33 -0
- data/test/models/barkest_core/date_parser_test.rb +110 -0
- data/test/models/barkest_core/email_config_test.rb +57 -0
- data/test/models/barkest_core/global_status_test.rb +50 -0
- data/test/models/barkest_core/ms_sql_db_updater_test.rb +115 -0
- data/test/models/barkest_core/ms_sql_definition_test.rb +102 -0
- data/test/models/barkest_core/ms_sql_function_test.rb +131 -0
- data/test/models/barkest_core/number_parser_test.rb +29 -0
- data/test/models/barkest_core/self_update_config_test.rb +29 -0
- data/test/models/barkest_core/user_alert_test.rb +19 -0
- data/test/models/barkest_core/user_manager_test.rb +34 -0
- data/test/models/barkest_core/work_path_test.rb +26 -0
- data/test/models/disable_user_test.rb +27 -0
- data/test/models/generic_time_test.rb +66 -0
- data/test/models/ldap_access_group_test.rb +31 -0
- data/test/models/pdf_table_builder_test.rb +6 -0
- data/test/models/system_config_test.rb +78 -0
- data/test/models/user_login_history_test.rb +37 -0
- data/test/models/user_test.rb +130 -0
- data/test/test_helper.rb +63 -0
- metadata +798 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
module BarkestCore
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
# Defines a few extensions to models that have unique names.
|
|
6
|
+
#
|
|
7
|
+
# If the unique field is named :name then you don't have to do
|
|
8
|
+
# anything more than include this file. For other unique fields
|
|
9
|
+
# simply define +UNIQUE_STRING_FIELD+ to the name of the unique
|
|
10
|
+
# field as either a symbol or a string.
|
|
11
|
+
module NamedModel
|
|
12
|
+
# :nodoc:
|
|
13
|
+
def self.included(base)
|
|
14
|
+
|
|
15
|
+
base.class_eval do
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def self.unique_string_field
|
|
20
|
+
@unique_string_field ||= const_defined?(:UNIQUE_STRING_FIELD) ? const_get(:UNIQUE_STRING_FIELD).to_sym : :name
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
public
|
|
24
|
+
|
|
25
|
+
##
|
|
26
|
+
# Locates the model from ID or name.
|
|
27
|
+
def self.get(value)
|
|
28
|
+
if value.is_a?(Numeric)
|
|
29
|
+
self.find_by(id: value)
|
|
30
|
+
elsif value.is_a?(String)
|
|
31
|
+
self.where("LOWER(\"#{table_name}\".\"#{unique_string_field}\")=?", value.downcase).first
|
|
32
|
+
elsif value.is_a?(Symbol)
|
|
33
|
+
self.where("LOWER(\"#{table_name}\".\"#{unique_string_field}\")=?", value.to_s.downcase).first ||
|
|
34
|
+
self.where("LOWER(\"#{table_name}\".\"#{unique_string_field}\")=?", value.to_s.humanize.downcase).first
|
|
35
|
+
elsif value.class == self
|
|
36
|
+
value
|
|
37
|
+
else
|
|
38
|
+
nil
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
##
|
|
43
|
+
# Gets the name of this model.
|
|
44
|
+
def to_s
|
|
45
|
+
send( self.class.unique_string_field )
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
##
|
|
49
|
+
# Tests for equality on ID or name.
|
|
50
|
+
def ==(other)
|
|
51
|
+
if other.is_a?(Numeric)
|
|
52
|
+
id == other
|
|
53
|
+
elsif other.is_a?(String)
|
|
54
|
+
send( self.class.unique_string_field ).to_s.downcase == other.downcase
|
|
55
|
+
elsif other.is_a?(Symbol)
|
|
56
|
+
[
|
|
57
|
+
other.to_s.downcase,
|
|
58
|
+
other.to_s.humanize.downcase
|
|
59
|
+
].include?(send( self.class.unique_string_field ).to_s.downcase)
|
|
60
|
+
elsif other.is_a?(self.class)
|
|
61
|
+
id == other.id
|
|
62
|
+
else
|
|
63
|
+
other = self.class.get(other)
|
|
64
|
+
other && id == other.id
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
module BarkestCore
|
|
2
|
+
##
|
|
3
|
+
# This module will add number parsing methods to a class.
|
|
4
|
+
#
|
|
5
|
+
module NumberParser
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# This regular expression should match any non-exponential numeric value.
|
|
9
|
+
NUMBER_REGEX = /^[\-\+]?(?:[0-9]+,)*[0-9]+(?:\.[0-9]+)?$/
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Parses a value for storage in a float column.
|
|
13
|
+
#
|
|
14
|
+
# Returns nil if the value is invalid.
|
|
15
|
+
# Otherwise it returns a float.
|
|
16
|
+
#
|
|
17
|
+
def self.parse_for_float_column(value)
|
|
18
|
+
value = value.to_s
|
|
19
|
+
return nil unless NUMBER_REGEX.match(value)
|
|
20
|
+
value.blank? ? nil : value.split(',').join.to_f
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# Parses a value for storage in an integer column.
|
|
25
|
+
#
|
|
26
|
+
# Returns nil if the value is invalid.
|
|
27
|
+
# Otherwise it returns an integer.
|
|
28
|
+
def self.parse_for_int_column(value)
|
|
29
|
+
value = value.to_s
|
|
30
|
+
return nil unless NUMBER_REGEX.match(value)
|
|
31
|
+
value.blank? ? nil : value.split(',').join.to_i
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
##
|
|
35
|
+
# Parses a value for use as a SQL filter.
|
|
36
|
+
#
|
|
37
|
+
# Returns 'NULL' if the value parses to nil.
|
|
38
|
+
# Otherwise returns the value.
|
|
39
|
+
#
|
|
40
|
+
def self.parse_for_float_filter(value)
|
|
41
|
+
value = parse_for_float_column(value)
|
|
42
|
+
value.nil? ? 'NULL' : value.to_s
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
##
|
|
46
|
+
# Parses a value for use as a SQL filter.
|
|
47
|
+
#
|
|
48
|
+
# Returns 'NULL' if the value parses to nil.
|
|
49
|
+
# Otherwise returns the value.
|
|
50
|
+
#
|
|
51
|
+
def self.parse_for_int_filter(value)
|
|
52
|
+
value = parse_for_int_column(value)
|
|
53
|
+
value.nil? ? 'NULL' : value.to_s
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# :nodoc:
|
|
58
|
+
def self.included(base)
|
|
59
|
+
base.class_eval do
|
|
60
|
+
|
|
61
|
+
##
|
|
62
|
+
# Parses a value for storage in a float column.
|
|
63
|
+
#
|
|
64
|
+
# Returns nil if the value is invalid.
|
|
65
|
+
# Otherwise it returns a float.
|
|
66
|
+
#
|
|
67
|
+
def self.parse_for_float_column(value)
|
|
68
|
+
BarkestCore::NumberParser.parse_for_float_column value
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
##
|
|
72
|
+
# Parses a value for storage in an integer column.
|
|
73
|
+
#
|
|
74
|
+
# Returns nil if the value is invalid.
|
|
75
|
+
# Otherwise it returns an integer.
|
|
76
|
+
def self.parse_for_int_column(value)
|
|
77
|
+
BarkestCore::NumberParser.parse_for_int_column value
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
##
|
|
81
|
+
# Parses a value for use as a SQL filter.
|
|
82
|
+
#
|
|
83
|
+
# Returns 'NULL' if the value parses to nil.
|
|
84
|
+
# Otherwise returns the value.
|
|
85
|
+
#
|
|
86
|
+
def self.parse_for_float_filter(value)
|
|
87
|
+
BarkestCore::NumberParser.parse_for_float_filter value
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
##
|
|
91
|
+
# Parses a value for use as a SQL filter.
|
|
92
|
+
#
|
|
93
|
+
# Returns 'NULL' if the value parses to nil.
|
|
94
|
+
# Otherwise returns the value.
|
|
95
|
+
#
|
|
96
|
+
def self.parse_for_int_filter(value)
|
|
97
|
+
BarkestCore::NumberParser.parse_for_int_filter value
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
protected
|
|
104
|
+
|
|
105
|
+
##
|
|
106
|
+
# Parses a value for storage in a float column.
|
|
107
|
+
#
|
|
108
|
+
# Returns nil if the value is invalid.
|
|
109
|
+
# Otherwise it returns a float.
|
|
110
|
+
#
|
|
111
|
+
def parse_for_float_column(value)
|
|
112
|
+
BarkestCore::NumberParser.parse_for_float_column value
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
##
|
|
116
|
+
# Parses a value for storage in an integer column.
|
|
117
|
+
#
|
|
118
|
+
# Returns nil if the value is invalid.
|
|
119
|
+
# Otherwise it returns an integer.
|
|
120
|
+
def parse_for_int_column(value)
|
|
121
|
+
BarkestCore::NumberParser.parse_for_int_column value
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
##
|
|
125
|
+
# Parses a value for use as a SQL filter.
|
|
126
|
+
#
|
|
127
|
+
# Returns 'NULL' if the value parses to nil.
|
|
128
|
+
# Otherwise returns the value.
|
|
129
|
+
#
|
|
130
|
+
def parse_for_float_filter(value)
|
|
131
|
+
BarkestCore::NumberParser.parse_for_float_filter value
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
##
|
|
135
|
+
# Parses a value for use as a SQL filter.
|
|
136
|
+
#
|
|
137
|
+
# Returns 'NULL' if the value parses to nil.
|
|
138
|
+
# Otherwise returns the value.
|
|
139
|
+
#
|
|
140
|
+
def parse_for_int_filter(value)
|
|
141
|
+
BarkestCore::NumberParser.parse_for_int_filter value
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
module UtcConversion
|
|
5
|
+
class UtcConverter < DelegateClass(ActiveRecord::Type::Value)
|
|
6
|
+
include ActiveRecord::Type::Decorator
|
|
7
|
+
|
|
8
|
+
def type_cast_from_database(value)
|
|
9
|
+
convert_to_utc(value)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def type_cast_from_user(value)
|
|
13
|
+
convert_to_utc(value)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def convert_to_utc(value)
|
|
17
|
+
if value.is_a?(Array)
|
|
18
|
+
value.map { |v| convert_to_utc(v) }
|
|
19
|
+
else
|
|
20
|
+
Time.utc_parse(value) rescue nil
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
extend ActiveSupport::Concern
|
|
27
|
+
|
|
28
|
+
included do
|
|
29
|
+
self.time_zone_aware_attributes = false if self.respond_to?(:time_zone_aware_attributes=)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module ClassMethods
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def inherited(subclass)
|
|
36
|
+
subclass.class_eval do
|
|
37
|
+
matcher = ->(name, type) { create_utc_conversion_attribute?(name, type) }
|
|
38
|
+
decorate_matching_attribute_types(matcher, :_utc_conversion) do |type|
|
|
39
|
+
UtcConverter.new(type)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
super
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# disable TimeZoneConversion
|
|
46
|
+
def create_time_zone_conversion_attribute?(name, cast_type)
|
|
47
|
+
false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# enable UtcConversion
|
|
51
|
+
def create_utc_conversion_attribute?(name, cast_type)
|
|
52
|
+
cast_type.type == :datetime
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# add it to the base model.
|
|
60
|
+
ActiveRecord::Base.include BarkestCore::UtcConversion
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'jquery-rails'
|
|
2
|
+
require 'bootstrap-sass'
|
|
3
|
+
require 'ntlm/smtp'
|
|
4
|
+
require 'exception_notification'
|
|
5
|
+
|
|
6
|
+
module BarkestCore
|
|
7
|
+
class Engine < ::Rails::Engine
|
|
8
|
+
|
|
9
|
+
# Ensure the default logo gets compiled.
|
|
10
|
+
config.assets.precompile += %w( barkest_core/barcode-B.svg
|
|
11
|
+
barkest_core/ArchivoNarrow-Bold.ttf
|
|
12
|
+
barkest_core/ArchivoNarrow-BoldItalic.ttf
|
|
13
|
+
barkest_core/ArchivoNarrow-Italic.ttf
|
|
14
|
+
barkest_core/ArchivoNarrow-Regular.ttf )
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
# Update the databases as needed.
|
|
19
|
+
Rails::Application::Finisher.initializer 'barkest_core.finisher' do |app|
|
|
20
|
+
MsSqlDbDefinition.registered.each do |name,updater|
|
|
21
|
+
config = BarkestCore.db_config(name)
|
|
22
|
+
if config[:database] && config[:host]
|
|
23
|
+
Rails.logger.debug "Beginning updates for #{name} DB."
|
|
24
|
+
begin
|
|
25
|
+
updater.update_db config
|
|
26
|
+
rescue BarkestCore::MsSqlDbDefinition::NeedFullAccess => e
|
|
27
|
+
Rails.logger.error "The configuration for #{name} DB is missing a valid update user."
|
|
28
|
+
rescue StandardError => e
|
|
29
|
+
Rails.logger.error "The updater for #{name} DB was unable to complete.\n#{e}"
|
|
30
|
+
end
|
|
31
|
+
else
|
|
32
|
+
Rails.logger.warn "Skipping updates for #{name} DB since :database and/or :host is not set."
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# Initialize the library.
|
|
40
|
+
initializer 'barkest_core.initialize' do |app|
|
|
41
|
+
|
|
42
|
+
# cache the application root path.
|
|
43
|
+
BarkestCore.app_root = app.root
|
|
44
|
+
|
|
45
|
+
app.paths['app/helpers'] << 'app/helpers/barkest_core'
|
|
46
|
+
|
|
47
|
+
# get the email config.
|
|
48
|
+
cfg = BarkestCore.email_config
|
|
49
|
+
mode = cfg[:config_mode].to_s.downcase
|
|
50
|
+
[ config.action_mailer, ActionMailer::Base ].each do |obj|
|
|
51
|
+
# configure action_mailer accordingly.
|
|
52
|
+
if %w(smtp test).include?(mode) && !cfg[:default_hostname].blank?
|
|
53
|
+
obj.default_url_options = { host: cfg[:default_hostname] }
|
|
54
|
+
end
|
|
55
|
+
if mode == 'smtp'
|
|
56
|
+
obj.raise_delivery_errors = true
|
|
57
|
+
obj.perform_deliveries = true
|
|
58
|
+
obj.delivery_method = :smtp
|
|
59
|
+
obj.smtp_settings = cfg # remove the non-smtp settings.
|
|
60
|
+
.except(
|
|
61
|
+
:config_mode,
|
|
62
|
+
:default_recipient,
|
|
63
|
+
:default_sender,
|
|
64
|
+
:default_hostname
|
|
65
|
+
)
|
|
66
|
+
else
|
|
67
|
+
obj.delivery_method = mode.to_sym
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# in production mode, we want exceptions sent to the default recipient.
|
|
71
|
+
if Rails.env.production?
|
|
72
|
+
Rails.application.config.middleware.use(
|
|
73
|
+
ExceptionNotification::Rack,
|
|
74
|
+
email: {
|
|
75
|
+
email_prefix: "[BarkerEST #{Rails.application.app_name} (#{Rails.application.app_version})] ",
|
|
76
|
+
sender_address: cfg[:default_sender],
|
|
77
|
+
exception_recipients: [ cfg[:default_recipient] ]
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# configure prawn-rails
|
|
85
|
+
PrawnRails.config do |config|
|
|
86
|
+
config.page_layout = :portrait
|
|
87
|
+
config.page_size = 'LETTER'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
ActionView::Template.register_template_handler :csvrb, BarkestCore::CsvHandler::Handler
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# add date formats for American formatted dates.
|
|
94
|
+
Time::DATE_FORMATS[:date] = '%m/%d/%y'
|
|
95
|
+
Time::DATE_FORMATS[:date4] = '%m/%d/%Y'
|
|
96
|
+
Date::DATE_FORMATS[:date] = '%m/%d/%y'
|
|
97
|
+
Date::DATE_FORMATS[:date4] = '%m/%d/%Y'
|
|
98
|
+
|
|
99
|
+
# If a child gem extends this class, we still want to load the original.
|
|
100
|
+
require_relative '../../app/controllers/barkest_core/application_controller_base'
|
|
101
|
+
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module BarkestCore
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# Adds some helper methods to connection adapters.
|
|
7
|
+
module ConnectionAdapterExtensions
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Searches the database to determine if an object with the specified name exists.
|
|
11
|
+
def object_exists?(object_name)
|
|
12
|
+
safe_name = "'#{object_name.gsub('\'','\'\'')}'"
|
|
13
|
+
klass = self.class.name
|
|
14
|
+
|
|
15
|
+
sql =
|
|
16
|
+
if klass == 'ActiveRecord::ConnectionAdapters::SQLServerAdapter'
|
|
17
|
+
# use sysobjects table.
|
|
18
|
+
"SELECT COUNT(*) AS \"one\" FROM \"sysobjects\" WHERE \"name\"=#{safe_name}"
|
|
19
|
+
elsif klass == 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
|
|
20
|
+
# use sqlite_master table.
|
|
21
|
+
"SELECT COUNT(*) AS \"one\" FROM \"sqlite_master\" WHERE (\"type\"='table' OR \"type\"='view') AND (\"name\"=#{safe_name})"
|
|
22
|
+
else
|
|
23
|
+
# query the information_schema TABLES and ROUTINES views.
|
|
24
|
+
"SELECT SUM(Z.\"one\") AS \"one\" FROM (SELECT COUNT(*) AS \"one\" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=#{safe_name} UNION SELECT COUNT(*) AS \"one\" FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=#{safe_name}) AS Z"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
result = exec_query(sql).first
|
|
28
|
+
|
|
29
|
+
result && result['one'] >= 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# Executes a stored procedure.
|
|
34
|
+
#
|
|
35
|
+
# For MS SQL Server, this will return the return value from the procedure.
|
|
36
|
+
# For other providers, this is the same as +execute+.
|
|
37
|
+
def exec_sp(stmt)
|
|
38
|
+
klass = self.class.name
|
|
39
|
+
if klass == 'ActiveRecord::ConnectionAdapters::SQLServerAdapter'
|
|
40
|
+
rex = /^exec(?:ute)?\s+[\["]?(?<PROC>[a-z][a-z0-9_]*)[\]"]?(?<ARGS>\s.*)?$/i
|
|
41
|
+
match = rex.match(stmt)
|
|
42
|
+
if match
|
|
43
|
+
exec_query("DECLARE @RET INTEGER; EXECUTE @RET=[#{match['PROC']}]#{match['ARGS']}; SELECT @RET AS [RET]").first['RET']
|
|
44
|
+
else
|
|
45
|
+
execute stmt
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
execute stmt
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Add a few extensions to models.
|
|
57
|
+
ActiveRecord::Base.class_eval do
|
|
58
|
+
|
|
59
|
+
##
|
|
60
|
+
# Tests for equality on ID.
|
|
61
|
+
def ==(other)
|
|
62
|
+
if respond_to?(:id)
|
|
63
|
+
if other.is_a?(Numeric)
|
|
64
|
+
id == other
|
|
65
|
+
elsif other.class == self.class
|
|
66
|
+
id == other.id
|
|
67
|
+
else
|
|
68
|
+
false
|
|
69
|
+
end
|
|
70
|
+
else
|
|
71
|
+
self.inspect == other.inspect
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
##
|
|
76
|
+
# Loads the concerns for the current model.
|
|
77
|
+
def self.add_concerns(subdir = nil)
|
|
78
|
+
klass = self
|
|
79
|
+
subdir ||= klass.name.underscore
|
|
80
|
+
|
|
81
|
+
Dir.glob(File.expand_path("../../../app/models/concerns/#{subdir}/*.rb", __FILE__)).each do |item|
|
|
82
|
+
require item
|
|
83
|
+
mod_name = File.basename(item)[0...-3].camelcase
|
|
84
|
+
if const_defined? mod_name
|
|
85
|
+
mod_name = const_get mod_name
|
|
86
|
+
klass.include mod_name
|
|
87
|
+
else
|
|
88
|
+
raise StandardError.new("The #{mod_name} module does not appear to be defined.")
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# patch 'connection' so that we can insert our extensions to the returned adapters.
|
|
94
|
+
class << self
|
|
95
|
+
# :nodoc:
|
|
96
|
+
alias_method :barkest_core_original_connection, :connection
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# :nodoc:
|
|
100
|
+
def self.connection(*args)
|
|
101
|
+
ret = barkest_core_original_connection(*args)
|
|
102
|
+
unless ret.class.include?(BarkestCore::ConnectionAdapterExtensions)
|
|
103
|
+
ret.class.include BarkestCore::ConnectionAdapterExtensions
|
|
104
|
+
end
|
|
105
|
+
yield ret if block_given?
|
|
106
|
+
ret
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
##
|
|
110
|
+
# Searches the database to determine if an object with the specified name exists.
|
|
111
|
+
#
|
|
112
|
+
# This method is actually attached to the connection adapter, so anywhere you have the +connection+ you can use it
|
|
113
|
+
# to query if an object exists.
|
|
114
|
+
def self.object_exists?(object_name)
|
|
115
|
+
return connection.object_exists?(object_name)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
|