Module: Netfira::WebConnect::Rails

Extended by:
Forwardable
Defined in:
lib/netfira/web_connect/rails/version.rb,
lib/netfira/web_connect/rails/initializer.rb,
lib/netfira/web_connect/rails/mock_request.rb,
lib/netfira/web_connect/rails/request_trap.rb,
lib/netfira/web_connect/rails/configuration.rb,
lib/netfira/web_connect/rails/railtie.rb,
lib/web-connect-rails.rb

Defined Under Namespace

Classes: Configuration, MockRequest, Railtie, RequestTrap

Constant Summary collapse

VERSION =
'0.4.13'
GEM_ROOT =
Pathname(__FILE__).parent

Class Method Summary collapse

Class Method Details

.configure {|@config| ... } ⇒ Object

Yields:

  • (@config)


41
42
43
# File 'lib/netfira/web_connect/rails/initializer.rb', line 41

def self.configure
  yield @config
end

.initialize!Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/netfira/web_connect/rails/initializer.rb', line 3

def self.initialize!
  @config = Configuration.new

  # Read end-user configuration data, which may include database connection details
  # This will fail if the end-user hasn't run rails generate web_connect:install
  begin
    require Rails.root + 'config/initializers/web_connect'
  rescue LoadError

    # If there's no initializer, leave things along if Rails isn't running as a server.
    # This will give `rails generate` a chance to succeed.
    return unless caller.grep(/\bconfig\.ru\b/).any?
    raise 'To complete installation of WebConnect, run `rails generate web_connect:install`'
  end

  # Add additional configuration to the web-connect gem
  Netfira::WebConnect.configure do |c|

    # Use a blank string as the default table prefix
    c.db_table_prefix ||= ''

    # Sharing the host app's DB with no table prefix will cause collisions in the
    # schema_migrations table, and possibly other tables.
    raise 'WebConnect cannot share the host application database without a table prefix.' if !c.db && c.db_table_prefix.empty?

    # Use the default rails logger
    c.logger = Rails.logger

    # Use the Rails database connection if none was specified by the end-user
    c.db ||= Rails.configuration.database_configuration[Rails.env]
  end

  # Ensure database is properly migrated, except when running rake tasks
  if File.basename($0) != 'rake' && Netfira::WebConnect.needs_migration?
    raise 'WebConnect has pending database migrations. Please run `rake wc:migrate`'
  end
end