ramverk 0.10.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ramverk might be problematic. Click here for more details.

Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +36 -0
  5. data/.travis.yml +24 -0
  6. data/.yardopts +2 -0
  7. data/Gemfile +10 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +51 -0
  10. data/Rakefile +15 -0
  11. data/bench/config.ru +23 -0
  12. data/bin/app/.env.development.tt +1 -0
  13. data/bin/app/.env.example.tt +6 -0
  14. data/bin/app/.env.test.tt +1 -0
  15. data/bin/app/.gitignore.tt +25 -0
  16. data/bin/app/Gemfile.tt +27 -0
  17. data/bin/app/Rakefile.tt +3 -0
  18. data/bin/app/config/application.rb.tt +30 -0
  19. data/bin/app/config/boot.rb.tt +9 -0
  20. data/bin/app/config/database.rb.tt +13 -0
  21. data/bin/app/config/routes.rb.tt +7 -0
  22. data/bin/app/config.ru.tt +5 -0
  23. data/bin/app/lib/app.rb.tt +4 -0
  24. data/bin/app/spec/lib/app_spec.rb.tt +10 -0
  25. data/bin/app/spec/spec_helper.rb.tt +14 -0
  26. data/bin/app/web/controllers/application.rb.tt +4 -0
  27. data/bin/ramverk +126 -0
  28. data/lib/ramverk/application.rb +147 -0
  29. data/lib/ramverk/configuration/middleware.rb +44 -0
  30. data/lib/ramverk/configuration.rb +219 -0
  31. data/lib/ramverk/controller/configuration.rb +41 -0
  32. data/lib/ramverk/controller/cookies.rb +47 -0
  33. data/lib/ramverk/controller.rb +198 -0
  34. data/lib/ramverk/middleware/body_parser.rb +47 -0
  35. data/lib/ramverk/middleware/reloader.rb +23 -0
  36. data/lib/ramverk/middleware/request_logger.rb +59 -0
  37. data/lib/ramverk/router/methods.rb +117 -0
  38. data/lib/ramverk/router/mount.rb +40 -0
  39. data/lib/ramverk/router/route.rb +79 -0
  40. data/lib/ramverk/router/scope.rb +40 -0
  41. data/lib/ramverk/router.rb +129 -0
  42. data/lib/ramverk/setup.rb +32 -0
  43. data/lib/ramverk/version.rb +6 -0
  44. data/lib/ramverk.rb +55 -0
  45. data/ramverk.gemspec +31 -0
  46. data/spec/integration/body_parser_spec.rb +47 -0
  47. data/spec/integration/controller/cookies_spec.rb +49 -0
  48. data/spec/integration/rack_spec.rb +50 -0
  49. data/spec/integration/request_logger_spec.rb +37 -0
  50. data/spec/spec_helper.rb +60 -0
  51. data/spec/support/cleaner.rb +31 -0
  52. data/spec/support/matchers.rb +6 -0
  53. data/spec/support/rack.rb +20 -0
  54. data/spec/unit/application_spec.rb +72 -0
  55. data/spec/unit/configuration/middleware_spec.rb +35 -0
  56. data/spec/unit/configuration_spec.rb +180 -0
  57. data/spec/unit/controller/configuration_spec.rb +58 -0
  58. data/spec/unit/controller/filters_spec.rb +58 -0
  59. data/spec/unit/controller/redirect_spec.rb +37 -0
  60. data/spec/unit/controller/render_spec.rb +19 -0
  61. data/spec/unit/ramverk_spec.rb +70 -0
  62. data/spec/unit/router/mount_spec.rb +53 -0
  63. data/spec/unit/router/route_spec.rb +61 -0
  64. data/spec/unit/router/scope_spec.rb +54 -0
  65. data/spec/unit/router_spec.rb +76 -0
  66. metadata +225 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 28eef213a5325174e9e19b7ddc0f4c193ee653e0244359efe8d5175fce87972c
4
+ data.tar.gz: a9a6637ba266ca738295232ef87585e593787e1690a0deaebf03aa1da458a72f
5
+ SHA512:
6
+ metadata.gz: 4b5eadb631701e67f10de639dccb52fb13190b8351a2d0569f1caff922296eafca455c081ffda6fb04288e20f43d5fa12fb0c26b0f8a7058e6d1ebe77e516513
7
+ data.tar.gz: c1ce438441d106c40157ea74475d286db796c8f2b0aa59797b17e25bd758a10781e90df6af725c42e31cc8055162bc14b0dcfb71069628e2bf7ffdab74ff0234
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /tmp/
10
+ .DS_Store
11
+ /doc
12
+ /spec/tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,36 @@
1
+ require: rubocop-performance
2
+ AllCops:
3
+ TargetRubyVersion: 2.5
4
+ NewCops: enable
5
+ DisplayCopNames: true
6
+ Exclude:
7
+ - "*.gemspec"
8
+ - "Gemfile"
9
+ - "bench/*"
10
+ - "bin/*"
11
+
12
+ Performance:
13
+ Enabled: true
14
+
15
+ Style/StringLiterals:
16
+ EnforcedStyle: double_quotes
17
+
18
+ Style/ClassAndModuleChildren:
19
+ Enabled: false
20
+
21
+ Layout/EmptyLineAfterGuardClause:
22
+ Enabled: false
23
+
24
+ Metrics/MethodLength:
25
+ Max: 15
26
+
27
+ Metrics/BlockLength:
28
+ Exclude:
29
+ - "spec/**/*"
30
+
31
+ Metrics/ModuleLength:
32
+ Exclude:
33
+ - "spec/**/*"
34
+
35
+ Naming/MethodParameterName:
36
+ MinNameLength: 2
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ script: "bundle exec rake spec:coverage"
3
+ cache: bundler
4
+ env:
5
+ global:
6
+ - CODECOV_TOKEN="52b505b7-f1b3-46d1-b6ec-efc17dd4558f"
7
+ before_install:
8
+ - "gem update --system"
9
+ rvm:
10
+ - 2.7.0
11
+ - 2.6.0
12
+ - 2.5.0
13
+ - ruby-head
14
+ - jruby
15
+ - jruby-head
16
+ - truffleruby
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: jruby-head
20
+ - rvm: ruby-head
21
+ - rvm: truffleruby
22
+ branches:
23
+ only:
24
+ - master
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --no-private
2
+ -m markdown
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "rubocop"
7
+ gem "rubocop-performance"
8
+
9
+ gem "simplecov"
10
+ gem 'codecov', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Tobias Sandelius
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,51 @@
1
+ # Ramverk
2
+
3
+ Ramverk is a web application framework written in Ruby.
4
+
5
+ The goal of Ramverk is to keep the core framework as neat as possible and only include basic
6
+ functionality like logging, constant autoloading. We rather add, than remove, functionality.
7
+
8
+ While Ramverk comes with an application generator, the directory structure is not set in stone and
9
+ can be adjusted to fit your needs. Start small with only one file and grow into a modular MVC structure.
10
+ Or start big directly, your choice.
11
+
12
+ ## Inspirations
13
+
14
+ - Ruby on Rails
15
+ - Phoenix Framework
16
+ - Hanami
17
+ - Sinatra
18
+
19
+ ## Status
20
+
21
+ Under development, not ready for prime-time just yet.
22
+
23
+ [![Build Status](https://travis-ci.org/sandelius/ramverk.svg?branch=master)](https://travis-ci.org/sandelius/ramverk)
24
+ [![codecov](https://codecov.io/gh/sandelius/ramverk/branch/master/graph/badge.svg)](https://codecov.io/gh/sandelius/ramverk)
25
+ [![Inline docs](http://inch-ci.org/github/sandelius/ramverk.svg?branch=master)](http://inch-ci.org/github/sandelius/ramverk)
26
+
27
+ ## Installation
28
+
29
+ Ramverk supports Ruby (MRI) 2.5+ and JRuby 9.2+
30
+
31
+ ```
32
+ $ gem install ramverk
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ```bash
38
+ $ ramverk new petstore
39
+ ```
40
+
41
+ ```bash
42
+ $ cd petstore && bundle && ramverk server
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sandelius/ramverk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ namespace :spec do
9
+ task :coverage do
10
+ ENV["COVERAGE"] = "true"
11
+ Rake::Task["spec"].invoke
12
+ end
13
+ end
14
+
15
+ task default: :spec
data/bench/config.ru ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ require_relative "../lib/ramverk"
5
+
6
+ # puma -e production -t 16:16
7
+ class Application < Ramverk::Application
8
+ config.logger = nil
9
+
10
+ routes do
11
+ # wrk -t 2 http://localhost:9292/
12
+ root do
13
+ render "Hello World"
14
+ end
15
+
16
+ # wrk -t 2 http://localhost:9292/ruby
17
+ get "/:lang" do
18
+ render params["lang"]
19
+ end
20
+ end
21
+ end
22
+
23
+ run Application.new
@@ -0,0 +1 @@
1
+ DATABASE_URL=postgres://user:password@localhost/<%= app_name %>_development
@@ -0,0 +1,6 @@
1
+ # This is an example file that should show all required ENV variables.
2
+ #
3
+ # This file is also included in version control so DO NOT add and real
4
+ # credentials in here.
5
+
6
+ DATABASE_URL=postgres://user:password@localhost/dbname
@@ -0,0 +1 @@
1
+ DATABASE_URL=postgres://user:password@localhost/<%= app_name %>_test
@@ -0,0 +1,25 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ /log/*
12
+ /tmp/*
13
+
14
+ # Assets
15
+ /node_modules
16
+
17
+ # Dotenv
18
+ /.env
19
+ /.env.development
20
+ /.env.test
21
+
22
+ # Misc
23
+ .byebug_history
24
+ .DS_Store
25
+ /coverage
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # A make-like build utility for Ruby.
6
+ gem "rake"
7
+
8
+ # The Ruby Application Framework.
9
+ gem "ramverk", "~> <%= Ramverk::VERSION %>"
10
+
11
+ # Database (Sequel) integration.
12
+ gem "ramverk-database", "~> 0.1"
13
+
14
+ # Database adapter.
15
+ gem "pg"
16
+
17
+ group :development, :test do
18
+ # A Ruby gem to load environment variables from `.env`.
19
+ gem "dotenv", "~> 2.7"
20
+ end
21
+
22
+ group :test do
23
+ # Behaviour Driven Development for Ruby.
24
+ gem "rspec", "~> 3.8"
25
+ # Rack::Test is a layer on top of Rack's MockRequest.
26
+ gem "rack-test", "~> 1.1"
27
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "config/application"
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ require "ramverk/setup"
5
+
6
+ module <%= app_namespace %>
7
+ class Application < Ramverk::Application
8
+ require_relative "routes"
9
+ require_relative "database"
10
+
11
+ # Paths of which Ramverk will autoload constants.
12
+ config.autoload_paths << "lib"
13
+ config.autoload_paths << "web"
14
+
15
+ # DEVELOPMENT
16
+
17
+ config.environment :development do
18
+ end
19
+
20
+ # TEST
21
+
22
+ config.environment :test do
23
+ end
24
+
25
+ # PRODUCTION
26
+
27
+ config.environment :production do
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is only used when booting up your application outside of a web
4
+ # request. Background workers is one common use case where this file should
5
+ # be loaded.
6
+
7
+ require_relative "application"
8
+
9
+ Ramverk.application.boot
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ramverk/database"
4
+
5
+ Ramverk.application do
6
+ extend Ramverk::Database
7
+
8
+ # Connection credentials
9
+ config.database.connection = ENV.fetch("DATABASE_URL")
10
+
11
+ # Autoload models as root constants
12
+ config.autoload_paths << "lib/models"
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ Ramverk.application.routes do
4
+ scope namespace: "Controllers" do
5
+ # Routes DSL
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "config/application"
4
+
5
+ run Ramverk.application.new
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= app_namespace %>
4
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe <%= app_namespace %> do
6
+ it "works" do
7
+ expect(true)
8
+ .to eq(true)
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV["APP_ENV"] = "test"
4
+
5
+ require_relative "../config/boot"
6
+
7
+ # Requires supporting ruby files used for testing.
8
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
9
+
10
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ # Disable monkey-pachting core ruby.
13
+ config.disable_monkey_patching!
14
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Controllers::Application < Ramverk::Controller
4
+ end
data/bin/ramverk ADDED
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "pathname"
5
+ require "erb"
6
+ require "ostruct"
7
+ require "fileutils"
8
+ require "bundler"
9
+ require "rack"
10
+ require "ramverk/version"
11
+
12
+ def help
13
+ puts <<~HELP
14
+ ramverk new APP_NAME # Generate a new application
15
+ ramverk s[erver] # Start Ramverk development server
16
+ ramverk version # Print framework version
17
+ HELP
18
+ end
19
+
20
+ def erb(source, destination, **locals)
21
+ file = File.join(__dir__, "app", source)
22
+ body = File.read(file)
23
+ context = OpenStruct.new(locals)
24
+ result = ERB.new(body).result(context.instance_eval { binding })
25
+
26
+ FileUtils.mkdir_p(File.dirname(destination))
27
+ File.write(destination, result)
28
+
29
+ text = destination.sub("#{Dir.pwd}/", "")
30
+ puts "created: #{text}"
31
+ end
32
+
33
+ def touch(destination)
34
+ FileUtils.mkdir_p(File.dirname(destination))
35
+ FileUtils.touch destination
36
+
37
+ text = destination.sub("#{Dir.pwd}/", "")
38
+ puts "created: #{text}"
39
+ end
40
+
41
+ def app(args)
42
+ if args.empty?
43
+ puts "APP_NAME is required: ramverk new my_app"
44
+ exit
45
+ end
46
+
47
+ name = args.shift
48
+
49
+ locals = {}
50
+ locals[:app_name] = name.downcase
51
+ locals[:app_namespace] = camelize(locals[:app_name])
52
+
53
+ root = Pathname.new(Dir.pwd).join(locals[:app_name])
54
+
55
+ # ./
56
+ erb "config.ru.tt", root.join("config.ru"), **locals
57
+ erb "Rakefile.tt", root.join("Rakefile"), **locals
58
+ erb "Gemfile.tt", root.join("Gemfile"), **locals
59
+ erb ".gitignore.tt", root.join(".gitignore"), **locals
60
+ erb ".env.example.tt", root.join(".env.example"), **locals
61
+ erb ".env.development.tt", root.join(".env.development"), **locals
62
+ erb ".env.test.tt", root.join(".env.test"), **locals
63
+
64
+ # ./config
65
+ erb "config/application.rb.tt", root.join("config", "application.rb"), **locals
66
+ erb "config/boot.rb.tt", root.join("config", "boot.rb"), **locals
67
+ erb "config/database.rb.tt", root.join("config", "database.rb"), **locals
68
+ erb "config/routes.rb.tt", root.join("config", "routes.rb"), **locals
69
+
70
+ # ./lib
71
+ erb "lib/app.rb.tt", root.join("lib", "#{locals[:app_name]}.rb"), **locals
72
+ touch root.join("lib", "#{locals[:app_name]}", ".gitkeep")
73
+ touch root.join("lib", "models", ".gitkeep")
74
+
75
+ # ./spec
76
+ erb "spec/spec_helper.rb.tt", root.join("spec", "spec_helper.rb"), **locals
77
+ erb "spec/lib/app_spec.rb.tt", root.join("spec", "lib", "#{locals[:app_name]}_spec.rb"), **locals
78
+ touch root.join("spec", "lib", "models", ".gitkeep")
79
+ touch root.join("spec", "support", ".gitkeep")
80
+
81
+ # ./public
82
+ touch root.join("public", ".gitkeep")
83
+
84
+ # ./web
85
+ erb "web/controllers/application.rb.tt", root.join("web", "controllers", "application.rb"), **locals
86
+ end
87
+
88
+ def camelize(name)
89
+ name.split(/_|-/).map(&:capitalize).join
90
+ end
91
+
92
+ module Ramverk
93
+ class Server < Rack::Server
94
+ def middleware
95
+ mw = ::Hash.new { |e, m| e[m] = [] }
96
+ mw["development"].concat([::Rack::ShowExceptions])
97
+ mw
98
+ end
99
+ end
100
+ end
101
+
102
+ def server(_argv)
103
+ port = ENV["PORT"]&.to_i || 3000
104
+
105
+ Ramverk::Server.new(config: "config.ru",
106
+ Host: "0.0.0.0",
107
+ Port: port,
108
+ AccessLog: []).start
109
+ end
110
+
111
+ command = ARGV.shift
112
+
113
+ case command
114
+ when "server", "s"
115
+ server(ARGV)
116
+ exit
117
+ when "version"
118
+ puts Ramverk::VERSION
119
+ exit
120
+ when "new"
121
+ app(ARGV)
122
+ exit
123
+ else
124
+ help
125
+ exit
126
+ end