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.



123
124
125
126
127
128
# File 'lib/incline/engine.rb', line 123

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.



114
115
116
117
118
119
# File 'lib/incline/engine.rb', line 114

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.



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/incline/engine.rb', line 181

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.



196
197
198
199
200
201
# File 'lib/incline/engine.rb', line 196

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.



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

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.



205
206
207
208
209
210
211
212
# File 'lib/incline/engine.rb', line 205

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.



165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/incline/engine.rb', line 165

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)



103
104
105
106
107
108
109
110
# File 'lib/incline/engine.rb', line 103

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.



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

cattr_accessor :show_valid_permissions