Class: FileContent
- Inherits:
-
Object
- Object
- FileContent
- Defined in:
- lib/raamen/file_contents/app_content.rb,
lib/raamen/file_contents/model_content.rb,
lib/raamen/file_contents/gem_file_content.rb,
lib/raamen/file_contents/controller_content.rb,
lib/raamen/file_contents/db_connection_content.rb
Class Method Summary collapse
- .app_content ⇒ Object
- .controller_content(name) ⇒ Object
- .db_connection_content(app_name) ⇒ Object
- .gem_file_content ⇒ Object
- .model_content(name) ⇒ Object
Class Method Details
.app_content ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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) ⇒ Object
2 3 4 5 6 |
# 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) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 ⇒ Object
2 3 4 5 |
# File 'lib/raamen/file_contents/gem_file_content.rb', line 2 def self.gem_file_content "gem 'raamen' gem 'rack'" end |
.model_content(name) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/raamen/file_contents/model_content.rb', line 2 def self.model_content(name) "class #{name} < Raamen::SQLObject self.finalize! end" end |