Class: Framework::ApplicationGenerator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/framework/generators/application_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



10
11
12
# File 'lib/framework/generators/application_generator.rb', line 10

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#create_application_configObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/framework/generators/application_generator.rb', line 27

def create_application_config
  create_file 'config/application.yml' do
    <<-CONFIG.strip_heredoc
    development: &common
      enable_logging: yes
      autoload_paths:
        - app/models
      default_timezone: 'Pacific Time (US & Canada)'

    test:
      <<: *common
      enable_logging: no

    staging:
      <<: *common

    production:
      <<: *common
      enable_logging: no
    CONFIG
  end
end

#create_base_directoriesObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/framework/generators/application_generator.rb', line 14

def create_base_directories
  empty_directory 'app/models'
  empty_directory 'app/models/concerns'
  create_file 'app/models/concerns/.keep'

  empty_directory 'lib'
  create_file 'lib/.keep'

  empty_directory 'db'
  empty_directory 'db/migrate'
  create_file 'db/migrate/.keep'
end

#create_database_configObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/framework/generators/application_generator.rb', line 50

def create_database_config
  db_name = name.underscore

  create_file 'config/database.yml' do
    <<-CONFIG.strip_heredoc
    development: &common
      adapter: postgresql
      username:
      password:
      database: #{db_name}_development
      min_messages: WARNING
      reconnect: true
      pool: 5
      encoding: unicode
      host: localhost

    test:
      <<: *common
      database: #{db_name}_test

    production:
      <<: *common
      database: #{db_name}_production
    CONFIG
  end
end

#create_environmentObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/framework/generators/application_generator.rb', line 77

def create_environment
  create_file 'config/environment.rb' do
    <<-CONFIG.strip_heredoc
    # Set up gems listed in the Gemfile.
    ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
    require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

    require 'framework'

    Bundler.require(:default, Framework.env)

    Framework::Application.new do |app|
      app.init!
    end
    CONFIG
  end
end

#create_gemfileObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/framework/generators/application_generator.rb', line 95

def create_gemfile
  create_file 'Gemfile' do
    <<-CONFIG.strip_heredoc
      source 'https://rubygems.org'

      gem 'framework', '#{Framework::VERSION}'
      gem 'pg'
    CONFIG
  end
end

#create_rakefileObject



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/framework/generators/application_generator.rb', line 106

def create_rakefile
  create_file 'Rakefile' do
    <<-CONFIG.strip_heredoc
    # Add your own tasks in files placed in lib/tasks ending in .rake,
    # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

    require 'framework'
    require 'framework/rake'

    Dir["\#{Dir.pwd}/app/tasks/**/*.rake"].each(&method(:load))
    CONFIG
  end
end

#create_readmeObject



141
142
143
# File 'lib/framework/generators/application_generator.rb', line 141

def create_readme
  create_file 'README.md', "This app utilizes Framework v#{Framework::VERSION} and rocks MIT license."
end

#create_sample_initializersObject



131
132
133
134
135
136
137
138
139
# File 'lib/framework/generators/application_generator.rb', line 131

def create_sample_initializers
  empty_directory 'config/initializers'
  create_file 'config/initializers/time_zone.rb' do
    <<-CONFIG.strip_heredoc
      # Sample usage of application config
      Time.zone = Framework.app.config['default_timezone']
    CONFIG
  end
end

#create_sample_tasksObject



120
121
122
123
124
125
126
127
128
129
# File 'lib/framework/generators/application_generator.rb', line 120

def create_sample_tasks
  empty_directory 'app/tasks'
  create_file 'app/tasks/hello.rake' do
    <<-RAKE.strip_heredoc
    task hello: :environment do
      Framework::Logger.disappointment("Hello from: Framework v#{Framework::VERSION}")
    end
    RAKE
  end
end