Module: Incline
- Defined in:
- lib/incline.rb,
lib/incline/cli.rb,
lib/incline/log.rb,
lib/incline/engine.rb,
lib/incline/errors.rb,
lib/incline/version.rb,
lib/incline/bit_enum.rb,
lib/incline/cli/usage.rb,
lib/incline/recaptcha.rb,
lib/incline/work_path.rb,
lib/incline/cli/errors.rb,
app/models/incline/user.rb,
lib/incline/cli/prepare.rb,
lib/incline/cli/version.rb,
lib/incline/json_logger.rb,
lib/incline/user_manager.rb,
lib/incline/constant_enum.rb,
lib/incline/global_status.rb,
lib/incline/number_formats.rb,
lib/incline/auth_engine_base.rb,
lib/incline/cli/helpers/yaml.rb,
lib/incline/date_time_formats.rb,
lib/incline/json_log_formatter.rb,
app/mailers/incline/user_mailer.rb,
app/models/incline/access_group.rb,
app/models/incline/action_group.rb,
app/models/incline/disable_info.rb,
lib/incline/data_tables_request.rb,
app/mailers/incline/contact_form.rb,
app/models/incline/password_reset.rb,
app/models/incline/action_security.rb,
app/models/incline/contact_message.rb,
lib/incline/cli/prepare/config_ssh.rb,
lib/incline/cli/prepare/install_db.rb,
lib/incline/cli/prepare/ssh_copy_id.rb,
lib/incline/cli/prepare/extend_shell.rb,
lib/incline/cli/prepare/install_ruby.rb,
app/models/incline/user_login_history.rb,
lib/incline/cli/prepare/install_rails.rb,
lib/incline/cli/prepare/install_rbenv.rb,
lib/incline/cli/prepare/restart_nginx.rb,
lib/incline/cli/prepare/update_system.rb,
lib/incline/extensions/current_request.rb,
lib/incline/validators/email_validator.rb,
lib/incline/cli/prepare/add_deploy_user.rb,
lib/incline/cli/prepare/install_flytrap.rb,
lib/incline/cli/prepare/install_prereqs.rb,
app/controllers/incline/users_controller.rb,
lib/generators/incline/install_generator.rb,
lib/incline/cli/prepare/config_passenger.rb,
app/models/incline/password_reset_request.rb,
lib/incline/cli/prepare/install_passenger.rb,
app/controllers/incline/contact_controller.rb,
app/controllers/incline/welcome_controller.rb,
lib/incline/cli/prepare/create_nginx_utils.rb,
lib/incline/validators/recaptcha_validator.rb,
lib/incline/validators/safe_name_validator.rb,
app/controllers/incline/security_controller.rb,
app/controllers/incline/sessions_controller.rb,
app/mailers/incline/application_mailer_base.rb,
app/models/incline/access_group_user_member.rb,
lib/incline/validators/ip_address_validator.rb,
app/models/incline/access_group_group_member.rb,
app/controllers/incline/access_test_controller.rb,
app/controllers/incline/application_controller.rb,
app/controllers/incline/access_groups_controller.rb,
app/controllers/incline/password_resets_controller.rb,
app/controllers/incline/account_activations_controller.rb
Overview
require_dependency “incline/application_controller”
Defined Under Namespace
Modules: CliHelpers, DateTimeFormats, Extensions, Helpers, NumberFormats Classes: AccessGroup, AccessGroupGroupMember, AccessGroupUserMember, AccessGroupsController, AccessTestController, AccountActivationsController, ActionGroup, ActionSecurity, ApplicationController, ApplicationMailerBase, AuthEngineBase, BitEnum, CLI, ConstantEnum, ContactController, ContactForm, ContactMessage, DataTablesRequest, DisableInfo, EmailValidator, Engine, GlobalStatus, InstallGenerator, IpAddressValidator, JsonLogFormatter, JsonLogger, Log, PasswordReset, PasswordResetRequest, PasswordResetsController, Recaptcha, RecaptchaValidator, SafeNameValidator, SecurityController, SessionsController, User, UserLoginHistory, UserMailer, UserManager, UsersController, WelcomeController, WorkPath
Constant Summary collapse
- NotLoggedIn =
An exception used to indicate when a user is not logged in.
Class.new(StandardError)
- NotAuthorized =
An exception used to indicate when a user is not authorized.
Class.new(StandardError)
- InvalidApiCall =
An exception used to indicate an invalid API call.
Class.new(StandardError)
- VERSION =
"0.3.14"
Class Method Summary collapse
- .current_request ⇒ Object
-
.email_config ⇒ Object
Gets the automatic email configuration for the Incline application.
-
.gem_list(*patterns) ⇒ Object
Gets a list of key gems with their versions.
-
.get_controller_class(controller_name) ⇒ Object
Locates and loads a controller’s class definition.
-
.migrate! ⇒ Object
Performs a database migration against the configured database.
-
.route_list ⇒ Object
Gets a list of routes for the current application.
Instance Method Summary collapse
-
#session_store ⇒ Object
Allows the session store to be configured.
Class Method Details
.current_request ⇒ Object
18 19 20 21 |
# File 'lib/incline/extensions/current_request.rb', line 18 def self.current_request th = ::Thread.current th.thread_variable?(:incline_current_request) ? th.thread_variable_get(:incline_current_request) : nil end |
.email_config ⇒ Object
Gets the automatic email configuration for the Incline application.
The primary configuration should be stored in config/email.yml
. If this file is missing, automatic email configuration is skipped and must be manually specified in your application’s environment initializer (eg - config/environment/production.rb).
test:
...
development:
...
production:
default_url: www.example.com
default_recipient: [email protected]
sender: [email protected]
auth: :plain
start_tls: true
ssl: false
server: smtp.example.com
port: 587
You shouldn’t use an open relay, a warning will be thrown if you do. But you don’t want your login credentials stored in config/email.yml
either. Instead, credentials (if any) should be stored in config/secrets.yml
.
test:
...
development:
...
production:
email:
user: [email protected]
password: super-secret-password
secret_key_base: ...
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/incline.rb', line 51 def self.email_config @email_config ||= begin yaml = Rails.root.join('config', 'email.yml') if File.exist?(yaml) cfg = File.exist?(yaml) ? YAML.load(ERB.new(File.read(yaml)).result) : { } cfg = (cfg[Rails.env] || {}).symbolize_keys cfg = { port: 25, auth: :plain, start_tls: true, ssl: false }.merge(cfg) Incline::Log::warn 'The email configuration is missing the "user" key.' if cfg[:user].blank? Incline::Log::warn 'The email configuration is missing the "password" key.' if cfg[:password].blank? Incline::Log::error 'The email configuration is missing the "server" key.' if cfg[:server].blank? Incline::Log::error 'The email configuration is missing the "sender" key.' if cfg[:sender].blank? Incline::Log::error 'The email configuration is missing the "default_url" key.' if cfg[:default_url].blank? Incline::Log::error 'The email configuration is missing the "default_recipient" key.' if cfg[:default_recipient].blank? def cfg.valid? return false if self[:sender].blank? || self[:server].blank? || self[:default_url].blank? || self[:default_recipient].blank? true end cfg.freeze else Incline::Log::info 'The configuration file "email.yml" does not exist, automatic email configuration disabled.' cfg = {} def cfg.valid? false end cfg.freeze end end end |
.gem_list(*patterns) ⇒ Object
Gets a list of key gems with their versions.
This is useful for informational displays.
Supply one or more patterns for gem names. If you supply none, then the default pattern list is used.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/incline.rb', line 100 def self.gem_list(*patterns) patterns = if patterns.blank? default_gem_patterns elsif patterns.first.is_a?(::TrueClass) default_gem_patterns + patterns[1..-1] else patterns end patterns = patterns.flatten.inject([]) { |m,v| m << v unless m.include?(v); m } gems = Gem::Specification.to_a.sort{ |a,b| a.name <=> b.name } patterns.inject([]) do |ret,pat| gems .select { |g| (pat.is_a?(::String) && g.name == pat) || (pat.is_a?(::Regexp) && g.name =~ pat) } .each do |g| ret << [ g.name, g.version.to_s ] unless ret.find { |(name,_)| name == g.name } end ret end end |
.get_controller_class(controller_name) ⇒ Object
Locates and loads a controller’s class definition.
If found, returns the controller class, otherwise nil.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/incline.rb', line 157 def self.get_controller_class(controller_name) controller_name += '_controller' unless controller_name =~ /_controller$/ class_name = controller_name.classify klass = begin class_name.constantize rescue NameError nil end if klass unless klass <= ::ActionController::Base ::Incline::Log::warn "The '#{class_name}' class does not inherit from 'ActionController::Base'." return nil end end unless klass = if controller_name.include?('/') ns,_,ctrl = controller_name.rpartition('/') [ "#{ns}/app/controllers/#{ns}/#{ctrl}_controller", "app/controllers/#{ns}/#{ctrl}_controller", "#{ns}/app/controllers/#{ctrl}_controller", "#{ns}/#{ctrl}_controller" ] else [ "app/controllers/#{controller_name}_controller", "#{controller_name}_controller" ] end while (file = .shift) begin require file klass = class_name.constantize if klass <= ::ActionController::Base ::Incline::Log::debug "Found '#{class_name}' in '#{file}'." else ::Incline::Log::warn "Found '#{class_name}' in '#{file}', but it does not inherit from 'ActionController::Base'." klass = nil end break rescue LoadError, NameError # don't bubble up these errors. klass = nil end end end klass end |
.migrate! ⇒ Object
Performs a database migration against the configured database.
149 150 151 |
# File 'lib/incline.rb', line 149 def self.migrate! ActiveRecord::Migrator.migrate File.('../../db/migrate', __FILE__), nil end |
.route_list ⇒ Object
Gets a list of routes for the current application.
The returned list contains hashes with :engine, :controller, :action, :name, :verb, and :path keys.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/incline.rb', line 129 def self.route_list @route_list ||= begin require 'action_dispatch/routing/inspector' get_routes(Rails.application.routes.routes).sort do |a,b| if a[:engine] == b[:engine] if a[:controller] == b[:controller] a[:action] <=> b[:action] else a[:controller] <=> b[:controller] end else a[:engine] <=> b[:engine] end end end end |
Instance Method Details
#session_store ⇒ Object
Allows the session store to be configured.
Incline::session_store = :cookie_store
13 |
# File 'lib/incline.rb', line 13 mattr_accessor :session_store |