Class: Headshot::Generators::ConfigGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/headshot/config/config_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_flash_middlewareObject



9
10
11
12
# File 'lib/generators/headshot/config/config_generator.rb', line 9

def copy_flash_middleware
  say_status('copying', 'Copying Flash session cookie middleware ...')
  copy_file('../middlewares/flash_session_cookie_middleware.rb', 'app/middlewares/flash_session_cookie_middleware.rb')
end

#create_default_directoriesObject



39
40
41
42
# File 'lib/generators/headshot/config/config_generator.rb', line 39

def create_default_directories
  say_status('creating', 'Creating default headshots directory public/headshots.')
  create_file('public/headshots/empty_file', '')
end

#initialize_session_storeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/headshot/config/config_generator.rb', line 25

def initialize_session_store
  session_store_rb_path = "config/initializers/session_store.rb"
  loading_code = 'config.autoload_paths += %W(#{config.root}/app/middlewares)'
  say_status('checking', 'Checking if session_store.rb contains the code for initializing for the middleware.')
  initializer_code = "\n"

  inside(source_paths[0] + '/../initializers', :verbose => true) do
    initializer_code_lines = IO.readlines('session_store.rb')
    initializer_code += initializer_code_lines.join('')
  end

  append_file(session_store_rb_path, initializer_code)
end

#load_middlewares_in_application_rbObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/headshot/config/config_generator.rb', line 14

def load_middlewares_in_application_rb
  application_rb_path = "config/application.rb"
  code_marker = "class Application < Rails::Application"
  loading_code = 'config.autoload_paths += %W(#{config.root}/app/middlewares)'
  say_status('checking', 'Checking if application.rb contains the loading code for the middleware.')

  inject_into_file application_rb_path, :after => "#{code_marker}\n" do
    "\t\t#{loading_code}\n"
  end
end