incline 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +186 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +208 -0
- data/Rakefile +37 -0
- data/app/assets/fonts/incline/.keep +0 -0
- data/app/assets/images/incline/.keep +0 -0
- data/app/assets/images/incline/barcode-B.svg +181 -0
- data/app/assets/javascripts/incline/activate_classed_items.js +11 -0
- data/app/assets/javascripts/incline/application.js +30 -0
- data/app/assets/javascripts/incline/bootstrap-datepicker.js +1800 -0
- data/app/assets/javascripts/incline/datatables.js +22193 -0
- data/app/assets/javascripts/incline/escapeHtml.js +10 -0
- data/app/assets/javascripts/incline/inline_actions.js +479 -0
- data/app/assets/javascripts/incline/jquery.doubleScroll.js +112 -0
- data/app/assets/javascripts/incline/jquery.number.js +764 -0
- data/app/assets/javascripts/incline/regexMask.js +27 -0
- data/app/assets/javascripts/incline/select2/i18n/en.js +3 -0
- data/app/assets/javascripts/incline/select2/select2.full.js +6436 -0
- data/app/assets/stylesheets/incline/application.css +18 -0
- data/app/assets/stylesheets/incline/bootstrap-theme.min.css +5 -0
- data/app/assets/stylesheets/incline/custom.scss +279 -0
- data/app/assets/stylesheets/incline/datatables.css +494 -0
- data/app/assets/stylesheets/incline/datepicker3.css +790 -0
- data/app/assets/stylesheets/incline/select2.css +484 -0
- data/app/controllers/incline/access_groups_controller.rb +127 -0
- data/app/controllers/incline/access_test_controller.rb +30 -0
- data/app/controllers/incline/account_activations_controller.rb +28 -0
- data/app/controllers/incline/application_controller.rb +11 -0
- data/app/controllers/incline/contact_controller.rb +34 -0
- data/app/controllers/incline/password_resets_controller.rb +113 -0
- data/app/controllers/incline/security_controller.rb +100 -0
- data/app/controllers/incline/sessions_controller.rb +50 -0
- data/app/controllers/incline/users_controller.rb +304 -0
- data/app/controllers/incline/welcome_controller.rb +19 -0
- data/app/helpers/incline/.keep +0 -0
- data/app/mailers/incline/application_mailer_base.rb +11 -0
- data/app/mailers/incline/contact_form.rb +19 -0
- data/app/mailers/incline/user_mailer.rb +45 -0
- data/app/models/incline/access_group.rb +121 -0
- data/app/models/incline/access_group_group_member.rb +12 -0
- data/app/models/incline/access_group_user_member.rb +10 -0
- data/app/models/incline/action_group.rb +12 -0
- data/app/models/incline/action_security.rb +222 -0
- data/app/models/incline/contact_message.rb +37 -0
- data/app/models/incline/disable_info.rb +20 -0
- data/app/models/incline/password_reset.rb +14 -0
- data/app/models/incline/password_reset_request.rb +14 -0
- data/app/models/incline/user.rb +437 -0
- data/app/models/incline/user_login_history.rb +30 -0
- data/app/views/incline/access_groups/_details.json.jbuilder +10 -0
- data/app/views/incline/access_groups/_form.html.erb +19 -0
- data/app/views/incline/access_groups/_list.html.erb +60 -0
- data/app/views/incline/access_groups/_messages.json.jbuilder +6 -0
- data/app/views/incline/access_groups/edit.html.erb +2 -0
- data/app/views/incline/access_groups/index.html.erb +6 -0
- data/app/views/incline/access_groups/index.json.jbuilder +16 -0
- data/app/views/incline/access_groups/new.html.erb +2 -0
- data/app/views/incline/access_groups/show.html.erb +9 -0
- data/app/views/incline/access_groups/show.json.jbuilder +11 -0
- data/app/views/incline/contact/new.html.erb +22 -0
- data/app/views/incline/contact_form/contact.html.erb +16 -0
- data/app/views/incline/contact_form/contact.text.erb +13 -0
- data/app/views/incline/password_resets/edit.html.erb +16 -0
- data/app/views/incline/password_resets/new.html.erb +12 -0
- data/app/views/incline/security/_details.json.jbuilder +7 -0
- data/app/views/incline/security/_form.html.erb +20 -0
- data/app/views/incline/security/_list.html.erb +89 -0
- data/app/views/incline/security/_messages.json.jbuilder +6 -0
- data/app/views/incline/security/edit.html.erb +2 -0
- data/app/views/incline/security/index.html.erb +6 -0
- data/app/views/incline/security/index.json.jbuilder +16 -0
- data/app/views/incline/security/show.html.erb +31 -0
- data/app/views/incline/security/show.json.jbuilder +11 -0
- data/app/views/incline/sessions/new.html.erb +26 -0
- data/app/views/incline/user_mailer/account_activation.html.erb +7 -0
- data/app/views/incline/user_mailer/account_activation.text.erb +6 -0
- data/app/views/incline/user_mailer/invalid_password_reset.html.erb +3 -0
- data/app/views/incline/user_mailer/invalid_password_reset.text.erb +5 -0
- data/app/views/incline/user_mailer/password_reset.html.erb +8 -0
- data/app/views/incline/user_mailer/password_reset.text.erb +7 -0
- data/app/views/incline/users/_details.json.jbuilder +32 -0
- data/app/views/incline/users/_form.html.erb +21 -0
- data/app/views/incline/users/_list.html.erb +102 -0
- data/app/views/incline/users/_messages.json.jbuilder +6 -0
- data/app/views/incline/users/disable_confirm.html.erb +19 -0
- data/app/views/incline/users/edit.html.erb +5 -0
- data/app/views/incline/users/index.html.erb +6 -0
- data/app/views/incline/users/index.json.jbuilder +16 -0
- data/app/views/incline/users/new.html.erb +5 -0
- data/app/views/incline/users/show.html.erb +12 -0
- data/app/views/incline/users/show.json.jbuilder +11 -0
- data/app/views/incline/welcome/home.html.erb +5 -0
- data/app/views/layouts/application.html.erb +1 -0
- data/app/views/layouts/incline/_account_menu.html.erb +18 -0
- data/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
- data/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
- data/app/views/layouts/incline/_footer.html.erb +13 -0
- data/app/views/layouts/incline/_header.html.erb +21 -0
- data/app/views/layouts/incline/_html_mailer.html.erb +5 -0
- data/app/views/layouts/incline/_incline_app.html.erb +25 -0
- data/app/views/layouts/incline/_messages.html.erb +3 -0
- data/app/views/layouts/incline/_shim.html.erb +3 -0
- data/app/views/layouts/incline/_text_mailer.text.erb +1 -0
- data/app/views/layouts/incline/application.html.erb +1 -0
- data/app/views/layouts/mailer.html.erb +2 -0
- data/app/views/layouts/mailer.text.erb +2 -0
- data/bin/rails +12 -0
- data/bin/test_scaffold.sh +10 -0
- data/config/routes.rb +61 -0
- data/db/migrate/20170511230126_create_incline_users.rb +26 -0
- data/db/migrate/20170515003052_create_incline_access_groups.rb +10 -0
- data/db/migrate/20170515003221_create_incline_user_login_histories.rb +12 -0
- data/db/migrate/20170515150908_create_incline_access_group_user_members.rb +11 -0
- data/db/migrate/20170515151058_create_incline_access_group_group_members.rb +11 -0
- data/db/migrate/20170517193432_add_comments_to_incline_user.rb +5 -0
- data/db/migrate/20170622132700_create_incline_action_securities.rb +16 -0
- data/db/migrate/20170622172712_create_incline_action_groups.rb +11 -0
- data/db/migrate/20170622195742_add_non_standard_to_action_security.rb +5 -0
- data/db/migrate/20170622230422_add_visible_to_action_security.rb +5 -0
- data/db/seeds.rb +81 -0
- data/exe/new_incline_app +42 -0
- data/lib/generators/incline/install_generator.rb +259 -0
- data/lib/generators/incline/templates/_app_menu_anon.html.erb +1 -0
- data/lib/generators/incline/templates/_app_menu_authenticated.html.erb +1 -0
- data/lib/generators/incline/templates/incline_application.css +17 -0
- data/lib/generators/incline/templates/incline_application.html.erb +1 -0
- data/lib/generators/incline/templates/incline_application.js +12 -0
- data/lib/generators/incline/templates/incline_database.yml +25 -0
- data/lib/generators/incline/templates/incline_email.yml +20 -0
- data/lib/generators/incline/templates/incline_mailer.html.erb +2 -0
- data/lib/generators/incline/templates/incline_mailer.text.erb +2 -0
- data/lib/generators/incline/templates/incline_users.yml +64 -0
- data/lib/generators/incline/templates/incline_version.rb +3 -0
- data/lib/incline/auth_engine_base.rb +52 -0
- data/lib/incline/data_tables_request.rb +336 -0
- data/lib/incline/date_time_formats.rb +6 -0
- data/lib/incline/engine.rb +212 -0
- data/lib/incline/errors.rb +15 -0
- data/lib/incline/extensions/action_controller_base.rb +526 -0
- data/lib/incline/extensions/action_mailer_base.rb +66 -0
- data/lib/incline/extensions/action_view_base.rb +489 -0
- data/lib/incline/extensions/active_record_base.rb +308 -0
- data/lib/incline/extensions/application.rb +137 -0
- data/lib/incline/extensions/application_configuration.rb +50 -0
- data/lib/incline/extensions/connection_adapter.rb +55 -0
- data/lib/incline/extensions/date_time_value.rb +123 -0
- data/lib/incline/extensions/date_value.rb +77 -0
- data/lib/incline/extensions/decimal_value.rb +55 -0
- data/lib/incline/extensions/erb_scaffold_generator.rb +31 -0
- data/lib/incline/extensions/float_value.rb +59 -0
- data/lib/incline/extensions/form_builder.rb +617 -0
- data/lib/incline/extensions/integer_value.rb +54 -0
- data/lib/incline/extensions/jbuilder_generator.rb +38 -0
- data/lib/incline/extensions/jbuilder_template.rb +39 -0
- data/lib/incline/extensions/main_app.rb +40 -0
- data/lib/incline/extensions/numeric.rb +63 -0
- data/lib/incline/extensions/object.rb +31 -0
- data/lib/incline/extensions/resource_route_generator.rb +53 -0
- data/lib/incline/extensions/session.rb +113 -0
- data/lib/incline/extensions/string.rb +50 -0
- data/lib/incline/extensions/test_case.rb +764 -0
- data/lib/incline/extensions/time_zone_converter.rb +40 -0
- data/lib/incline/global_status.rb +236 -0
- data/lib/incline/helpers/route_hash_formatter.rb +46 -0
- data/lib/incline/json_log_formatter.rb +96 -0
- data/lib/incline/json_logger.rb +17 -0
- data/lib/incline/log.rb +153 -0
- data/lib/incline/number_formats.rb +17 -0
- data/lib/incline/recaptcha.rb +346 -0
- data/lib/incline/user_manager.rb +212 -0
- data/lib/incline/validators/email_validator.rb +45 -0
- data/lib/incline/validators/ip_address_validator.rb +32 -0
- data/lib/incline/validators/recaptcha_validator.rb +37 -0
- data/lib/incline/validators/safe_name_validator.rb +31 -0
- data/lib/incline/version.rb +3 -0
- data/lib/incline/work_path.rb +75 -0
- data/lib/incline.rb +197 -0
- data/lib/tasks/incline_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +43 -0
- data/lib/templates/erb/scaffold/_list.html.erb +81 -0
- data/lib/templates/erb/scaffold/edit.html.erb +1 -0
- data/lib/templates/erb/scaffold/index.html.erb +6 -0
- data/lib/templates/erb/scaffold/new.html.erb +1 -0
- data/lib/templates/erb/scaffold/show.html.erb +34 -0
- data/lib/templates/jbuilder/scaffold/_details.json.jbuilder +20 -0
- data/lib/templates/jbuilder/scaffold/index.json.jbuilder +16 -0
- data/lib/templates/jbuilder/scaffold/show.json.jbuilder +16 -0
- data/lib/templates/rails/scaffold_controller/controller.rb +128 -0
- data/test/controllers/incline/access_groups_controller_test.rb +65 -0
- data/test/controllers/incline/access_test_controller_test.rb +53 -0
- data/test/controllers/incline/contact_controller_test.rb +32 -0
- data/test/controllers/incline/security_controller_test.rb +39 -0
- data/test/controllers/incline/welcome_controller_test.rb +16 -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 +12 -0
- data/test/dummy/app/assets/stylesheets/application.css +17 -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/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/incline/_app_menu_anon.html.erb +1 -0
- data/test/dummy/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +2 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +2 -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 +38 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +34 -0
- data/test/dummy/config/email.yml +24 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +45 -0
- data/test/dummy/config/environments/production.rb +85 -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/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/to_time_preserves_timezone.rb +10 -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 +6 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/schema.rb +108 -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/extensions/action_controller_base_extensions_test.rb +21 -0
- data/test/extensions/action_mailer_base_extensions_test.rb +20 -0
- data/test/extensions/action_view_base_extensions_test.rb +267 -0
- data/test/extensions/active_record_extensions_test.rb +173 -0
- data/test/extensions/application_configuration_extensions_test.rb +46 -0
- data/test/extensions/application_extensions_test.rb +23 -0
- data/test/extensions/connection_adapter_extensions_test.rb +54 -0
- data/test/extensions/date_time_value_extensions_test.rb +104 -0
- data/test/extensions/date_value_extensions_test.rb +102 -0
- data/test/extensions/decimal_value_extensions_test.rb +85 -0
- data/test/extensions/erb_scaffold_generator_extensions_test.rb +17 -0
- data/test/extensions/float_value_extensions_test.rb +78 -0
- data/test/extensions/form_builder_extensions_test.rb +28 -0
- data/test/extensions/integer_value_extensions_test.rb +78 -0
- data/test/extensions/jbuilder_generator_extensions_test.rb +21 -0
- data/test/extensions/jbuilder_template_extensions_test.rb +47 -0
- data/test/extensions/main_app_extensions_test.rb +55 -0
- data/test/extensions/numeric_extensions_test.rb +76 -0
- data/test/extensions/object_extensions_test.rb +104 -0
- data/test/extensions/session_extensions_test.rb +69 -0
- data/test/extensions/string_extensions_test.rb +32 -0
- data/test/extensions/test_case_extensions_test.rb +538 -0
- data/test/extensions/time_zone_converter_extensions_test.rb +10 -0
- data/test/fixtures/incline/access_group_group_members.yml +1 -0
- data/test/fixtures/incline/access_group_user_members.yml +1 -0
- data/test/fixtures/incline/access_groups.yml +13 -0
- data/test/fixtures/incline/action_groups.yml +6 -0
- data/test/fixtures/incline/action_securities.yml +18 -0
- data/test/fixtures/incline/user_login_histories.yml +1 -0
- data/test/fixtures/incline/users.yml +64 -0
- data/test/incline_test.rb +63 -0
- data/test/integration/incline/users_edit_test.rb +180 -0
- data/test/integration/incline/users_login_test.rb +105 -0
- data/test/integration/incline/users_signup_test.rb +147 -0
- data/test/integration/navigation_test.rb +11 -0
- data/test/lib/data_tables_request_test.rb +245 -0
- data/test/lib/date_time_formats_test.rb +111 -0
- data/test/lib/global_status_test.rb +89 -0
- data/test/lib/json_log_formatter_test.rb +43 -0
- data/test/lib/log_test.rb +36 -0
- data/test/lib/recaptcha_test.rb +75 -0
- data/test/lib/user_manager_test.rb +47 -0
- data/test/lib/work_path_test.rb +18 -0
- data/test/models/incline/access_group_group_member_test.rb +30 -0
- data/test/models/incline/access_group_test.rb +60 -0
- data/test/models/incline/access_group_user_member_test.rb +29 -0
- data/test/models/incline/action_group_test.rb +27 -0
- data/test/models/incline/action_security_test.rb +176 -0
- data/test/models/incline/contact_message_test.rb +66 -0
- data/test/models/incline/disable_info_test.rb +29 -0
- data/test/models/incline/password_reset_request_test.rb +35 -0
- data/test/models/incline/password_reset_test.rb +51 -0
- data/test/models/incline/user_login_history_test.rb +31 -0
- data/test/models/incline/user_test.rb +91 -0
- data/test/test_helper.rb +42 -0
- data/test/validators/email_validator_test.rb +102 -0
- data/test/validators/ip_address_validator_test.rb +107 -0
- data/test/validators/recaptcha_validator_test.rb +57 -0
- data/test/validators/safe_name_validator_test.rb +101 -0
- metadata +584 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'jbuilder/jbuilder_template'
|
2
|
+
|
3
|
+
module Incline::Extensions
|
4
|
+
##
|
5
|
+
# Adds the +api_errors+ method to be used in jbuilder views to easily list
|
6
|
+
# errors for a model in a form that is compatible with the DataTables API.
|
7
|
+
module JbuilderTemplate
|
8
|
+
|
9
|
+
##
|
10
|
+
# List out the errors for the model.
|
11
|
+
#
|
12
|
+
# model_name:: The singular name for the model (e.g. - "user_account")
|
13
|
+
# model_errors:: The errors collection from the model.
|
14
|
+
#
|
15
|
+
# json.api_errors! "user_account", user.errors
|
16
|
+
#
|
17
|
+
def api_errors!(model_name, model_errors)
|
18
|
+
base_error = model_errors[:base]
|
19
|
+
field_errors = model_errors.reject{ |k,_| k == :base }
|
20
|
+
unless base_error.blank?
|
21
|
+
set! 'error', "#{model_name.humanize} #{base_error.map{|e| h(e.to_s)}.join("<br>\n#{model_name.humanize} ")}"
|
22
|
+
end
|
23
|
+
unless field_errors.blank?
|
24
|
+
set! 'fieldErrors' do
|
25
|
+
array! field_errors do |k,v|
|
26
|
+
set! 'name', "#{model_name}.#{k}"
|
27
|
+
set! 'status', v.is_a?(::Array) ?
|
28
|
+
"#{k.to_s.humanize} #{v.map{|e| h(e.to_s)}.join("<br>\n#{k.to_s.humanize} ")}" :
|
29
|
+
"#{k.to_s.humanize} #{h v.to_s}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
JbuilderTemplate.include Incline::Extensions::JbuilderTemplate
|
39
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
require 'action_mailer'
|
3
|
+
require 'action_view'
|
4
|
+
|
5
|
+
module Incline::Extensions
|
6
|
+
|
7
|
+
##
|
8
|
+
# Makes 'main_app' automatically get searched for methods.
|
9
|
+
module MainApp
|
10
|
+
|
11
|
+
def self.included(base) # :nodoc:
|
12
|
+
base.class_eval do
|
13
|
+
|
14
|
+
# :nodoc:
|
15
|
+
alias :incline_mainapp_original_method_missing :method_missing
|
16
|
+
|
17
|
+
def method_missing(method, *args, &block) # :nodoc:
|
18
|
+
o_main_app = if respond_to?(:main_app)
|
19
|
+
send(:main_app)
|
20
|
+
else
|
21
|
+
Rails.application.class.routes.url_helpers
|
22
|
+
end
|
23
|
+
|
24
|
+
if o_main_app && o_main_app.respond_to?(method)
|
25
|
+
return o_main_app.send(method, *args, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
incline_mainapp_original_method_missing(method, *args, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
ActionController::Base.include Incline::Extensions::MainApp
|
39
|
+
ActionMailer::Base.include Incline::Extensions::MainApp
|
40
|
+
ActionView::Base.include Incline::Extensions::MainApp
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
|
3
|
+
module Incline::Extensions
|
4
|
+
##
|
5
|
+
# Adds to_human to numeric types (floats and integers).
|
6
|
+
module Numeric
|
7
|
+
|
8
|
+
##
|
9
|
+
# The short scale for humanizing a number.
|
10
|
+
SHORT_SCALE =
|
11
|
+
[
|
12
|
+
[ Integer('1'.ljust(40,'0')), 'duodecillion' ],
|
13
|
+
[ Integer('1'.ljust(37,'0')), 'undecillion' ],
|
14
|
+
[ Integer('1'.ljust(34,'0')), 'decillion' ],
|
15
|
+
[ Integer('1'.ljust(31,'0')), 'nonillion' ],
|
16
|
+
[ Integer('1'.ljust(28,'0')), 'octilillion' ],
|
17
|
+
[ Integer('1'.ljust(25,'0')), 'septillion' ],
|
18
|
+
[ Integer('1'.ljust(22,'0')), 'sextillion' ],
|
19
|
+
[ Integer('1'.ljust(19,'0')), 'quintillion' ],
|
20
|
+
[ Integer('1'.ljust(16,'0')), 'quadrillion' ],
|
21
|
+
[ Integer('1'.ljust(13,'0')), 'trillion' ],
|
22
|
+
[ Integer('1'.ljust(10,'0')), 'billion' ],
|
23
|
+
[ Integer('1'.ljust(7,'0')), 'million' ],
|
24
|
+
[ Integer('1'.ljust(4,'0')), 'thousand' ],
|
25
|
+
]
|
26
|
+
|
27
|
+
##
|
28
|
+
# Formats the number using the short scale for any number over 1 million.
|
29
|
+
def to_human
|
30
|
+
Incline::Extensions::Numeric::SHORT_SCALE.each do |(num,label)|
|
31
|
+
if self >= num
|
32
|
+
# Add 0.0001 to the value before rounding it off.
|
33
|
+
# This way we're telling the system that we want it to round up instead of round to even.
|
34
|
+
s = ('%.2f' % ((self.to_f / num) + 0.0001)).gsub(/\.?0+\z/,'')
|
35
|
+
return "#{s} #{label}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if self.is_a?(::Rational)
|
40
|
+
if self.denominator == 1
|
41
|
+
return self.numerator.to_s
|
42
|
+
end
|
43
|
+
return self.to_s
|
44
|
+
elsif self.is_a?(::Integer)
|
45
|
+
return self.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
# Again we want to add the 0.0001 to the value before rounding.
|
49
|
+
('%.2f' % (self.to_f + 0.0001)).gsub(/\.?0+\z/,'')
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Converts this value into a boolean.
|
54
|
+
#
|
55
|
+
# A value of 0 is false, any other value is true.
|
56
|
+
def to_bool
|
57
|
+
self != 0
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Numeric.include Incline::Extensions::Numeric
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Incline::Extensions
|
2
|
+
|
3
|
+
##
|
4
|
+
# Adds the +object_pointer+ method to all objects.
|
5
|
+
module Object
|
6
|
+
|
7
|
+
##
|
8
|
+
# Gets the object_id formatted in hexadecimal with a leading '0x'.
|
9
|
+
def object_pointer
|
10
|
+
'0x' + self.object_id.to_s(16).rjust(12,'0').downcase
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Converts this object into a boolean value.
|
15
|
+
#
|
16
|
+
# The +true+ value returns true, as do the :true, :yes, and :on symbols.
|
17
|
+
# Any numeric not equal to 0 returns true.
|
18
|
+
# And the strings of 'true', 't', 'yes', 'y', 'on', and '1' (case-insensitive) return true.
|
19
|
+
# Everything else will return false, including +nil+.
|
20
|
+
#
|
21
|
+
# This obviously differs from the Ruby behavior that only nil and false evaluate to false.
|
22
|
+
# This is not meant to replace that behavior, it was actually meant to enable simple usage of
|
23
|
+
# other values commonly used to the represent true and false (eg - 0 and 1).
|
24
|
+
def to_bool
|
25
|
+
is_a?(::TrueClass) || self == :true || self == :yes || self == :on
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Object.include Incline::Extensions::Object
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/rails/resource_route/resource_route_generator'
|
3
|
+
|
4
|
+
module Incline::Extensions
|
5
|
+
module ResourceRouteGenerator
|
6
|
+
|
7
|
+
##
|
8
|
+
# Overrides the add_resource_route method.
|
9
|
+
def self.included(base)
|
10
|
+
base.class_eval do
|
11
|
+
undef add_resource_route
|
12
|
+
|
13
|
+
##
|
14
|
+
# Adds a resource route with additional :api and :locate actions.
|
15
|
+
def add_resource_route
|
16
|
+
return if options[:actions].present?
|
17
|
+
|
18
|
+
# iterates over all namespaces and opens up blocks
|
19
|
+
regular_class_path.each_with_index do |namespace, index|
|
20
|
+
write("namespace :#{namespace} do", index + 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
# inserts the primary resource with api routes as well.
|
24
|
+
pad = ' ' * (route_length + 1)
|
25
|
+
write <<-EOR, 0
|
26
|
+
#{pad}resources :#{file_name.pluralize} do
|
27
|
+
#{pad} member do
|
28
|
+
#{pad} post :locate
|
29
|
+
#{pad} end
|
30
|
+
#{pad} collection do
|
31
|
+
#{pad} match :api, via: [ :get, :post ]
|
32
|
+
#{pad} end
|
33
|
+
#{pad}end
|
34
|
+
EOR
|
35
|
+
|
36
|
+
# ends blocks
|
37
|
+
regular_class_path.each_index do |index|
|
38
|
+
write("end", route_length - index)
|
39
|
+
end
|
40
|
+
|
41
|
+
# route prepends two spaces onto the front of the string that is passed, this corrects that.
|
42
|
+
# Also it adds a \n to the end of each line, as route already adds that
|
43
|
+
# we need to correct that too.
|
44
|
+
route route_string[2..-2]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Rails::Generators::ResourceRouteGenerator.include Incline::Extensions::ResourceRouteGenerator
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_mailer'
|
4
|
+
require 'action_dispatch'
|
5
|
+
|
6
|
+
module Incline::Extensions
|
7
|
+
|
8
|
+
##
|
9
|
+
# Patches the views and controllers to have access to user session features.
|
10
|
+
module Session
|
11
|
+
|
12
|
+
##
|
13
|
+
# Contains the methods common to both controllers and views.
|
14
|
+
module Common
|
15
|
+
|
16
|
+
##
|
17
|
+
# Gets the name of the cookie containing the user ID for the current user.
|
18
|
+
#
|
19
|
+
# This gets set when the user selects the "Remember me" checkbox when logging in.
|
20
|
+
def user_id_cookie
|
21
|
+
@user_id_cookie ||= Rails.application.cookie_name(:user_id)
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Gets the name of the cookie containing the remember token for the current user.
|
26
|
+
#
|
27
|
+
# This gets set when the user selects the "Remember me" checkbox when logging in.
|
28
|
+
def user_token_cookie
|
29
|
+
@user_token_cookie ||= Rails.application.cookie_name(:user_token)
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Gets the currently logged in user.
|
34
|
+
def current_user
|
35
|
+
@current_user ||=
|
36
|
+
if (user_id = session[:user_id])
|
37
|
+
Incline::User.find_by(id: user_id)
|
38
|
+
elsif (cookies&.respond_to?(:signed)) &&
|
39
|
+
(user_id = cookies.signed[user_id_cookie]) &&
|
40
|
+
(user = Incline::User.find_by(id: user_id)) &&
|
41
|
+
(user.authenticated?(:remember, cookies[user_token_cookie]))
|
42
|
+
log_in user if respond_to?(:log_in)
|
43
|
+
user
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end ||Incline::User::anonymous
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Is the specified user the current user?
|
51
|
+
def current_user?(user)
|
52
|
+
current_user == user
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Is a user logged in?
|
57
|
+
def logged_in?
|
58
|
+
!current_user.anonymous?
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Is the current user a system administrator?
|
63
|
+
def system_admin?
|
64
|
+
logged_in? && current_user.system_admin? && current_user.enabled? && current_user.activated?
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Contains the methods specific to controllers.
|
71
|
+
module Controller
|
72
|
+
|
73
|
+
##
|
74
|
+
# Logs in the given user.
|
75
|
+
def log_in(user)
|
76
|
+
session[:user_id] = user.id
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Logs out any currently logged in user.
|
81
|
+
def log_out
|
82
|
+
forget current_user
|
83
|
+
session.delete(:user_id)
|
84
|
+
@current_user = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Stores the user ID to the permanent cookie store to keep the user logged in.
|
89
|
+
def remember(user)
|
90
|
+
user.remember
|
91
|
+
cookies.permanent.signed[user_id_cookie] = user.id
|
92
|
+
cookies.permanent[user_token_cookie] = user.remember_token
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Removes the user from the permanent cookie store.
|
97
|
+
def forget(user)
|
98
|
+
user.forget
|
99
|
+
cookies.delete(user_id_cookie)
|
100
|
+
cookies.delete(user_token_cookie)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
ActionView::Base.include Incline::Extensions::Session::Common
|
109
|
+
ActionMailer::Base.include Incline::Extensions::Session::Common
|
110
|
+
ActionController::Base.include Incline::Extensions::Session::Common
|
111
|
+
ActionController::Base.include Incline::Extensions::Session::Controller
|
112
|
+
ActionDispatch::IntegrationTest.include Incline::Extensions::Session::Common
|
113
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Incline::Extensions
|
2
|
+
|
3
|
+
##
|
4
|
+
# Defines or overrides few string helper methods.
|
5
|
+
module String
|
6
|
+
|
7
|
+
##
|
8
|
+
# Converts a hex string into a byte string.
|
9
|
+
#
|
10
|
+
# Whitespace in the string is ignored.
|
11
|
+
# The string must only contain characters valid for hex (ie - 0-9, A-F, a-f).
|
12
|
+
# The string must contain an even number of characters since each character only represents half a byte.
|
13
|
+
def to_byte_string
|
14
|
+
ret = self.gsub(/\s+/,'')
|
15
|
+
raise 'Hex string must have even number of characters.' unless ret.size % 2 == 0
|
16
|
+
raise 'Hex string must only contain 0-9 and A-F characters.' if ret =~ /[^0-9a-fA-F]/
|
17
|
+
[ret].pack('H*').force_encoding('ascii-8bit')
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Converts a binary string into a hex string.
|
22
|
+
#
|
23
|
+
# The +grouping+ parameter can be set to true or an integer value specifying how many chars you want in
|
24
|
+
# each group. If true or less than 1, then characters are put into groups of 2.
|
25
|
+
def to_hex_string(grouping = false)
|
26
|
+
ret = self.unpack('H*').first
|
27
|
+
if grouping
|
28
|
+
if grouping.is_a?(::Integer) && grouping > 0
|
29
|
+
ret.gsub(/(#{'.' * grouping})/,'\1 ').rstrip
|
30
|
+
else
|
31
|
+
ret.gsub(/(..)/,'\1 ').rstrip
|
32
|
+
end
|
33
|
+
else
|
34
|
+
ret
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Converts a string into a boolean value.
|
40
|
+
#
|
41
|
+
# The following values are considered true: true, t, yes, y, on, 1
|
42
|
+
# Everything else will be false.
|
43
|
+
def to_bool
|
44
|
+
%w(true t yes y on 1).include?(self.downcase)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
String.include Incline::Extensions::String
|