class DaimonSkycrawlers::Generator::New
@private
Public Class Methods
source_root()
click to toggle source
# File lib/daimon_skycrawlers/generator/new.rb, line 18 def self.source_root (Pathname(__dir__) + "../../../templates/new").to_s end
Public Instance Methods
copy_files()
click to toggle source
# File lib/daimon_skycrawlers/generator/new.rb, line 73 def copy_files [ "Dockerfile", "Dockerfile.db", "Gemfile", "Rakefile", "app/crawler.rb", "app/processor.rb", "config/init.rb", "services/common/docker-entrypoint.sh", "services/db/init-user-db.sh" ].each do |path| copy_file(path, "#{name}/#{path}", mode: :preserve) end end
create_directories()
click to toggle source
# File lib/daimon_skycrawlers/generator/new.rb, line 89 def create_directories [ "app/crawlers", "app/filters", "app/processors", "vendor/bundle", "docker-cache/bundle", "docker-cache/.bundle" ].each do |entry| empty_directory("#{name}/#{entry}") end end
create_files()
click to toggle source
# File lib/daimon_skycrawlers/generator/new.rb, line 22 def create_files config = { password: SecureRandom.urlsafe_base64 } [ "README.md", "config/database.yml", "docker-compose.yml", "env", "env.db", ].each do |path| if path.start_with?("env") template("#{path}.erb", "#{name}/.#{path}", config) else template("#{path}.erb", "#{name}/#{path}", config) end end migration_options = { destination_root: File.join(destination_root, name), timestamps: true } invoke(MigrationGenerator, [ "CreatePages", "key:string", "url:string", "headers:text", "body:binary", "last_modified_at:datetime", "etag:string" ], migration_options) end
display_post_message()
click to toggle source
# File lib/daimon_skycrawlers/generator/new.rb, line 102 def display_post_message puts <<MESSAGE Check .env and .env.db before running `docker-compose build` or `docker-compose up`. MESSAGE end
insert_index()
click to toggle source
# File lib/daimon_skycrawlers/generator/new.rb, line 55 def insert_index Dir.glob(File.join(destination_root, name, "db/migrate/*_create_pages.rb")) do |entry| source = File.read(entry) replaced_source = source.gsub(/(^ +)t.timestamps$/) do |_match; indent| indent = $1 <<-CODE.chomp #{indent}t.timestamps #{indent}t.index [:key] #{indent}t.index [:key, :updated_at] #{indent}t.index [:url] #{indent}t.index [:url, :updated_at] CODE end File.write(entry, replaced_source) end end