class FileContent

Public Class Methods

app_content() click to toggle source
# File lib/raamen/file_contents/app_content.rb, line 2
  def self.app_content
"require 'raamen'
require 'rack'

def app()
  router = Raamen::Router.new
  router.draw do
    # Add routes here, example:
    # get Regexp.new(\"^/cats$\"), CatsController, :index
  end

  app = Proc.new do |env|
    req = Rack::Request.new(env)
    res = Rack::Response.new
    router.run(req, res)
    res.finish
  end

  app = Rack::Builder.new do
    use Raamen::ShowExceptions
    use Raamen::Static
    run app
  end.to_app
end"
  end
controller_content(name) click to toggle source
# File lib/raamen/file_contents/controller_content.rb, line 2
  def self.controller_content(name)
"class #{name} < Raamen::ControllerBase

end"
  end
db_connection_content(app_name) click to toggle source
# File lib/raamen/file_contents/db_connection_content.rb, line 2
  def self.db_connection_content(app_name)
"require 'sqlite3'

PRINT_QUERIES = ENV['PRINT_QUERIES'] == 'true'
# https://tomafro.net/2010/01/tip-relative-paths-with-file-expand-path
ROOT_FOLDER = Dir.pwd
SQL_FILE = File.join(ROOT_FOLDER, 'db', '#{app_name}.sql')
DB_FILE = File.join(ROOT_FOLDER, 'db', '#{app_name}.db')

class DBConnection
  def self.open(db_file_name)
    @db = SQLite3::Database.new(db_file_name)
    @db.results_as_hash = true
    @db.type_translation = true

    @db
  end

  def self.reset
    return DBConnection.open(DB_FILE) if File.exist?(DB_FILE)

    commands = [\"cat '\#{SQL_FILE}' | sqlite3 '\#{DB_FILE}'\"]
    commands.each { |command| `\#{command}` }
    DBConnection.open(DB_FILE)
  end

  def self.instance
    reset if @db.nil?

    @db
  end

  def self.execute(*args)
    print_query(*args)
    instance.execute(*args)
  end

  def self.execute2(*args)
    print_query(*args)
    instance.execute2(*args)
  end

  def self.last_insert_row_id
    instance.last_insert_row_id
  end

  private

  def self.print_query(query, *interpolation_args)
    return unless PRINT_QUERIES

    puts '--------------------'
    puts query
    unless interpolation_args.empty?
      puts \"interpolate: \#{interpolation_args.inspect}\"
    end
    puts '--------------------'
  end
end"
  end
gem_file_content() click to toggle source
# File lib/raamen/file_contents/gem_file_content.rb, line 2
  def self.gem_file_content
"gem 'raamen'
gem 'rack'"
  end
model_content(name) click to toggle source
# File lib/raamen/file_contents/model_content.rb, line 2
  def self.model_content(name)
"class #{name} < Raamen::SQLObject

  self.finalize!
end"
  end