railz_lite 0.1.6 → 0.2.1
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 +8 -1
- data/lib/railz_lite/controllers/controller_base.rb +2 -2
- data/lib/railz_lite/controllers/static.rb +2 -2
- data/lib/railz_lite/generators/project.rb +8 -5
- data/lib/railz_lite/generators/templates/server.rb +7 -0
- 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/associatable.rb +23 -25
- data/lib/railz_lite/models/db_connection.rb +9 -6
- data/lib/railz_lite/models/searchable.rb +7 -10
- data/lib/railz_lite/models/sql_object.rb +5 -0
- data/lib/railz_lite/version.rb +1 -1
- metadata +3 -7
- data/exe/railz_lite.rb~ +0 -3
- data/lib/railz_lite/controllers/templates/rescue.html.erb~ +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: d9913416758845461437f605307b2a10be934ed1da34652947f9a2dcbfdb1caa
|
4
|
+
data.tar.gz: 33c8f9a302c65d3f4f55ebcd1682458de7a856d2c0c66c4fc6e1c614d64792e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 900a8e1808fdfc07b4c5638c1a7fb0cc3357c15fe9eaf8a563c8b56596716fc12ba038a75df0fe462ddd7f2bffc42c6367c6743e9184fe4d63c3be5e8cd384ec
|
7
|
+
data.tar.gz: 56cdd5db6f1d0b008f1ad9b34e24047da258601bd57b8d76723bf1ccd8a76bbad486c1ec7df5503965d3d0f1b1d3e7fb8e7939974e71739bfbee4d94ca762144
|
data/lib/railz_lite/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
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
|
@@ -9,14 +10,20 @@ module RailzLite
|
|
9
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')
|
15
16
|
if File.exist?(file)
|
17
|
+
DBConnection.start # load our db connection
|
16
18
|
system('ruby', file)
|
17
19
|
else
|
18
20
|
raise "File not found at #{file}"
|
19
21
|
end
|
20
22
|
end
|
23
|
+
|
24
|
+
desc 'db_reset', 'Restarts the database and reads db/app.sql file'
|
25
|
+
def db_reset
|
26
|
+
DBConnection.reset
|
27
|
+
end
|
21
28
|
end
|
22
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.split('_controller').first}", "#{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')
|
@@ -11,7 +11,6 @@ module RailzLite
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.destination_root
|
14
|
-
puts "destination for folder #{Dir.pwd}"
|
15
14
|
Dir.pwd
|
16
15
|
end
|
17
16
|
|
@@ -24,15 +23,19 @@ module RailzLite
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def add_server
|
27
|
-
template("#{project_name}/
|
26
|
+
template('server.rb', "#{project_name}/config/server.rb")
|
28
27
|
end
|
29
28
|
|
30
|
-
def
|
31
|
-
|
29
|
+
def add_welcome_view
|
30
|
+
template('welcome_view.index.html.erb', "#{project_name}/views/welcome/index.html.erb")
|
32
31
|
end
|
33
32
|
|
34
33
|
def add_public
|
35
|
-
|
34
|
+
copy_file('winter_fox_large.jpg', "#{project_name}/public/winter_fox_large.jpg")
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_sql_file
|
38
|
+
create_file("#{project_name}/db/app.sql")
|
36
39
|
end
|
37
40
|
end
|
38
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|
|
@@ -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
|
@@ -46,34 +46,32 @@ class HasManyOptions < AssocOptions
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
module
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
module RailzLite
|
50
|
+
module Associatable
|
51
|
+
def belongs_to(name, options = {})
|
52
|
+
options = BelongsToOptions.new(name, options)
|
53
|
+
assoc_options[name] = options
|
54
|
+
define_method(name) do
|
55
|
+
foreign_key = send(options.foreign_key)
|
56
|
+
primary_key = options.primary_key
|
57
|
+
params = [[primary_key, foreign_key]].to_h
|
58
|
+
options.model_class.where(params).first
|
59
|
+
end
|
58
60
|
end
|
59
|
-
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
def has_many(name, options = {})
|
63
|
+
options = HasManyOptions.new(name, self.name, options)
|
64
|
+
define_method(name) do
|
65
|
+
foreign_key = options.foreign_key
|
66
|
+
primary_key = send(options.primary_key)
|
67
|
+
params = [[foreign_key, primary_key]].to_h
|
68
|
+
options.model_class.where(params)
|
69
|
+
end
|
68
70
|
end
|
69
|
-
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def assoc_options
|
73
|
+
@assoc_options ||= {}
|
74
|
+
@assoc_options
|
75
|
+
end
|
74
76
|
end
|
75
77
|
end
|
76
|
-
|
77
|
-
class SQLObject
|
78
|
-
extend Associatable
|
79
|
-
end
|
@@ -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
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative 'db_connection'
|
2
|
-
require_relative 'sql_object'
|
3
2
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module RailzLite
|
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
8
|
SELECT
|
9
9
|
*
|
10
10
|
FROM
|
@@ -12,10 +12,7 @@ module Searchable
|
|
12
12
|
WHERE
|
13
13
|
#{where_line}
|
14
14
|
SQL
|
15
|
-
|
15
|
+
results.map { |attrs| self.new(attrs) }
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
|
-
|
19
|
-
class SQLObject
|
20
|
-
extend Searchable
|
21
|
-
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
require_relative 'db_connection'
|
2
|
+
require_relative 'associatable'
|
3
|
+
require_relative 'searchable'
|
2
4
|
require 'active_support/inflector'
|
3
5
|
|
4
6
|
module RailzLite
|
5
7
|
class SQLObject
|
8
|
+
extend RailzLite::Associatable
|
9
|
+
extend RailzLite::Searchable
|
10
|
+
|
6
11
|
def self.columns
|
7
12
|
@columns ||= DBConnection.execute2(<<-SQL)
|
8
13
|
SELECT
|
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.2.1
|
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,19 +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
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
|
174
173
|
- lib/railz_lite/models/associatable.rb
|
175
|
-
- lib/railz_lite/models/associatable.rb~
|
176
174
|
- lib/railz_lite/models/associatable2.rb
|
177
|
-
- lib/railz_lite/models/associatable2.rb~
|
178
175
|
- lib/railz_lite/models/attr_accessor_object.rb
|
179
176
|
- lib/railz_lite/models/db_connection.rb
|
180
177
|
- lib/railz_lite/models/searchable.rb
|
181
|
-
- lib/railz_lite/models/searchable.rb~
|
182
178
|
- lib/railz_lite/models/sql_object.rb
|
183
179
|
- lib/railz_lite/models/validatable.rb
|
184
180
|
- lib/railz_lite/version.rb
|
data/exe/railz_lite.rb~
DELETED
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
|