yaframework 0.4.0 → 0.4.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33b8bd38ee7fbf3d16bdef94f830384f979ad465ff674d085378caa6a46b6971
4
- data.tar.gz: 1da887439ec28a18fc4ee8a4812d9bf3d9f70be894636f181a6af98a965d0dd2
3
+ metadata.gz: bb7911725bae2b9c6c1a8e575f35c32002950733011474ef711ecfbb486349f7
4
+ data.tar.gz: 3aebe5de332841aa193423f2796415e9b5f7842a6f28f4d71f56d9d6f1fa6ff9
5
5
  SHA512:
6
- metadata.gz: 6ff977d266bccebbc67aa17c7ff2116be8f51c057be070807afa4d2c6e6a090c1053f146434e3a9ed78defa9ee840dfaa08b760f4807b0976b7bef9a09b181db
7
- data.tar.gz: a62b06535d579d4b552aec2c1a0856514d5b27628aec77e267cfa4d98bc9b4b6185d00d6c919cae5fdf198a295870a7d0a8233eb4b3df08e39c967663791887f
6
+ metadata.gz: 1155c9b2c1989b62ffa01d56134fa40e1c61babaed7a570b489db0c2b1e385b5c17158818fa1a61f23f7a94585a483ba897fb91ede42f1ce1948204c5566abf2
7
+ data.tar.gz: c14ad19ffb1e5504bac06a64534cabd590b2531798444d44773557e55111208f115b3d7a11b99df3fbf7c1583c5f7021274fdbe9063c5d3b54d454a864941c1a
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,32 @@
1
+ ## [0.4.5] - 2021-07-25
2
+
3
+ - Error handling added
4
+
5
+ ## [0.4.4] - 2021-07-25
6
+
7
+ - Interaction with cookies has been updated
8
+
9
+ ## [0.4.3] - 2021-07-25
10
+
11
+ - Updated the method for changing the Content-Type
12
+ - Interaction with headers has been improved
13
+
14
+ ## [0.4.2] - 2021-07-24
15
+
16
+ - DB module removed
17
+
18
+ ## [0.4.1] - 2021-07-24
19
+
20
+ - A little fix. Fixed an error with the wrong order of declaring variables (lol)
21
+
22
+ ## [0.4.0] - 2021-07-24
23
+
24
+ - Global routing update and large-scale code base changes
25
+
26
+ ## [0.3.0] - 2021-07-24
27
+
28
+ - Added tools for interacting with the database
29
+
1
30
  ## [0.2.2] - 2021-07-23
2
31
 
3
32
  - Params fixed
data/Gemfile CHANGED
@@ -3,7 +3,3 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
-
7
- gem "minitest", "~> 5.0"
8
- gem "pg", "~> 1.2", ">= 1.2.3"
9
- gem "rack", "~> 2.2", ">= 2.2.3"
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaframework (0.2.2)
5
- rack (~> 2.2)
4
+ yaframework (0.4.5)
5
+ rack (~> 2.2, >= 2.2.3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -12,7 +12,6 @@ GEM
12
12
  parallel (1.20.1)
13
13
  parser (3.0.2.0)
14
14
  ast (~> 2.4.1)
15
- pg (1.2.3)
16
15
  rack (2.2.3)
17
16
  rainbow (3.0.0)
18
17
  rake (13.0.6)
@@ -36,13 +35,11 @@ PLATFORMS
36
35
  ruby
37
36
 
38
37
  DEPENDENCIES
39
- bundler (~> 2.1.4)
38
+ bundler (>= 2.2.10)
40
39
  minitest (~> 5.0)
41
- pg (~> 1.2, >= 1.2.3)
42
- rack (~> 2.2, >= 2.2.3)
43
40
  rake (~> 13.0)
44
41
  rubocop (~> 1.7)
45
42
  yaframework!
46
43
 
47
44
  BUNDLED WITH
48
- 2.1.4
45
+ 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
@@ -1,14 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../lib/yaframework"
3
+ require "yaframework"
4
4
  app = Yaframework::Application
5
5
 
6
6
  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
@@ -3,7 +3,6 @@
3
3
  require_relative "yaframework/base"
4
4
  require_relative "yaframework/request"
5
5
  require_relative "yaframework/response"
6
- require_relative "yaframework/database"
7
6
 
8
7
  module Yaframework
9
8
  end
@@ -8,6 +8,7 @@ module Yaframework
8
8
 
9
9
  def initialize
10
10
  @routes = Hash.new([])
11
+ @inbox = {}
11
12
  end
12
13
 
13
14
  %w[GET POST PATCH PUT DELETE HEAD OPTIONS].each do |verb|
@@ -17,9 +18,9 @@ module Yaframework
17
18
  end
18
19
 
19
20
  def call(env)
21
+ @env = env
20
22
  @request = Yaframework::Request.new @env
21
23
  @response = Yaframework::Response.new
22
- @env = env
23
24
  catch(:halt) { route_eval }
24
25
  end
25
26
 
@@ -27,6 +28,10 @@ module Yaframework
27
28
  throw :halt, response
28
29
  end
29
30
 
31
+ def handle(status, &block)
32
+ @inbox[status] = block
33
+ end
34
+
30
35
  def listen(port = 5000)
31
36
  Rack::Handler::WEBrick.run self, Port: port
32
37
  end
@@ -50,6 +55,11 @@ module Yaframework
50
55
  end
51
56
 
52
57
  def route_eval
58
+ if @inbox[response.status]
59
+ response.write instance_eval(&@inbox[response.status])
60
+ return response.finish
61
+ end
62
+
53
63
  route = find_route
54
64
  if route
55
65
  response.write instance_eval(&route[:handler])
@@ -2,6 +2,14 @@
2
2
 
3
3
  module Yaframework
4
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
+
5
13
  attr_accessor :status
6
14
  attr_reader :headers, :body
7
15
 
@@ -21,19 +29,50 @@ module Yaframework
21
29
  end
22
30
 
23
31
  def finish
24
- headers["Content-Length"] = @length.to_s unless (100..199).include?(status) || status == 204
32
+ @headers[Rack::CONTENT_LENGTH] = @length.to_s unless (100..199).include?(status) || status == 204
25
33
  [status, headers, body]
26
34
  end
27
35
 
28
36
  def redirect(target, status = 302)
29
- self.status = status
30
- headers["Location"] = target
37
+ @status = status
38
+ @headers[LOCATION] = target
31
39
  end
32
40
 
33
41
  def write(string)
34
42
  s = string.to_s
35
43
  @length += s.bytesize
36
- body << s
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
+
70
+ def set_cookie(key, value)
71
+ Rack::Utils.set_cookie_header!(@headers, key, value)
72
+ end
73
+
74
+ def delete_cookie(key, value = {})
75
+ Rack::Utils.delete_cookie_header!(@headers, key, value)
37
76
  end
38
77
  end
39
78
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yaframework
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.5"
5
5
  end
data/yaframework.gemspec CHANGED
@@ -28,9 +28,10 @@ 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
+ spec.add_development_dependency "minitest", "~> 5.0"
32
33
  spec.add_development_dependency "rake", "~> 13.0"
33
34
  spec.add_development_dependency "rubocop", "~> 1.7"
34
35
 
35
- spec.add_runtime_dependency "rack", "~> 2.2"
36
+ spec.add_runtime_dependency "rack", "~> 2.2", ">= 2.2.3"
36
37
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaframework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - maxbarsukov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-24 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.10
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: 2.1.4
33
+ version: '5.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: 2.1.4
40
+ version: '5.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +73,9 @@ dependencies:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
75
  version: '2.2'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.2.3
62
79
  type: :runtime
63
80
  prerelease: false
64
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -66,6 +83,9 @@ dependencies:
66
83
  - - "~>"
67
84
  - !ruby/object:Gem::Version
68
85
  version: '2.2'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.2.3
69
89
  description: What could be better than one more Sinatra?
70
90
  email:
71
91
  - maximbarsukov@bk.ru
@@ -86,14 +106,20 @@ files:
86
106
  - bin/console
87
107
  - bin/setup
88
108
  - examples/README.md
109
+ - examples/halts-and-redirects/Gemfile
110
+ - examples/halts-and-redirects/README.md
111
+ - examples/halts-and-redirects/app.rb
112
+ - examples/halts-and-redirects/config.ru
89
113
  - examples/hello-world/Gemfile
90
- - examples/hello-world/Gemfile.lock
91
114
  - examples/hello-world/README.md
92
115
  - examples/hello-world/app.rb
93
116
  - examples/hello-world/config.ru
117
+ - examples/params/Gemfile
118
+ - examples/params/README.md
119
+ - examples/params/app.rb
120
+ - examples/params/config.ru
94
121
  - lib/yaframework.rb
95
122
  - lib/yaframework/base.rb
96
- - lib/yaframework/database.rb
97
123
  - lib/yaframework/request.rb
98
124
  - lib/yaframework/response.rb
99
125
  - lib/yaframework/version.rb
@@ -1,15 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- rack (2.2.3)
5
- yaframework (0.2.2)
6
- rack (~> 2.2)
7
-
8
- PLATFORMS
9
- ruby
10
-
11
- DEPENDENCIES
12
- yaframework
13
-
14
- BUNDLED WITH
15
- 2.1.4
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pg"
4
-
5
- class Database
6
- def self.connect(db_name)
7
- pg_conn = PG.connect(dbname: db_name)
8
- new(pg_conn)
9
- end
10
-
11
- def initialize(pg_conn)
12
- @pg_conn = pg_conn
13
- end
14
-
15
- def exec(sql)
16
- @pg_conn.exec(sql).to_a
17
- end
18
- end