rails_lite 0.1.0

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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +8 -0
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +22 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +39 -0
  8. data/Rakefile +2 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/exe/railslite +4 -0
  12. data/lib/.DS_Store +0 -0
  13. data/lib/rails_lite.rb +6 -0
  14. data/lib/rails_lite/.DS_Store +0 -0
  15. data/lib/rails_lite/cli.rb +65 -0
  16. data/lib/rails_lite/version.rb +3 -0
  17. data/lib/scaffold/.DS_Store +0 -0
  18. data/lib/scaffold/Gemfile +12 -0
  19. data/lib/scaffold/app/controllers/albums_controller.rb +55 -0
  20. data/lib/scaffold/app/controllers/application_controller.rb +45 -0
  21. data/lib/scaffold/app/controllers/bands_controller.rb +62 -0
  22. data/lib/scaffold/app/controllers/notes_controller.rb +26 -0
  23. data/lib/scaffold/app/controllers/sessions_controller.rb +34 -0
  24. data/lib/scaffold/app/controllers/tracks_controller.rb +55 -0
  25. data/lib/scaffold/app/controllers/users_controller.rb +41 -0
  26. data/lib/scaffold/app/models/album.rb +14 -0
  27. data/lib/scaffold/app/models/application_model.rb +5 -0
  28. data/lib/scaffold/app/models/band.rb +7 -0
  29. data/lib/scaffold/app/models/note.rb +7 -0
  30. data/lib/scaffold/app/models/track.rb +20 -0
  31. data/lib/scaffold/app/models/user.rb +42 -0
  32. data/lib/scaffold/app/views/albums_controller/edit.html.erb +51 -0
  33. data/lib/scaffold/app/views/albums_controller/new.html.erb +50 -0
  34. data/lib/scaffold/app/views/albums_controller/show.html.erb +25 -0
  35. data/lib/scaffold/app/views/application.html.erb +41 -0
  36. data/lib/scaffold/app/views/bands_controller/edit.html.erb +16 -0
  37. data/lib/scaffold/app/views/bands_controller/index.html.erb +12 -0
  38. data/lib/scaffold/app/views/bands_controller/json.json.jbuilder +3 -0
  39. data/lib/scaffold/app/views/bands_controller/new.html.erb +15 -0
  40. data/lib/scaffold/app/views/bands_controller/show.html.erb +27 -0
  41. data/lib/scaffold/app/views/sessions_controller/new.html.erb +22 -0
  42. data/lib/scaffold/app/views/tracks_controller/edit.html.erb +60 -0
  43. data/lib/scaffold/app/views/tracks_controller/new.html.erb +59 -0
  44. data/lib/scaffold/app/views/tracks_controller/show.html.erb +56 -0
  45. data/lib/scaffold/app/views/users_controller/new.html.erb +22 -0
  46. data/lib/scaffold/app/views/users_controller/show.html.erb +4 -0
  47. data/lib/scaffold/bin/pry +13 -0
  48. data/lib/scaffold/bin/routes +10 -0
  49. data/lib/scaffold/bin/server +32 -0
  50. data/lib/scaffold/config/routes.rb +26 -0
  51. data/lib/scaffold/db/database.db +0 -0
  52. data/lib/scaffold/db/database.sql +48 -0
  53. data/lib/scaffold/lib/.DS_Store +0 -0
  54. data/lib/scaffold/lib/controller/controller_base.rb +183 -0
  55. data/lib/scaffold/lib/controller/controller_callbacks.rb +17 -0
  56. data/lib/scaffold/lib/controller/cookies/flash.rb +33 -0
  57. data/lib/scaffold/lib/controller/cookies/flash_now.rb +15 -0
  58. data/lib/scaffold/lib/controller/cookies/session.rb +29 -0
  59. data/lib/scaffold/lib/controller/strong_params.rb +40 -0
  60. data/lib/scaffold/lib/middleware/file_server.rb +42 -0
  61. data/lib/scaffold/lib/middleware/show_exceptions.rb +62 -0
  62. data/lib/scaffold/lib/middleware/static.rb +31 -0
  63. data/lib/scaffold/lib/middleware/templates/rescue.html.erb +49 -0
  64. data/lib/scaffold/lib/model/associations/assoc_options.rb +16 -0
  65. data/lib/scaffold/lib/model/associations/associatable.rb +120 -0
  66. data/lib/scaffold/lib/model/associations/belongs_to_options.rb +18 -0
  67. data/lib/scaffold/lib/model/associations/has_many_options.rb +17 -0
  68. data/lib/scaffold/lib/model/db_connection.rb +59 -0
  69. data/lib/scaffold/lib/model/model_base.rb +183 -0
  70. data/lib/scaffold/lib/model/model_callbacks.rb +46 -0
  71. data/lib/scaffold/lib/model/relations/relation.rb +151 -0
  72. data/lib/scaffold/lib/model/relations/searchable.rb +27 -0
  73. data/lib/scaffold/lib/model/validations/validations.rb +31 -0
  74. data/lib/scaffold/lib/model/validations/validator.rb +81 -0
  75. data/lib/scaffold/lib/router/route.rb +24 -0
  76. data/lib/scaffold/lib/router/router.rb +192 -0
  77. data/lib/scaffold/lib/utils/url_helpers.rb +96 -0
  78. data/lib/scaffold/public/main.css +165 -0
  79. data/rails_lite.gemspec +41 -0
  80. metadata +168 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 24a86519448b52873c72c9e48ea0cbb359c3628c0838ad4ca0ea5c51865c793e
4
+ data.tar.gz: 387288a3778af1cc88c1351291e8bb33f39289485174ee8d5a15e5db499fc21e
5
+ SHA512:
6
+ metadata.gz: 4bd1ecf8ede005ac6707fd5ac72a64238ed031ca0744c881139946f16e8e9e94f221ea4564e336bcfc3af891a02968fd44eb9af053a2368132aeeae32498c36d
7
+ data.tar.gz: 14657330fe9b7d75f31a4f5d85502256b3c6b4cb926c190c087252b0b7bf5a841a903283f7ca9c7f67a8bdd6ea46c9bb568af65128db43b8a0da6dccda6f6015
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rails_lite.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_lite (0.1.0)
5
+ thor
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ rake (10.5.0)
11
+ thor (0.20.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.17)
18
+ rails_lite!
19
+ rake (~> 10.0)
20
+
21
+ BUNDLED WITH
22
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Jeff DeLiso
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # RailsLite
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_lite`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails_lite'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails_lite
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_lite.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_lite"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/railslite ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rails_lite/cli'
3
+
4
+ RailsLite::CLI.start
data/lib/.DS_Store ADDED
Binary file
data/lib/rails_lite.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "rails_lite/version"
2
+
3
+ module RailsLite
4
+ class Error < StandardError; end
5
+
6
+ end
Binary file
@@ -0,0 +1,65 @@
1
+ require 'thor'
2
+ require 'fileutils'
3
+
4
+ module RailsLite
5
+
6
+ class CLI < Thor
7
+
8
+ desc "new", "Creates a new rails lite project"
9
+ method_option aliases: "n"
10
+ def new(*words)
11
+ words = ['new', 'app'] if words.empty?
12
+ name = words.join('_')
13
+ directory = File.dirname(__FILE__)
14
+ source = File.join(directory, "..", "scaffold")
15
+ FileUtils.cp_r source, FileUtils.pwd
16
+ FileUtils.mv(File.join(FileUtils.pwd, "scaffold"), File.join(FileUtils.pwd, name))
17
+ end
18
+
19
+ desc "server", "Starts the rails lite server"
20
+ method_option aliases: "s"
21
+ def server
22
+ root = FileUtils.pwd
23
+ file_name = File.join(root, 'bin', 'server')
24
+ if File.exist?(file_name)
25
+ system('bin/server')
26
+ else
27
+ puts "Not a rails lite directory"
28
+ end
29
+ end
30
+
31
+ desc "console", "Starts the rails lite console"
32
+ method_option aliases: "c"
33
+ def console
34
+ root = FileUtils.pwd
35
+ file_name = File.join(root, 'bin', 'pry')
36
+ if File.exist?(file_name)
37
+ system('bin/pry')
38
+ else
39
+ puts "Not a rails lite directory"
40
+ end
41
+ end
42
+
43
+ desc "routes", "Displays the current routes"
44
+ def routes
45
+ root = FileUtils.pwd
46
+ file_name = File.join(root, 'bin', 'routes')
47
+ if File.exist?(file_name)
48
+ system('bin/routes')
49
+ else
50
+ puts "Not a rails lite directory"
51
+ end
52
+ end
53
+
54
+ desc "dbreset", "Resets the database"
55
+ def dbreset
56
+ root = FileUtils.pwd
57
+ file_name = File.join(root, 'bin', 'routes')
58
+ if File.exist?(file_name)
59
+ system('bin/dbreset')
60
+ else
61
+ puts "Not a rails lite directory"
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module RailsLite
2
+ VERSION = "0.1.0"
3
+ end
Binary file
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rack'
4
+ gem 'byebug'
5
+ gem 'rspec', '~> 3.1.0'
6
+ gem 'activesupport'
7
+ gem 'puma'
8
+ gem 'sqlite3'
9
+ gem 'bcrypt'
10
+ gem 'thor'
11
+ gem 'pry'
12
+ gem 'jbuilder'
@@ -0,0 +1,55 @@
1
+ class AlbumsController < ApplicationController
2
+
3
+ def show
4
+ @album = Album.find(params[:id])
5
+ render :show
6
+ end
7
+
8
+ def new
9
+ @band = Band.find(params[:band_id])
10
+ @album = Album.new(band_id: params[:band_id])
11
+ render :new
12
+ end
13
+
14
+ def create
15
+ @album = Album.new(album_params)
16
+
17
+ if @album.save
18
+ redirect_to album_url(@album)
19
+ else
20
+ @band = @album.band
21
+ flash.now[:errors] = @album.errors
22
+ render :new
23
+ end
24
+ end
25
+
26
+ def edit
27
+ @album = Album.find(params[:id])
28
+ render :edit
29
+ end
30
+
31
+ def update
32
+ @album = Album.find(params[:id])
33
+
34
+ if @album.update_attributes(album_params)
35
+ redirect_to album_url(@album)
36
+ else
37
+ flash.now[:errors] = @album.errors
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ def destroy
43
+ @album = Album.find(params[:id])
44
+ @album.destroy
45
+ redirect_to band_url(@album.band_id)
46
+ end
47
+
48
+ private
49
+
50
+ def album_params
51
+ params.require(:album).permit(:band_id, :live, :name, :year)
52
+ end
53
+
54
+ before_action :ensure_login, except: [:index]
55
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../../lib/controller/controller_base'
2
+
3
+ class ApplicationController < ControllerBase
4
+
5
+ def current_user
6
+ @current_user ||= User.find_by(session_token: session[:session_token])
7
+ end
8
+
9
+ def ensure_login
10
+ unless logged_in?
11
+ flash[:errors] = ['must be logged in']
12
+ redirect_to new_sessions_url
13
+
14
+ true
15
+ else
16
+ false
17
+ end
18
+ end
19
+
20
+ def ensure_logout
21
+ if logged_in?
22
+ flash[:errors] = ['already logged in']
23
+ redirect_to bands_url
24
+
25
+ true
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ def login(user)
32
+ @current_user = user
33
+ session[:session_token] = user.reset_token!
34
+ end
35
+
36
+ def logout
37
+ current_user.reset_token!
38
+ session[:session_token] = nil
39
+ @current_user = nil
40
+ end
41
+
42
+ def logged_in?
43
+ !!current_user
44
+ end
45
+ end
@@ -0,0 +1,62 @@
1
+ class BandsController < ApplicationController
2
+ protect_from_forgery
3
+
4
+ def index
5
+ @bands = Band.all
6
+ render :index
7
+ end
8
+
9
+ def show
10
+ @band = Band.find(params[:id])
11
+ render :show
12
+ end
13
+
14
+ def new
15
+ @band = Band.new
16
+ render :new
17
+ end
18
+
19
+ def create
20
+ @band = Band.new(band_params)
21
+
22
+ if @band.save
23
+ redirect_to band_url(@band)
24
+ else
25
+ flash.now[:errors] = @band.errors.full_messages
26
+ render :new
27
+ end
28
+ end
29
+
30
+ def edit
31
+ @band = Band.find(params[:id])
32
+ render :edit
33
+ end
34
+
35
+ def update
36
+ @band = Band.find(params[:id])
37
+ if @band.update_attributes(band_params)
38
+ redirect_to band_url(@band)
39
+ else
40
+ flash.now[:errors] = @band.errors.full_messages
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ def destroy
46
+ @band = Band.find(params[:id])
47
+ @band.destroy
48
+ redirect_to bands_url
49
+ end
50
+
51
+ def json
52
+ @bands = Band.all
53
+ end
54
+
55
+ private
56
+
57
+ def band_params
58
+ params.require(:band).permit(:name)
59
+ end
60
+
61
+ before_action :ensure_login
62
+ end
@@ -0,0 +1,26 @@
1
+ class NotesController < ApplicationController
2
+ protect_from_forgery
3
+
4
+ def create
5
+ note = Note.new(note_params)
6
+ note.user_id = current_user.id
7
+ note.save
8
+ flash[:errors] = note.errors
9
+
10
+ redirect_to track_url(note.track_id)
11
+ end
12
+
13
+ def destroy
14
+ note = Note.find(params[:id])
15
+ note.destroy
16
+ redirect_to track_url(note.track_id)
17
+ end
18
+
19
+ private
20
+
21
+ def note_params
22
+ params.require(:note).permit(:content, :track_id)
23
+ end
24
+
25
+ before_action :ensure_login, only: [:create, :destroy]
26
+ end