Class: Telegrator::Generators::Bot

Inherits:
Base
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/telegrator/generators/bot/generator.rb

Constant Summary collapse

DATABASES =
%w[postgresql mongodb].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

dispatch

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Bot

Returns a new instance of Bot.



13
14
15
16
# File 'lib/telegrator/generators/bot/generator.rb', line 13

def initialize(args = [], options = {}, config = {})
  config[:destination_root] ||= args.first
  super
end

Class Method Details

.source_rootObject

TODO: move to Base class



9
10
11
# File 'lib/telegrator/generators/bot/generator.rb', line 9

def self.source_root
  File.expand_path('../templates', __FILE__)
end

Instance Method Details

#create_app_dirObject

app/ directory ===



54
55
56
# File 'lib/telegrator/generators/bot/generator.rb', line 54

def create_app_dir
  empty_directory 'app'
end

#create_bin_dirObject

bin/ directory ===



87
88
89
# File 'lib/telegrator/generators/bot/generator.rb', line 87

def create_bin_dir
  directory 'bin', mode: :preserve
end

#create_commandsObject



58
59
60
61
# File 'lib/telegrator/generators/bot/generator.rb', line 58

def create_commands
  template 'app/commands.rb'
  directory 'app/commands'
end

#create_config_dirObject

config/ directory ===



92
93
94
95
96
97
98
99
100
# File 'lib/telegrator/generators/bot/generator.rb', line 92

def create_config_dir
  directory 'config'

  if options[:skip_capistrano]
    remove_file 'config/deploy/'
    remove_file 'config/deploy.rb'
  end
  remove_file 'config/initializers/sequel.rb' if mongodb?
end

#create_db_dirObject

db/ directory ===



103
104
105
106
# File 'lib/telegrator/generators/bot/generator.rb', line 103

def create_db_dir
  return if mongodb?
  directory 'db'
end

#create_keyboardsObject

TODO: inline keyboards



65
66
67
68
69
# File 'lib/telegrator/generators/bot/generator.rb', line 65

def create_keyboards
  return if options[:skip_keyboards]
  template 'app/keyboards.rb'
  directory 'app/keyboards'
end

#create_lib_dirObject

lib/ directory ===



109
110
111
112
# File 'lib/telegrator/generators/bot/generator.rb', line 109

def create_lib_dir
  directory 'lib'
  remove_file 'lib/tasks/db.rake' if mongodb?
end

#create_log_dirObject

log/ directory ===



115
116
117
118
# File 'lib/telegrator/generators/bot/generator.rb', line 115

def create_log_dir
  empty_directory 'log'
  create_file 'log/.keep'
end

#create_modelsObject



71
72
73
74
# File 'lib/telegrator/generators/bot/generator.rb', line 71

def create_models
  template 'app/models.rb'
  directory 'app/models'
end

#create_root_filesObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/telegrator/generators/bot/generator.rb', line 41

def create_root_files
  template 'gitignore.tt', '.gitignore'

  template 'env.tt', '.env.sample'
  template 'env.tt', '.env'

  template 'Gemfile.tt'
  template 'Rakefile.tt'
  template 'Capfile.tt' unless options[:skip_capistrano]
  template 'config.ru.tt' unless options[:skip_webhook]
end

#create_servicesObject



76
77
78
79
# File 'lib/telegrator/generators/bot/generator.rb', line 76

def create_services
  template 'app/services.rb'
  directory 'app/services'
end

#create_workersObject



81
82
83
84
# File 'lib/telegrator/generators/bot/generator.rb', line 81

def create_workers
  template 'app/workers.rb'
  directory 'app/workers'
end

#initObject



120
121
122
123
# File 'lib/telegrator/generators/bot/generator.rb', line 120

def init
  inside { run 'git init' }
  inside { run 'bundle install' } unless options[:skip_bundler]
end