Class: Ecrire::Application

Inherits:
Rails::Application
  • Object
show all
Defined in:
lib/ecrire/application.rb

Overview

Ecrire::Application is the entry point when running a blog.

The big difference between this application and a normal Rails application is that Ecrire will look for secrets.yml in the current working directory.

If it doesn’t find one, it will load the Onboarding process so the user can configure the database and the first user.

If the application finds secrets.yml, it will load the Theme which is located in the current working directory.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.onboarding?Boolean

Returns true if Ecrire::Onboarding::Engine is loaded in the application runtime

Returns:

  • (Boolean)


82
83
84
# File 'lib/ecrire/application.rb', line 82

def self.onboarding?
  defined?(Ecrire::Onboarding::Engine)
end

Instance Method Details

#initialize!(group = :default) ⇒ Object

There seems to be a crack between when the configuration is loaded and when the initializer collection is built.

Ecrire requires the configuration to be loaded before knowing which module it should load based on the current configuration.

Another issue happens with railties being memoized before Ecrire could figure out if the user needs to be onboarded.

For those reasons, this method is overloaded.



49
50
51
52
53
54
55
56
57
58
# File 'lib/ecrire/application.rb', line 49

def initialize!(group=:default) #:nodoc:
  raise "Application has been already initialized." if @initialized

  ActiveSupport.run_load_hooks(:before_initialize, self)
  @railties = Railties.new

  run_initializers(group, self)
  @initialized = true
  self
end

#pathsObject

Return paths based off Rails default plus some customization.

These paths are Ecrire’s, not the users’s theme.

For the user’s paths, look at Ecrire::Theme::Engine.paths



67
68
69
70
71
72
73
74
75
76
# File 'lib/ecrire/application.rb', line 67

def paths
  @paths ||= begin
     paths = super
     paths.add 'config/secrets', with: Dir.pwd + '/secrets.yml'
     paths.add 'config/database', with: Dir.pwd + '/secrets.yml'
     paths.add 'config/routes.rb', with: 'routes.rb'
     paths.add 'config/locales', with: 'locales', glob: "**/*.{rb,yml}"
     paths
   end
end