ramverk 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +31 -0
  5. data/.travis.yml +24 -0
  6. data/.yardopts +2 -0
  7. data/Gemfile +12 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +45 -0
  10. data/Rakefile +15 -0
  11. data/bin/ramverk +7 -0
  12. data/lib/ramverk/cli/command.rb +21 -0
  13. data/lib/ramverk/cli/commands/base.rb +31 -0
  14. data/lib/ramverk/cli/commands/console.rb +34 -0
  15. data/lib/ramverk/cli/commands/new.rb +35 -0
  16. data/lib/ramverk/cli/commands/server.rb +29 -0
  17. data/lib/ramverk/cli/commands/version.rb +8 -0
  18. data/lib/ramverk/cli/templates/new/.env.development.tt +0 -0
  19. data/lib/ramverk/cli/templates/new/.env.example.tt +7 -0
  20. data/lib/ramverk/cli/templates/new/.env.test.tt +0 -0
  21. data/lib/ramverk/cli/templates/new/.gitignore.tt +25 -0
  22. data/lib/ramverk/cli/templates/new/Gemfile.tt +21 -0
  23. data/lib/ramverk/cli/templates/new/Rakefile.tt +3 -0
  24. data/lib/ramverk/cli/templates/new/config/boot.rb.tt +9 -0
  25. data/lib/ramverk/cli/templates/new/config/environment.rb.tt +24 -0
  26. data/lib/ramverk/cli/templates/new/config.ru.tt +5 -0
  27. data/lib/ramverk/cli/templates/new/lib/project.rb.tt +4 -0
  28. data/lib/ramverk/cli/templates/new/spec/lib/project_spec.rb.tt +10 -0
  29. data/lib/ramverk/cli/templates/new/spec/spec_helper.rb.tt +14 -0
  30. data/lib/ramverk/configuration/dynamic_groups.rb +40 -0
  31. data/lib/ramverk/configuration/middleware.rb +48 -0
  32. data/lib/ramverk/configuration.rb +228 -0
  33. data/lib/ramverk/middleware/reloader.rb +23 -0
  34. data/lib/ramverk/middleware/request_logger.rb +61 -0
  35. data/lib/ramverk/middleware/static.rb +32 -0
  36. data/lib/ramverk/resolver.rb +47 -0
  37. data/lib/ramverk/setup.rb +37 -0
  38. data/lib/ramverk/string.rb +47 -0
  39. data/lib/ramverk/version.rb +6 -0
  40. data/lib/ramverk.rb +91 -0
  41. data/ramverk.gemspec +32 -0
  42. data/spec/fixtures/files/example.txt +1 -0
  43. data/spec/integration/cli/console_spec.rb +27 -0
  44. data/spec/integration/cli/new_spec.rb +49 -0
  45. data/spec/integration/cli/server_spec.rb +16 -0
  46. data/spec/integration/cli/version_spec.rb +8 -0
  47. data/spec/integration/rack_spec.rb +74 -0
  48. data/spec/integration/request_logger_spec.rb +33 -0
  49. data/spec/integration/serve_static_files_spec.rb +32 -0
  50. data/spec/spec_helper.rb +60 -0
  51. data/spec/support/cleaner.rb +33 -0
  52. data/spec/support/cli.rb +55 -0
  53. data/spec/support/matchers.rb +11 -0
  54. data/spec/support/rack.rb +20 -0
  55. data/spec/unit/configuration/dynamic_groups_spec.rb +37 -0
  56. data/spec/unit/configuration/middleware_spec.rb +35 -0
  57. data/spec/unit/configuration_spec.rb +167 -0
  58. data/spec/unit/ramverk_spec.rb +56 -0
  59. data/spec/unit/string_spec.rb +21 -0
  60. metadata +231 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3be3ea670be24bfeae059cca40a71c25e8160bcf2e6e8439af96e8026b839a98
4
+ data.tar.gz: 514a6b5dd743ab1e4d6ed4d43cc5f34585cd8f2c51af325a532368bb3a73dae5
5
+ SHA512:
6
+ metadata.gz: 813cf0310b75b77147415d47c776b26425fa36821d85f31870a5c1ba41f628f4311dd14f8c799046e10efdcf985926f4174e0f9b414773147383509f0cc01763
7
+ data.tar.gz: 63b93fb9c45997b7b6f66af7258ff2911c437c552c2c1a21fb56d16cf8e0f87bfc650496fa3070cf5297f21a96049b126b82bf099b41ad175321ff7dc022e888
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,31 @@
1
+ require: rubocop-performance
2
+ AllCops:
3
+ TargetRubyVersion: 2.6
4
+ NewCops: enable
5
+ DisplayCopNames: true
6
+ Exclude:
7
+ - "*.gemspec"
8
+ - "Gemfile"
9
+
10
+ Performance:
11
+ Enabled: true
12
+
13
+ Style/StringLiterals:
14
+ EnforcedStyle: double_quotes
15
+
16
+ Style/ClassAndModuleChildren:
17
+ Enabled: false
18
+
19
+ Layout/EmptyLineAfterGuardClause:
20
+ Enabled: false
21
+
22
+ Metrics/MethodLength:
23
+ Max: 15
24
+
25
+ Metrics/BlockLength:
26
+ Exclude:
27
+ - "spec/**/*"
28
+
29
+ Metrics/ModuleLength:
30
+ Exclude:
31
+ - "spec/**/*"
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
+ - 3.0.0
11
+ - 2.7.0
12
+ - 2.6.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,12 @@
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
11
+
12
+ gem "byebug"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 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,45 @@
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 functionality like logging, constant autoloading. We rather add, than remove, functionality.
6
+
7
+ ## Inspirations
8
+
9
+ - Ruby on Rails
10
+ - Phoenix Framework
11
+ - Hanami
12
+ - Sinatra
13
+
14
+ ## Status
15
+
16
+ Under development, not ready for prime-time just yet.
17
+
18
+ [![Build Status](https://travis-ci.org/sandelius/ramverk.svg?branch=master)](https://travis-ci.org/sandelius/ramverk)
19
+ [![codecov](https://codecov.io/gh/sandelius/ramverk/branch/master/graph/badge.svg)](https://codecov.io/gh/sandelius/ramverk)
20
+
21
+ ## Installation
22
+
23
+ Ramverk supports Ruby (MRI) 2.6+ and JRuby 9.2+
24
+
25
+ ```
26
+ $ gem install ramverk
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```bash
32
+ $ ramverk new petstore
33
+ ```
34
+
35
+ ```bash
36
+ $ cd petstore && bundle && ramverk server
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 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.
42
+
43
+ ## License
44
+
45
+ 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/bin/ramverk ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler"
5
+ require "ramverk/cli/command"
6
+
7
+ Ramverk::Cli::Command.start
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ramverk/cli/commands/base"
4
+
5
+ module Ramverk
6
+ module Cli
7
+ class Command < Commands::Base
8
+ # $ ramverk version
9
+ require "ramverk/cli/commands/version"
10
+
11
+ # $ ramverk new PROJECT_NAME
12
+ require "ramverk/cli/commands/new"
13
+
14
+ # $ ramverk server
15
+ require "ramverk/cli/commands/server"
16
+
17
+ # $ ramverk console
18
+ require "ramverk/cli/commands/console"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "thor"
5
+ require "shellwords"
6
+ require "ramverk/version"
7
+ require "ramverk/string"
8
+
9
+ module Ramverk
10
+ module Cli
11
+ module Commands
12
+ # @abstract
13
+ class Base < Thor
14
+ include Thor::Actions
15
+
16
+ # @private
17
+ self.source_paths << File.expand_path("../templates", __dir__)
18
+
19
+ no_commands do
20
+ def env
21
+ (ENV["APP_ENV"] || ENV["RACK_ENV"] || :development).to_sym
22
+ end
23
+
24
+ def escape(string)
25
+ Shellwords.escape(string)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ Ramverk::Cli::Command.class_eval do
4
+ desc "console", "Starts an interactive console session"
5
+ def console
6
+ puts "Loading #{env} environment..."
7
+
8
+ # Clear ARGV so IRB dont parse it
9
+ ARGV.shift until ARGV.empty?
10
+
11
+ # Add reload! helper method to console
12
+ TOPLEVEL_BINDING.eval("self").__send__(:include, Ramverk::Console::CodeReloading)
13
+
14
+ require File.expand_path("config/boot", Dir.pwd)
15
+
16
+ # Avoid "irb: warn: can't alias context from irb_context."
17
+ RSpec.configuration.disable_monkey_patching! if defined?(RSpec)
18
+
19
+ require "irb"
20
+ IRB.start
21
+ end
22
+ end
23
+
24
+ module Ramverk
25
+ class Console
26
+ module CodeReloading
27
+ # @private
28
+ def reload!
29
+ puts 'Reloading...'
30
+ Ramverk.configuration.autoload_loader.reload
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ Ramverk::Cli::Command.class_eval do
4
+ desc "new PROJECT_NAME", "Generates a new project structure"
5
+ def new(project_name)
6
+ project_name = escape(project_name)
7
+ project_name = Ramverk::String.underscore(project_name)
8
+ project_namespace = Ramverk::String.classify(project_name)
9
+
10
+ config = {
11
+ project_name: project_name,
12
+ project_namespace: project_namespace
13
+ }
14
+
15
+ root = Pathname.new(Dir.pwd).join(project_name)
16
+
17
+ template "new/.gitignore.tt", root.join(".gitignore"), config
18
+ template "new/Gemfile.tt", root.join("Gemfile"), config
19
+ template "new/Rakefile.tt", root.join("Rakefile"), config
20
+ template "new/config.ru.tt", root.join("config.ru"), config
21
+ template "new/.env.example.tt", root.join(".env.example"), config
22
+ template "new/.env.test.tt", root.join(".env.test"), config
23
+ template "new/.env.development.tt", root.join(".env.development"), config
24
+
25
+ template "new/lib/project.rb.tt", root.join("lib", "#{project_name}.rb"), config
26
+ create_file root.join("lib", project_name, ".gitkeep")
27
+
28
+ template "new/config/environment.rb.tt", root.join("config", "environment.rb"), config
29
+ template "new/config/boot.rb.tt", root.join("config", "boot.rb"), config
30
+
31
+ template "new/spec/spec_helper.rb.tt", root.join("spec", "spec_helper.rb"), config
32
+ template "new/spec/lib/project_spec.rb.tt", root.join("spec", "lib", "#{project_name}_spec.rb"), config
33
+ create_file root.join("spec", "support", ".gitkeep")
34
+ end
35
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rack"
4
+
5
+ Ramverk::Cli::Command.class_eval do
6
+ desc "server", "Starts the development server"
7
+ method_option :port, type: :numeric, aliases: "-p", default: 3000
8
+ def server
9
+ environment = ENV["APP_ENV"] || ENV["RACK_ENV"] || "development"
10
+
11
+ Ramverk::Server.new(
12
+ config: "config.ru",
13
+ Host: "0.0.0.0",
14
+ Port: options[:port],
15
+ AccessLog: [],
16
+ environment: environment
17
+ ).start
18
+ end
19
+ end
20
+
21
+ module Ramverk
22
+ class Server < Rack::Server
23
+ def middleware
24
+ mw = ::Hash.new { |e, m| e[m] = [] }
25
+ mw["development"].concat([::Rack::ShowExceptions])
26
+ mw
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ Ramverk::Cli::Command.class_eval do
4
+ desc "version", "Print framework version"
5
+ def version
6
+ puts Ramverk::VERSION
7
+ end
8
+ end
File without changes
@@ -0,0 +1,7 @@
1
+
2
+ # This is an example file that should show all required ENV variables.
3
+ #
4
+ # This file is also included in version control so DO NOT add and real
5
+ # credentials in here.
6
+
7
+ ENV_VAR=env_value
File without changes
@@ -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,21 @@
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
+ group :development, :test do
12
+ # A Ruby gem to load environment variables from `.env`.
13
+ gem "dotenv", "~> 2.7"
14
+ end
15
+
16
+ group :test do
17
+ # Behaviour Driven Development for Ruby.
18
+ gem "rspec", "~> 3.8"
19
+ # Rack::Test is a layer on top of Rack's MockRequest.
20
+ gem "rack-test", "~> 1.1"
21
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "config/environment"
@@ -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 "environment"
8
+
9
+ Ramverk.boot
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ require "ramverk/setup"
5
+
6
+ Ramverk.configure do |config|
7
+ # Paths of which Ramverk will autoload constants.
8
+ config.autoload_paths << "lib"
9
+
10
+ # DEVELOPMENT
11
+
12
+ config.environment :development do
13
+ end
14
+
15
+ # TEST
16
+
17
+ config.environment :test do
18
+ end
19
+
20
+ # PRODUCTION
21
+
22
+ config.environment :production do
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "config/environment"
4
+
5
+ run Ramverk.rack
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= config[:project_namespace] %>
4
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe <%= config[:project_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,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ramverk
4
+ class Configuration
5
+ # Module for creating configuration items on the fly.
6
+ module DynamicGroups
7
+ # @private
8
+ def method_missing(meth, *args, &block)
9
+ return super unless meth.to_s.end_with?("=")
10
+
11
+ key = meth.to_s.sub("=", "")
12
+ dynamic_groups[key] = args.first
13
+
14
+ define_singleton_method(key) { dynamic_groups[key] }
15
+ end
16
+
17
+ # @private
18
+ # :nocov:
19
+ def respond_to_missing?(name, include_private = false)
20
+ super
21
+ end
22
+ # :nocov:
23
+
24
+ # @private
25
+ def freeze
26
+ dynamic_groups.freeze
27
+ dynamic_groups.each_value(&:freeze)
28
+
29
+ super
30
+ end
31
+
32
+ private
33
+
34
+ # @private
35
+ def dynamic_groups
36
+ @dynamic_groups ||= {}
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ramverk
4
+ class Configuration
5
+ # Middleware manager.
6
+ class Middleware
7
+ # Return all registered middleware in the stack.
8
+ #
9
+ # @return [Array]
10
+ attr_reader :stack
11
+
12
+ # @private
13
+ def initialize
14
+ @stack = []
15
+ end
16
+
17
+ # Append a middleware to the stack.
18
+ #
19
+ # @param middleware [Class]
20
+ # @param *args [*]
21
+ # @param &block [Proc]
22
+ def append(middleware, *args, &block)
23
+ @stack << [middleware, args, block].freeze
24
+ end
25
+ alias use append
26
+
27
+ # Prepend a middleware to the stack.
28
+ #
29
+ # @param middleware [Class]
30
+ # @param *args [*]
31
+ # @param &block [Proc]
32
+ def prepend(middleware, *args, &block)
33
+ @stack.unshift [middleware, args, block].freeze
34
+ end
35
+
36
+ def run
37
+
38
+ end
39
+
40
+ # @private
41
+ def freeze
42
+ @stack.freeze
43
+
44
+ super
45
+ end
46
+ end
47
+ end
48
+ end