Created
July 6, 2020 05:57
-
-
Save ikasamt/d133ddb19ec7ca1ce21e5613efca78cc to your computer and use it in GitHub Desktop.
simple-rails-like-framework.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## rails/database.rb | |
class Database | |
def connection() | |
return mysql.Connection() | |
end | |
end | |
## rails/test_databae.rb | |
class Database | |
def connection() | |
return sqlite3.Connection() | |
end | |
end | |
## rails/controller.rb | |
module Rails | |
class BaseController | |
def call(action_name) | |
eval("self.#{action_name}") | |
end | |
end | |
end | |
## rails/model.rb | |
module Rails | |
class BaseModel | |
def self.first | |
conn = Rails::Database.connection() | |
row = conn.execute("SELECT * FROM users ORDER BY id DESC LIMIT 1") | |
instance = bind(row) | |
return instance | |
end | |
end | |
end | |
## application/models/user.rb | |
class User < BaseModel | |
def self.bind(row) | |
instance = self() | |
instance.name = rows["name"] | |
instance.email = rows["email"] | |
instance.age = rows["age"] | |
return instance | |
end | |
end | |
## application/controllers/main.rb | |
class MainController < BaseController | |
def hello | |
me = User.first | |
json_response(value) | |
end | |
end | |
## application/init.rb | |
if ENV("test") | |
require "rails/test_databae.rb" | |
end | |
while do | |
regexp("/:controller_name/:action_name", url.path) | |
controller = eval("#{controller_name}Controller.new()") | |
http.responese(controller.call(action_name)) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment