Class: Incline::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/incline/engine.rb

Overview

The Incline engine.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_assets_to(app) ⇒ Object

Configures the application to include Incline assets.



119
120
121
122
123
124
# File 'lib/incline/engine.rb', line 119

def self.add_assets_to(app)
  # Add our assets
  app.config.assets.precompile += %w(
      incline/barcode-B.svg
  )
end

.add_helpers_to(app) ⇒ Object

Configures the application to include Incline helpers.



110
111
112
113
114
115
# File 'lib/incline/engine.rb', line 110

def self.add_helpers_to(app)
  # add our helper path to the search path.
  path = File.expand_path('../../../app/helpers', __FILE__)
  app.helpers_paths << path unless app.helpers_paths.include?(path)
  app.config.paths['app/helpers'] << path unless app.config.paths['app/helpers'].include?(path)
end

.add_migrations_to(app) ⇒ Object

Configures the application to use Incline migrations as opposed to copying the Incline migrations locally.



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/incline/engine.rb', line 177

def self.add_migrations_to(app)
  unless app.root.to_s.match root.to_s
    migrate_path = File.expand_path('../../../db/migrate', __FILE__)

    # this should be all that's required.
    app.config.paths['db/migrate'] << migrate_path unless app.config.paths['db/migrate'].include?(migrate_path)

    # however this gets set before the config is updated.
    # so we'll add it here as well to ensure it gets set correctly.
    ActiveRecord::Tasks::DatabaseTasks.migrations_paths << migrate_path unless ActiveRecord::Tasks::DatabaseTasks.migrations_paths.include?(migrate_path)
  end
end

.add_seeds_to(app) ⇒ Object

Configures the application to use Incline seeds.



192
193
194
195
196
197
# File 'lib/incline/engine.rb', line 192

def self.add_seeds_to(app)
  seeds_path = File.expand_path('../../../db/seeds.rb', __FILE__)

  # Once again, this should be all that's required.
  app.config.paths['db/seeds.rb'] << seeds_path unless app.config.paths['db/seeds.rb'].include?(seeds_path)
end

.apply_email_config_to(app) ⇒ Object

Configures the application to use the Incline email configuration.

If the config/email.yml file is not configured correctly this does nothing.



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/incline/engine.rb', line 130

def self.apply_email_config_to(app)
  if Incline::email_config.valid?
    app.config.action_mailer.default_url_options = {
        host: Incline::email_config[:default_url]
    }
    app.config.action_mailer.default_options = {
        from: Incline::email_config[:sender],
        to:   Incline::email_config[:default_recipient]
    }
    app.config.action_mailer.smtp_settings = {
        address:                Incline::email_config[:server],
        port:                   Incline::email_config[:port],
        user_name:              Incline::email_config[:user],
        password:               Incline::email_config[:password],
        authentication:         Incline::email_config[:user].blank? ? nil : Incline::email_config[:auth],
        enable_start_tls_auto:  Incline::email_config[:start_tls],
        ssl:                    Incline::email_config[:ssl],
        openssl_verify_mode:    'none'
    }
    if Rails.env.test?
      app.config.action_mailer.delivery_method = :test
    else
      app.config.action_mailer.delivery_method = :smtp
      app.config.action_mailer.raise_delivery_errors = true
      app.config.perform_deliveries = true
    end
  end
end

.configure_generators_for(app) ⇒ Object

Configures generators so they can use our templates and so they don’t create some redundant files.



201
202
203
204
205
206
207
208
# File 'lib/incline/engine.rb', line 201

def self.configure_generators_for(app)
  app.config.app_generators.templates << File.expand_path('../../templates', __FILE__)
  app.config.generators do |g|
    g.scaffold_stylesheet   false   # we depend on the application.css, no need for a scaffold.css
    g.stylesheets           false   # no need for a stylesheet for every controller.
    g.javascripts           false   # no need for a javascript file for every controller.
  end
end

.notify_on_exceptions_from(app) ⇒ Object

Configures the application to send messages when unhandled exceptions occur in production mode.



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/incline/engine.rb', line 161

def self.notify_on_exceptions_from(app)
  # Send emails for unhandled exceptions.
  if Rails.env.production?
    app.config.middleware.use(
        ExceptionNotification::Rack,
        email: {
            email_prefix: '[Incline ' + Rails.application.app_info + ']',
            sender_address: Incline::email_config[:sender],
            exception_recipients: [ Incline::email_config[:exception_recipient] || Incline::email_config[:default_recipient] ]
        }
    )
  end
end

.set_date_formatsObject

Sets the date formats to default to US format (ie - m/d/y)



99
100
101
102
103
104
105
106
# File 'lib/incline/engine.rb', line 99

def self.set_date_formats
  # add American formats as default.
  Time::DATE_FORMATS[:default] = '%m/%d/%Y %H:%M'
  Time::DATE_FORMATS[:date] = '%m/%d/%y'

  Date::DATE_FORMATS[:default] = '%m/%d/%Y'
  Date::DATE_FORMATS[:date] = '%m/%d/%y'
end

Instance Method Details

#show_valid_permissionsObject

If you want to report valid permissions on access denied, set this attribute to true.



65
# File 'lib/incline/engine.rb', line 65

cattr_accessor :show_valid_permissions