railz_lite 0.1.4 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/railz_lite/cli.rb +16 -4
- data/lib/railz_lite/controllers/controller_base.rb +2 -2
- data/lib/railz_lite/controllers/flash.rb +1 -1
- data/lib/railz_lite/controllers/router.rb +3 -3
- data/lib/railz_lite/controllers/session.rb +1 -1
- data/lib/railz_lite/controllers/static.rb +2 -2
- data/lib/railz_lite/generators/project.rb +11 -7
- data/lib/railz_lite/generators/templates/server.rb +8 -1
- data/lib/railz_lite/generators/templates/welcome_view.index.html.erb +12 -0
- data/lib/railz_lite/generators/templates/winter_fox_large.jpg +0 -0
- data/lib/railz_lite/models/db_connection.rb +9 -6
- data/lib/railz_lite/version.rb +1 -1
- metadata +3 -8
- data/exe/railz_lite.rb~ +0 -3
- data/lib/railz_lite/controllers/templates/rescue.html.erb~ +0 -0
- data/lib/railz_lite/generators/templates/routes.rb +0 -0
- data/lib/railz_lite/models/associatable.rb~ +0 -79
- data/lib/railz_lite/models/associatable2.rb~ +0 -35
- data/lib/railz_lite/models/searchable.rb~ +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81d26ed037ad3c977f1cb81938ae67fe84e5d61bb003b56fc4a42cfefa66c85e
|
4
|
+
data.tar.gz: 83094af33c58caab3053c15a6325360d4d865739a127180cb8b601010e3f20ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fc0c8c888e5c2d906c0d3c7be43d240ad13197ce19681547232308eca1dc6fe06f5805d18a52743923445d9916408caddb95c043b8f1b865ae16bca8657c7ad
|
7
|
+
data.tar.gz: 36bef73dd88344e44ad8066f73489fc8bc2e9d709013eff7e16ddb098992d34840fe6230e35f8770e089bbecabc8c35c71e9a301e2b6c60191b46e4987fded59
|
data/lib/railz_lite/cli.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'railz_lite'
|
3
3
|
require 'railz_lite/generators/project'
|
4
|
+
require 'railz_lite/models/db_connection'
|
4
5
|
|
5
6
|
module RailzLite
|
6
7
|
class CLI < Thor
|
7
8
|
desc 'new', 'Generates a new RailzLite project'
|
8
|
-
def new
|
9
|
-
RailzLite::Generators::Project.start([])
|
9
|
+
def new(project_name)
|
10
|
+
RailzLite::Generators::Project.start([project_name])
|
10
11
|
end
|
11
12
|
|
12
|
-
desc 'server', 'Starts up a puma server within RailzLite project'
|
13
|
+
desc 'server', 'Starts up a puma server within RailzLite project. Also initializes '
|
13
14
|
def server
|
14
|
-
|
15
|
+
file = File.join(Dir.pwd, 'config', 'server.rb')
|
16
|
+
if File.exist?(file)
|
17
|
+
DBConnection.start # load our db connection
|
18
|
+
system('ruby', file)
|
19
|
+
else
|
20
|
+
raise "File not found at #{file}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'db_reset', 'Restarts the database and reads db/app.sql file'
|
25
|
+
def db_reset
|
26
|
+
DBConnection.reset
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
@@ -45,8 +45,8 @@ module RailzLite
|
|
45
45
|
# use ERB and binding to evaluate templates
|
46
46
|
# pass the rendered html to render_content
|
47
47
|
def render(template_name)
|
48
|
-
dir_path =
|
49
|
-
file_path = File.join(dir_path, '
|
48
|
+
dir_path = Dir.pwd
|
49
|
+
file_path = File.join(dir_path, 'views', "#{self.class.name.underscore}", "#{template_name.to_s}.html.erb")
|
50
50
|
file = File.read(file_path)
|
51
51
|
template = ERB.new(file).result(binding)
|
52
52
|
render_content(template, 'text/html')
|
@@ -58,11 +58,11 @@ class Router
|
|
58
58
|
# either throw 404 or call run on a matched route
|
59
59
|
def run(req, res)
|
60
60
|
matching_route = match(req)
|
61
|
-
if matching_route.
|
62
|
-
matching_route.run(req, res)
|
63
|
-
else
|
61
|
+
if matching_route.nil?
|
64
62
|
res.status = 404
|
65
63
|
res.write("Matching route not found for #{req.path}")
|
64
|
+
else
|
65
|
+
matching_route.run(req, res)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -4,34 +4,38 @@ module RailzLite
|
|
4
4
|
module Generators
|
5
5
|
class Project < Thor::Group
|
6
6
|
include Thor::Actions
|
7
|
+
argument :project_name, type: :string
|
7
8
|
|
8
9
|
def self.source_root
|
9
10
|
File.dirname(__FILE__) + "/templates"
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.destination_root
|
13
|
-
puts "destination for folder #{Dir.pwd}"
|
14
14
|
Dir.pwd
|
15
15
|
end
|
16
16
|
|
17
17
|
def add_controllers
|
18
|
-
empty_directory("controllers")
|
18
|
+
empty_directory("#{project_name}/controllers")
|
19
19
|
end
|
20
20
|
|
21
21
|
def add_models
|
22
|
-
empty_directory("models")
|
22
|
+
empty_directory("#{project_name}/models")
|
23
23
|
end
|
24
24
|
|
25
25
|
def add_server
|
26
|
-
template(
|
26
|
+
template('server.rb', "#{project_name}/config/server.rb")
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def add_welcome_view
|
30
|
+
template('welcome_view.index.html.erb', "#{project_name}/views/welcome_controller/welcome_view.index.html.erb")
|
31
31
|
end
|
32
32
|
|
33
33
|
def add_public
|
34
|
-
|
34
|
+
copy_file('winter_fox_large.jpg', "#{project_name}/public")
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_sql_file
|
38
|
+
create_file("#{project_name}/db/app.sql")
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
@@ -2,10 +2,17 @@ require 'rack'
|
|
2
2
|
require 'railz_lite/controllers/static'
|
3
3
|
require 'railz_lite/controllers/show_exceptions'
|
4
4
|
require 'railz_lite/controllers/router'
|
5
|
+
require 'railz_lite'
|
6
|
+
|
7
|
+
# example controller config
|
8
|
+
class WelcomeController < RailzLite::ControllerBase
|
9
|
+
def index; end
|
10
|
+
end
|
5
11
|
|
6
12
|
router = Router.new
|
7
13
|
router.draw do
|
8
14
|
# add routes here
|
15
|
+
get Regexp.new('^/$'), WelcomeController, :index
|
9
16
|
end
|
10
17
|
|
11
18
|
app = Proc.new do |env|
|
@@ -16,7 +23,7 @@ app = Proc.new do |env|
|
|
16
23
|
end
|
17
24
|
|
18
25
|
app = Rack::Builder.new do
|
19
|
-
use
|
26
|
+
use ShowExceptions # generates helpful error messages
|
20
27
|
use Static # serves static assets from /public
|
21
28
|
run app
|
22
29
|
end.to_app
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div style="
|
2
|
+
width: 50%;
|
3
|
+
margin: 0 auto;
|
4
|
+
margin-top: 18px;
|
5
|
+
text-align: center;
|
6
|
+
">
|
7
|
+
<h1>Welcome To Railz Lite!</h1>
|
8
|
+
|
9
|
+
<img src="../public/winter_fox_large.jpg" />
|
10
|
+
|
11
|
+
<h3>For guidelines on how to build an app with this framework see <a href="https://github.com/bryanqb07/railz_lite">here</a>.</h3>
|
12
|
+
</div>
|
Binary file
|
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'sqlite3'
|
2
2
|
|
3
|
-
PRINT_QUERIES = ENV['PRINT_QUERIES'] == 'true'
|
4
|
-
# https://tomafro.net/2010/01/tip-relative-paths-with-file-expand-path
|
5
|
-
ROOT_FOLDER = File.join(File.dirname(__FILE__), '..')
|
6
|
-
SQL_FILE = File.join(ROOT_FOLDER, 'app.sql')
|
7
|
-
DB_FILE = File.join(ROOT_FOLDER, 'app.db')
|
8
|
-
|
9
3
|
class DBConnection
|
4
|
+
PRINT_QUERIES = ENV['PRINT_QUERIES'] == 'true'
|
5
|
+
ROOT_FOLDER = Dir.pwd
|
6
|
+
SQL_FILE = File.join(ROOT_FOLDER, 'db', 'app.sql')
|
7
|
+
DB_FILE = File.join(ROOT_FOLDER, 'db', 'app.db')
|
8
|
+
|
9
|
+
def self.start
|
10
|
+
DBConnection.open(DB_FILE)
|
11
|
+
end
|
12
|
+
|
10
13
|
def self.open(db_file_name)
|
11
14
|
@db = SQLite3::Database.new(db_file_name)
|
12
15
|
@db.results_as_hash = true
|
data/lib/railz_lite/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railz_lite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bryan lynch
|
@@ -141,7 +141,6 @@ email:
|
|
141
141
|
- bml312@nyu.edu
|
142
142
|
executables:
|
143
143
|
- railz_lite
|
144
|
-
- railz_lite.rb~
|
145
144
|
extensions: []
|
146
145
|
extra_rdoc_files: []
|
147
146
|
files:
|
@@ -156,7 +155,6 @@ files:
|
|
156
155
|
- bin/console
|
157
156
|
- bin/setup
|
158
157
|
- exe/railz_lite
|
159
|
-
- exe/railz_lite.rb~
|
160
158
|
- lib/railz_lite.rb
|
161
159
|
- lib/railz_lite/cli.rb
|
162
160
|
- lib/railz_lite/controllers/controller_base.rb
|
@@ -166,20 +164,17 @@ files:
|
|
166
164
|
- lib/railz_lite/controllers/show_exceptions.rb
|
167
165
|
- lib/railz_lite/controllers/static.rb
|
168
166
|
- lib/railz_lite/controllers/templates/rescue.html.erb
|
169
|
-
- lib/railz_lite/controllers/templates/rescue.html.erb~
|
170
167
|
- lib/railz_lite/generators/project.rb
|
171
168
|
- lib/railz_lite/generators/project.rb~
|
172
169
|
- lib/railz_lite/generators/templates/application_controller.rb~
|
173
|
-
- lib/railz_lite/generators/templates/routes.rb
|
174
170
|
- lib/railz_lite/generators/templates/server.rb
|
171
|
+
- lib/railz_lite/generators/templates/welcome_view.index.html.erb
|
172
|
+
- lib/railz_lite/generators/templates/winter_fox_large.jpg
|
175
173
|
- lib/railz_lite/models/associatable.rb
|
176
|
-
- lib/railz_lite/models/associatable.rb~
|
177
174
|
- lib/railz_lite/models/associatable2.rb
|
178
|
-
- lib/railz_lite/models/associatable2.rb~
|
179
175
|
- lib/railz_lite/models/attr_accessor_object.rb
|
180
176
|
- lib/railz_lite/models/db_connection.rb
|
181
177
|
- lib/railz_lite/models/searchable.rb
|
182
|
-
- lib/railz_lite/models/searchable.rb~
|
183
178
|
- lib/railz_lite/models/sql_object.rb
|
184
179
|
- lib/railz_lite/models/validatable.rb
|
185
180
|
- lib/railz_lite/version.rb
|
data/exe/railz_lite.rb~
DELETED
File without changes
|
File without changes
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require_relative '02_searchable'
|
2
|
-
require 'active_support/inflector'
|
3
|
-
|
4
|
-
class AssocOptions
|
5
|
-
attr_accessor(
|
6
|
-
:foreign_key,
|
7
|
-
:class_name,
|
8
|
-
:primary_key
|
9
|
-
)
|
10
|
-
|
11
|
-
def model_class
|
12
|
-
class_name.constantize
|
13
|
-
end
|
14
|
-
|
15
|
-
def table_name
|
16
|
-
model_class.table_name
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class BelongsToOptions < AssocOptions
|
21
|
-
def initialize(name, options = {})
|
22
|
-
foreign_key_sym = "#{name}_id".to_sym
|
23
|
-
class_name_val = name.to_s.camelcase.singularize
|
24
|
-
send("primary_key=", :id)
|
25
|
-
send("foreign_key=", foreign_key_sym)
|
26
|
-
send("class_name=", class_name_val)
|
27
|
-
|
28
|
-
options.each do |attr, val|
|
29
|
-
send("#{attr}=", val)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class HasManyOptions < AssocOptions
|
35
|
-
def initialize(name, self_class_name, options = {})
|
36
|
-
foreign_key_sym = "#{self_class_name.underscore}_id".to_sym
|
37
|
-
class_name_val = name.to_s.camelcase.singularize
|
38
|
-
|
39
|
-
send("primary_key=", :id)
|
40
|
-
send("foreign_key=", foreign_key_sym)
|
41
|
-
send("class_name=", class_name_val)
|
42
|
-
|
43
|
-
options.each do |attr, val|
|
44
|
-
send("#{attr}=", val)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
module Associatable
|
50
|
-
def belongs_to(name, options = {})
|
51
|
-
options = BelongsToOptions.new(name, options)
|
52
|
-
assoc_options[name] = options
|
53
|
-
define_method(name) do
|
54
|
-
foreign_key = send(options.foreign_key)
|
55
|
-
primary_key = options.primary_key
|
56
|
-
params = [[primary_key, foreign_key]].to_h
|
57
|
-
options.model_class.where(params).first
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def has_many(name, options = {})
|
62
|
-
options = HasManyOptions.new(name, self.name, options)
|
63
|
-
define_method(name) do
|
64
|
-
foreign_key = options.foreign_key
|
65
|
-
primary_key = send(options.primary_key)
|
66
|
-
params = [[foreign_key, primary_key]].to_h
|
67
|
-
options.model_class.where(params)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def assoc_options
|
72
|
-
@assoc_options ||= {}
|
73
|
-
@assoc_options
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class SQLObject
|
78
|
-
extend Associatable
|
79
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require_relative '03_associatable'
|
2
|
-
|
3
|
-
module Associatable
|
4
|
-
def has_one_through(name, through_name, source_name)
|
5
|
-
define_method(name) do
|
6
|
-
through_options = self.class.assoc_options[through_name]
|
7
|
-
source_options =
|
8
|
-
through_options.model_class.assoc_options[source_name]
|
9
|
-
|
10
|
-
through_table = through_options.table_name
|
11
|
-
through_pk = through_options.primary_key
|
12
|
-
through_fk = through_options.foreign_key
|
13
|
-
|
14
|
-
source_table = source_options.table_name
|
15
|
-
source_pk = source_options.primary_key
|
16
|
-
source_fk = source_options.foreign_key
|
17
|
-
|
18
|
-
key_val = self.send(through_fk)
|
19
|
-
results = DBConnection.execute(<<-SQL, key_val)
|
20
|
-
SELECT
|
21
|
-
#{source_table}.*
|
22
|
-
FROM
|
23
|
-
#{through_table}
|
24
|
-
JOIN
|
25
|
-
#{source_table}
|
26
|
-
ON
|
27
|
-
#{through_table}.#{source_fk} = #{source_table}.#{source_pk}
|
28
|
-
WHERE
|
29
|
-
#{through_table}.#{through_pk} = ?
|
30
|
-
SQL
|
31
|
-
|
32
|
-
source_options.model_class.parse_all(results).first
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require_relative 'db_connection'
|
2
|
-
require_relative '01_sql_object'
|
3
|
-
|
4
|
-
module Searchable
|
5
|
-
def where(params)
|
6
|
-
where_line = params.keys.map { |attr_name| "#{attr_name} = ?" }.join(" AND ")
|
7
|
-
results = DBConnection.execute(<<-SQL, *params.values)
|
8
|
-
SELECT
|
9
|
-
*
|
10
|
-
FROM
|
11
|
-
#{self.table_name}
|
12
|
-
WHERE
|
13
|
-
#{where_line}
|
14
|
-
SQL
|
15
|
-
results.map { |attrs| self.new(attrs) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class SQLObject
|
20
|
-
extend Searchable
|
21
|
-
end
|