Module: Combustion

Defined in:
lib/combustion.rb,
lib/combustion/database.rb,
lib/combustion/generator.rb,
lib/combustion/application.rb

Defined Under Namespace

Modules: Configurations, Databases Classes: Application, Database, Generator

Constant Summary collapse

MODULES =
begin
  hash = {
    :active_model      => "active_model/railtie",
    :active_record     => "active_record/railtie",
    :action_controller => "action_controller/railtie",
    :action_mailer     => "action_mailer/railtie",
    :action_view       => "action_view/railtie"
  }

  hash[:sprockets]      = "sprockets/railtie"     if Rails.version.to_f >= 3.1
  hash[:active_job]     = "active_job/railtie"    if Rails.version.to_f >= 4.2
  hash[:action_cable]   = "action_cable/engine"   if Rails.version.to_f >= 5.0
  hash[:active_storage] = "active_storage/engine" if Rails.version.to_f >= 5.2
  hash[:action_text]    = "action_text/engine"    if Rails.version.to_f >= 6.0
  hash[:action_mailbox] = "action_mailbox/engine" if Rails.version.to_f >= 6.0

  hash
end.freeze

Class Method Summary collapse

Class Method Details

.include_capybara_into(config) ⇒ Object


70
71
72
73
74
75
76
77
78
# File 'lib/combustion.rb', line 70

def self.include_capybara_into(config)
  return unless defined?(Capybara)

  config.include Capybara::RSpecMatchers if defined?(Capybara::RSpecMatchers)
  config.include Capybara::DSL           if defined?(Capybara::DSL)
  return if defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)

  config.include Capybara
end

.include_database(modules, options) ⇒ Object


49
50
51
52
53
54
55
# File 'lib/combustion.rb', line 49

def self.include_database(modules, options)
  return unless modules.map(&:to_s).include? "active_record"

  Combustion::Application.config.to_prepare do
    Combustion::Database.setup(options)
  end
end

.include_rspecObject


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/combustion.rb', line 57

def self.include_rspec
  return unless defined?(RSpec) && RSpec.respond_to?(:configure)

  RSpec.configure do |config|
    include_capybara_into config

    config.include Combustion::Application.routes.url_helpers
    if Combustion::Application.routes.respond_to?(:mounted_helpers)
      config.include Combustion::Application.routes.mounted_helpers
    end
  end
end

.initialize!(*modules, &block) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/combustion.rb', line 34

def self.initialize!(*modules, &block)
  self.setup_environment = block if block_given?

  options = modules.extract_options!
  modules = MODULES.keys if modules == [:all]
  modules.each { |mod| require MODULES.fetch(mod, "#{mod}/railtie") }

  Bundler.require :default, Rails.env

  Combustion::Application.configure_for_combustion
  include_database modules, options
  Combustion::Application.initialize!
  include_rspec
end