yaframework 0.3.0 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f292d6a4e199c7cbd9d9375649f311bfc3889c86212d8a30316a37d65685b90d
4
- data.tar.gz: a3715a27f85ef444a996edd039323dc15e6621f518c33c278d06fceeb6cf75c1
3
+ metadata.gz: ef685ddc4ab38b92f223ce779b2e57b27473556cdbdcb8a93bdf8269f7cb27ff
4
+ data.tar.gz: f89e2a1d07968d32b50ac56fe1aa7669d7f02c31ede5d7e7d0ccb09deb48c36d
5
5
  SHA512:
6
- metadata.gz: 2f152b5b3f1198fa48e2eb434ce38a9254970c3f4a82571d6ea9359ee531c2c39c663a65fa674c512c897d3bed269d6aa3d7858937047c22f911d5c5cfd8af73
7
- data.tar.gz: ad9ddf07e7ce153c3b55cbb48389628dcbc055f3dd23101eede3e28040961a47cd7c83a26fe46de824c96995cf35502ab2cb49856e50fba0aa2a04f48a5d9318
6
+ metadata.gz: 8bad4c17c6e830f8c2897112375da39947326a8f204db2a52dd41d99ed7c963a31f8f0b2ad05228bd50226cb4d82e995e5752c2be73f0ede1306e24b79f48ead
7
+ data.tar.gz: 32ee2f926d51b6324427f295bcebfd46958da7f364d7dbbdf80270777a486e5513ce75f50725fbe1c466ac304271fb2edbef0e864e3b5441a7af8b225bca30bf
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  /tmp/
13
13
  *.gem
14
14
  *.rbc
15
+ /examples/**/Gemfile.lock
data/.rubocop.yml CHANGED
@@ -16,5 +16,11 @@ Style/Documentation:
16
16
  Metrics/MethodLength:
17
17
  Enabled: false
18
18
 
19
+ Metrics/AbcSize:
20
+ Max: 25
21
+
19
22
  Layout/LineLength:
20
23
  Max: 120
24
+
25
+ Style/SpecialGlobalVars:
26
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [0.4.3] - 2021-07-24
2
+
3
+ - Updated the method for changing the Content-Type
4
+ - Interaction with headers has been improved
5
+
6
+ ## [0.4.2] - 2021-07-24
7
+
8
+ - DB module removed
9
+
10
+ ## [0.4.1] - 2021-07-24
11
+
12
+ - A little fix. Fixed an error with the wrong order of declaring variables (lol)
13
+
14
+ ## [0.4.0] - 2021-07-24
15
+
16
+ - Global routing update and large-scale code base changes
17
+
18
+ ## [0.3.0] - 2021-07-24
19
+
20
+ - Added tools for interacting with the database
21
+
1
22
  ## [0.2.2] - 2021-07-23
2
23
 
3
24
  - Params fixed
data/Gemfile CHANGED
@@ -5,5 +5,4 @@ source "https://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  gem "minitest", "~> 5.0"
8
- gem 'pg', '~> 1.2', '>= 1.2.3'
9
8
  gem "rack", "~> 2.2", ">= 2.2.3"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaframework (0.2.2)
4
+ yaframework (0.4.2)
5
5
  rack (~> 2.2)
6
6
 
7
7
  GEM
@@ -36,7 +36,7 @@ PLATFORMS
36
36
  ruby
37
37
 
38
38
  DEPENDENCIES
39
- bundler (~> 2.1.4)
39
+ bundler (>= 2.2.10)
40
40
  minitest (~> 5.0)
41
41
  pg (~> 1.2, >= 1.2.3)
42
42
  rack (~> 2.2, >= 2.2.3)
@@ -45,4 +45,4 @@ DEPENDENCIES
45
45
  yaframework!
46
46
 
47
47
  BUNDLED WITH
48
- 2.1.4
48
+ 2.2.16
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Yaframework
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/yaframework.svg)](https://badge.fury.io/rb/sinatra)
3
+ [![Gem Version](https://badge.fury.io/rb/yaframework.svg)](https://badge.fury.io/rb/yaframework)
4
4
  [![Build Status](https://app.travis-ci.com/maxbarsukov/yaframework.svg?token=T4CL2EqKG6FY816F3W3F&branch=master)](https://app.travis-ci.com/maxbarsukov/yaframework)
5
5
 
6
6
  Yaframework is a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language) for
data/examples/README.md CHANGED
@@ -2,9 +2,16 @@
2
2
 
3
3
  Here are some examples of applications created with Yaframework:
4
4
 
5
- 1. [**Hello World**](https://github.com/maxbarsukov/yaframework/tree/master/examples/hello-world)
5
+ 1. ###[Hello World](https://github.com/maxbarsukov/yaframework/tree/master/examples/hello-world)
6
6
 
7
7
  A simple application that displays "Hello world" to you.
8
8
 
9
9
 
10
- 2. Be soon...
10
+ 2. ###[Params](https://github.com/maxbarsukov/yaframework/tree/master/examples/params)
11
+
12
+ Shows how the application parameters can be used
13
+
14
+
15
+ 3. ###[Halts and Redirects](https://github.com/maxbarsukov/yaframework/tree/master/examples/halts-and-redirects)
16
+
17
+ Shows how to use halts and redirects
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "yaframework"
@@ -0,0 +1,12 @@
1
+ # Params
2
+
3
+ Shows how to use halts and redirects
4
+
5
+ ## Installation
6
+
7
+ Clone this repo and go to this folder.
8
+ Then, run `bundle install` to install this gem.
9
+
10
+ ## Run
11
+
12
+ Run with `ruby app.rb` or `rackup` and view at http://localhost:4567
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaframework"
4
+ app = Yaframework::Application
5
+
6
+ app.get "/" do
7
+ response.redirect "/hello"
8
+ end
9
+
10
+ app.get "/hello" do
11
+ "Hello world!"
12
+ end
13
+
14
+ app.get "/error" do
15
+ response.status = 401
16
+ halt response.finish
17
+ end
18
+
19
+ app.listen(4567)
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaframework"
4
+ require "./app"
5
+
6
+ run app
@@ -2,4 +2,4 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "yaframework", path: "/home/max/prog/ruby/yaframework"
5
+ gem "yaframework"
@@ -7,8 +7,4 @@ app.get "/" do
7
7
  "Hello world!"
8
8
  end
9
9
 
10
- app.get "/hi/:name" do
11
- "Hello #{request.params[:name]}"
12
- end
13
-
14
10
  app.listen(4567)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "yaframework"
@@ -0,0 +1,12 @@
1
+ # Params
2
+
3
+ Shows how the application parameters can be used
4
+
5
+ ## Installation
6
+
7
+ Clone this repo and go to this folder.
8
+ Then, run `bundle install` to install this gem.
9
+
10
+ ## Run
11
+
12
+ Run with `ruby app.rb` or `rackup` and view at http://localhost:4567
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaframework"
4
+ app = Yaframework::Application
5
+
6
+ app.get "/:name" do
7
+ "Hello #{request.params[:name]}!"
8
+ end
9
+
10
+ app.get "/:name/foo/:bar" do
11
+ "Hello #{request.params[:name]} from #{request.params[:bar]}!"
12
+ end
13
+
14
+ app.listen(4567)
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaframework"
4
+ require "./app"
5
+
6
+ run app
data/lib/yaframework.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "yaframework/base"
4
- require_relative "yaframework/database"
5
- require_relative 'yaframework/request'
6
- require_relative 'yaframework/response'
4
+ require_relative "yaframework/request"
5
+ require_relative "yaframework/response"
7
6
 
8
7
  module Yaframework
9
8
  end
@@ -4,11 +4,10 @@ require "rack"
4
4
 
5
5
  module Yaframework
6
6
  class Base
7
- attr_reader :routes, :request, :response, :env, :hello
7
+ attr_reader :routes, :request, :response, :env
8
8
 
9
9
  def initialize
10
- @routes = Hash.new { |h, k| h[k] = [] }
11
- # @routes = Hash.new([])
10
+ @routes = Hash.new([])
12
11
  end
13
12
 
14
13
  %w[GET POST PATCH PUT DELETE HEAD OPTIONS].each do |verb|
@@ -36,12 +35,10 @@ module Yaframework
36
35
 
37
36
  def add_route(verb, path, &handler)
38
37
  path = "/#{path}" unless path[0] == "/"
39
-
40
- @routes[verb] ||= []
41
- @routes[verb] << compile_route(path, &handler)
38
+ @routes[verb] << compile(path, &handler)
42
39
  end
43
40
 
44
- def compile_route(path, &handler)
41
+ def compile(path, &handler)
45
42
  route = { handler: handler, compiled_path: nil, extra_params: [], path: path }
46
43
 
47
44
  compiled_path = path.gsub(/:\w+/) do |match|
@@ -59,17 +56,16 @@ module Yaframework
59
56
  else
60
57
  response.status = 404
61
58
  end
62
-
63
59
  response.finish
64
60
  end
65
61
 
66
62
  def find_route
67
- route = @routes[request.request_method].detect do |r|
63
+ route = routes[request.request_method].detect do |r|
68
64
  r[:compiled_path] =~ request.path_info
69
65
  end
70
66
 
71
67
  if route
72
- $LAST_MATCH_INFO.captures.each_with_index do |value, index|
68
+ $~.captures.each_with_index do |value, index|
73
69
  param = route[:extra_params][index]
74
70
  request.params[param] = value
75
71
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rack/request"
4
+
5
+ module Yaframework
6
+ class Request < Rack::Request
7
+ def initialize(env)
8
+ env["PATH_INFO"] = "/" if env["PATH_INFO"].empty?
9
+ super
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yaframework
4
+ class Response
5
+ LOCATION = "Location"
6
+
7
+ module ContentType
8
+ HTML = "text/html"
9
+ TEXT = "text/plain"
10
+ JSON = "application/json"
11
+ end
12
+
13
+ attr_accessor :status
14
+ attr_reader :headers, :body
15
+
16
+ def initialize(body = [], status = 200, headers = { "Content-Type" => "text/html; charset=utf-8" })
17
+ @body = []
18
+ @headers = headers
19
+ @status = status
20
+ @length = 0
21
+
22
+ if body.respond_to? :to_str
23
+ write body.to_str
24
+ elsif body.respond_to? :each
25
+ body.each { |i| write i.to_s }
26
+ else
27
+ raise TypeError, "Body must #respond_to? #to_str or #each"
28
+ end
29
+ end
30
+
31
+ def finish
32
+ @headers[Rack::CONTENT_LENGTH] = @length.to_s unless (100..199).include?(status) || status == 204
33
+ [status, headers, body]
34
+ end
35
+
36
+ def redirect(target, status = 302)
37
+ @status = status
38
+ @headers[LOCATION] = target
39
+ end
40
+
41
+ def write(string)
42
+ s = string.to_s
43
+ @length += s.bytesize
44
+ @body << s
45
+ end
46
+
47
+ def [](key)
48
+ @headers[key]
49
+ end
50
+
51
+ def []=(key, value)
52
+ @headers[key] = value
53
+ end
54
+
55
+ def html(str)
56
+ @headers[Rack::CONTENT_TYPE] = ContentType::HTML
57
+ write(str)
58
+ end
59
+
60
+ def text(str)
61
+ @headers[Rack::CONTENT_TYPE] = ContentType::TEXT
62
+ write(str)
63
+ end
64
+
65
+ def json(str)
66
+ @headers[Rack::CONTENT_TYPE] = ContentType::JSON
67
+ write(str)
68
+ end
69
+ end
70
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yaframework
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.3"
5
5
  end
data/yaframework.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.bindir = "exe"
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
 
31
- spec.add_development_dependency "bundler", "~> 2.1.4"
31
+ spec.add_development_dependency "bundler", ">= 2.2.10"
32
32
  spec.add_development_dependency "rake", "~> 13.0"
33
33
  spec.add_development_dependency "rubocop", "~> 1.7"
34
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaframework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxbarsukov
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.4
19
+ version: 2.2.10
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.4
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,13 +86,22 @@ files:
86
86
  - bin/console
87
87
  - bin/setup
88
88
  - examples/README.md
89
+ - examples/halts-and-redirects/Gemfile
90
+ - examples/halts-and-redirects/README.md
91
+ - examples/halts-and-redirects/app.rb
92
+ - examples/halts-and-redirects/config.ru
89
93
  - examples/hello-world/Gemfile
90
- - examples/hello-world/Gemfile.lock
91
94
  - examples/hello-world/README.md
92
95
  - examples/hello-world/app.rb
93
96
  - examples/hello-world/config.ru
97
+ - examples/params/Gemfile
98
+ - examples/params/README.md
99
+ - examples/params/app.rb
100
+ - examples/params/config.ru
94
101
  - lib/yaframework.rb
95
102
  - lib/yaframework/base.rb
103
+ - lib/yaframework/request.rb
104
+ - lib/yaframework/response.rb
96
105
  - lib/yaframework/version.rb
97
106
  - test/test_helper.rb
98
107
  - test/yaframework_test.rb
@@ -1,19 +0,0 @@
1
- PATH
2
- remote: /home/max/prog/ruby/yaframework
3
- specs:
4
- yaframework (0.3.0)
5
- rack (~> 2.2)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- rack (2.2.3)
11
-
12
- PLATFORMS
13
- ruby
14
-
15
- DEPENDENCIES
16
- yaframework!
17
-
18
- BUNDLED WITH
19
- 2.1.4