bezel-app 0.0.6 → 0.0.7

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
  SHA1:
3
- metadata.gz: 8a2e49fcdb83b16cbdcbab274e930dbfce0b7fa1
4
- data.tar.gz: ec59c6d94b9b7fe5a4943e28f528e4ff7aed3223
3
+ metadata.gz: 7eb7d3e03695a324803eb0be6125841bbb5d17a5
4
+ data.tar.gz: 66ab72c4309df61a07d3126f5844ed261f3edbf5
5
5
  SHA512:
6
- metadata.gz: 50729a1b3bd7b70fa80df47052e903e5c0115fc869e969cd6e4b23e75690d9489c413556661d29d9ea9cfc473f0d4d01a7c94ed9803c252866af7f69100b2078
7
- data.tar.gz: 79c17a496961e932f4f8f2d92eba3758628bcb9cd9c98380b0df44a8c1bd8c1c5044d852dff1b9fb82dd65180ed5742975b58425b191289f5dc2d36a7f2801da
6
+ metadata.gz: 57368d376b440714338edfd82730e4f4e52869b308cd9c202ea1f25f8facf132b7236f7bee92d0323898eba7d3ea7ab746b7bce1320aa36bb4dcd32c97f63984
7
+ data.tar.gz: 3b367b6cf877d6e02d6081da992a56b6f7d4b8d757062c5941fc4d19efda5f541547b2589d732313be3420275a8c618ce0ecfb62c22de04d7d9d5ef68a9eafcf
data/bezel-app.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'bezel-app'
8
- spec.version = '0.0.6'
8
+ spec.version = '0.0.7'
9
9
  spec.authors = ['Keith Thompson']
10
10
  spec.email = ['KeithM_Thompson@outlook.com']
11
11
 
@@ -3,76 +3,77 @@ require 'active_support/core_ext'
3
3
  require 'erb'
4
4
  require_relative './session'
5
5
  require_relative './flash'
6
+ module Bezel
7
+ class ControllerBase
8
+ attr_reader :req, :res, :params, :flash
6
9
 
7
- class ControllerBase
8
- attr_reader :req, :res, :params, :flash
9
-
10
- def self.protect_from_forgery
11
- @@csrf_auth = true
12
- end
10
+ def self.protect_from_forgery
11
+ @@csrf_auth = true
12
+ end
13
13
 
14
- def initialize(req, res, route_params = {})
15
- @req = req
16
- @res = res
17
- @params = req.params.merge(route_params)
18
- @flash = Flash.new(req)
19
- @params['authenticity_token'] ||= SecureRandom.base64
20
- end
14
+ def initialize(req, res, route_params = {})
15
+ @req = req
16
+ @res = res
17
+ @params = req.params.merge(route_params)
18
+ @flash = Flash.new(req)
19
+ @params['authenticity_token'] ||= SecureRandom.base64
20
+ end
21
21
 
22
- def form_authenticity_token
23
- @res.set_cookie('authenticity_token',@params['authenticity_token'])
24
- @params['authenticity_token']
25
- end
22
+ def form_authenticity_token
23
+ @res.set_cookie('authenticity_token',@params['authenticity_token'])
24
+ @params['authenticity_token']
25
+ end
26
26
 
27
- def check_authenticity_token(token = "")
28
- @params['authenticity_token'] == token
29
- end
27
+ def check_authenticity_token(token = "")
28
+ @params['authenticity_token'] == token
29
+ end
30
30
 
31
31
 
32
- def already_built_response?
33
- !!@already_built_response
34
- end
32
+ def already_built_response?
33
+ !!@already_built_response
34
+ end
35
35
 
36
36
 
37
- def redirect_to(url)
38
- raise 'You cannot call render more than once' if already_built_response?
39
- @res.status = 302
40
- @res['Location'] = url
41
- @already_built_response = true
37
+ def redirect_to(url)
38
+ raise 'You cannot call render more than once' if already_built_response?
39
+ @res.status = 302
40
+ @res['Location'] = url
41
+ @already_built_response = true
42
42
 
43
- session.store_session(@res)
44
- end
43
+ session.store_session(@res)
44
+ end
45
45
 
46
- def render_content(content, content_type)
47
- raise 'You cannot call render more than once' if already_built_response?
48
- @res['Content-Type'] = content_type
49
- @res.write(content)
50
- @already_built_response = true
46
+ def render_content(content, content_type)
47
+ raise 'You cannot call render more than once' if already_built_response?
48
+ @res['Content-Type'] = content_type
49
+ @res.write(content)
50
+ @already_built_response = true
51
51
 
52
- session.store_session(@res)
53
- end
52
+ session.store_session(@res)
53
+ end
54
54
 
55
- def render(template_name)
56
- file_name = "views/"
57
- file_name += "#{self.class.to_s.underscore}/"
58
- file_name += "#{template_name}.html.erb"
59
- content = ERB.new(File.read(file_name)).result(binding)
55
+ def render(template_name)
56
+ file_name = "views/"
57
+ file_name += "#{self.class.to_s.underscore}/"
58
+ file_name += "#{template_name}.html.erb"
59
+ content = ERB.new(File.read(file_name)).result(binding)
60
60
 
61
- render_content(content, "text/html")
62
- end
61
+ render_content(content, "text/html")
62
+ end
63
63
 
64
- def session
65
- @session ||= Session.new(@req)
66
- end
64
+ def session
65
+ @session ||= Session.new(@req)
66
+ end
67
67
 
68
- def invoke_action(name)
69
- if @@csrf_auth && @req.request_method != "GET"
70
- unless check_authenticity_token(@req.cookies['authenticity_token'])
71
- raise "Invalid authenticity token"
68
+ def invoke_action(name)
69
+ if @@csrf_auth && @req.request_method != "GET"
70
+ unless check_authenticity_token(@req.cookies['authenticity_token'])
71
+ raise "Invalid authenticity token"
72
+ end
72
73
  end
73
- end
74
74
 
75
- send(name)
76
- render(name) unless already_built_response?
75
+ send(name)
76
+ render(name) unless already_built_response?
77
+ end
77
78
  end
78
79
  end
data/lib/flash.rb CHANGED
@@ -1,29 +1,30 @@
1
1
  require 'json'
2
-
3
- class Flash
4
- def initialize(req)
5
- if req.cookies['_bezel_flash']
6
- @flash = JSON.parse(req.cookies['_bezel_flash'])
7
- else
8
- @flash = {}
2
+ module Bezel
3
+ class Flash
4
+ def initialize(req)
5
+ if req.cookies['_bezel_flash']
6
+ @flash = JSON.parse(req.cookies['_bezel_flash'])
7
+ else
8
+ @flash = {}
9
+ end
10
+ @flash_now = {}
9
11
  end
10
- @flash_now = {}
11
- end
12
12
 
13
- def []=(key,val)
14
- @flash[key] = val
15
- end
13
+ def []=(key,val)
14
+ @flash[key] = val
15
+ end
16
16
 
17
- def [](key)
18
- return @flash_now[key] if @flash_now[key]
19
- @flash[key.to_s]
20
- end
17
+ def [](key)
18
+ return @flash_now[key] if @flash_now[key]
19
+ @flash[key.to_s]
20
+ end
21
21
 
22
- def store_flash(res)
23
- res.set_cookie('_bezel_flash', value: @flash.to_json, path: '/')
24
- end
22
+ def store_flash(res)
23
+ res.set_cookie('_bezel_flash', value: @flash.to_json, path: '/')
24
+ end
25
25
 
26
- def now
27
- @flash_now
26
+ def now
27
+ @flash_now
28
+ end
28
29
  end
29
30
  end
data/lib/router.rb CHANGED
@@ -23,38 +23,40 @@ class Route
23
23
  end
24
24
  end
25
25
 
26
- class Router
27
- attr_reader :routes
26
+ module Bezel
27
+ class Router
28
+ attr_reader :routes
28
29
 
29
- def initialize
30
- @routes = []
31
- end
30
+ def initialize
31
+ @routes = []
32
+ end
32
33
 
33
- def add_route(pattern, method, controller_class, action_name)
34
- @routes << Route.new(pattern, method, controller_class, action_name)
35
- end
34
+ def add_route(pattern, method, controller_class, action_name)
35
+ @routes << Route.new(pattern, method, controller_class, action_name)
36
+ end
36
37
 
37
- def draw(&proc)
38
- self.instance_eval(&proc)
39
- end
38
+ def draw(&proc)
39
+ self.instance_eval(&proc)
40
+ end
40
41
 
41
- [:get, :post, :put, :delete].each do |http_method|
42
+ [:get, :post, :put, :delete].each do |http_method|
42
43
 
43
- define_method(http_method) do |pattern, controller_class, method|
44
- add_route(pattern, http_method, controller_class, method)
44
+ define_method(http_method) do |pattern, controller_class, method|
45
+ add_route(pattern, http_method, controller_class, method)
46
+ end
45
47
  end
46
- end
47
48
 
48
- def match(req)
49
- @routes.each do |route|
50
- return route if route.matches?(req)
49
+ def match(req)
50
+ @routes.each do |route|
51
+ return route if route.matches?(req)
52
+ end
53
+ nil
51
54
  end
52
- nil
53
- end
54
55
 
55
- def run(req, res)
56
- route = match(req)
57
- return res.status = 404 unless route
58
- route.run(req,res)
56
+ def run(req, res)
57
+ route = match(req)
58
+ return res.status = 404 unless route
59
+ route.run(req,res)
60
+ end
59
61
  end
60
62
  end
@@ -0,0 +1,20 @@
1
+ require 'rack'
2
+ require './config/routes'
3
+
4
+ module Bezel
5
+ class ServerConnection
6
+ def self.start
7
+ app = proc do |env|
8
+ req = Rack::Request.new(env)
9
+ res = Rack::Response.new
10
+ ROUTER.run(req, res)
11
+ res.finish
12
+ end
13
+
14
+ Rack::Server.start(
15
+ app: app,
16
+ Port: 3000
17
+ )
18
+ end
19
+ end
20
+ end
data/lib/session.rb CHANGED
@@ -1,24 +1,26 @@
1
1
  require 'json'
2
2
 
3
- class Session
4
- def initialize(req)
5
- if req.cookies['_']
6
- @cookie = JSON.parse(req.cookies['_bezel'])
7
- else
8
- @cookie = {}
3
+ module Bezel
4
+ class Session
5
+ def initialize(req)
6
+ if req.cookies['_']
7
+ @cookie = JSON.parse(req.cookies['_bezel'])
8
+ else
9
+ @cookie = {}
10
+ end
9
11
  end
10
- end
11
12
 
12
- def [](key)
13
- @cookie[key]
14
- end
13
+ def [](key)
14
+ @cookie[key]
15
+ end
15
16
 
16
- def []=(key, val)
17
- @cookie[key] = val
18
- end
17
+ def []=(key, val)
18
+ @cookie[key] = val
19
+ end
19
20
 
20
- def store_session(res)
21
- json_cookie = @cookie.to_json
22
- res.set_cookie('_bezel', value: json_cookie, path: '/' )
21
+ def store_session(res)
22
+ json_cookie = @cookie.to_json
23
+ res.set_cookie('_bezel', value: json_cookie, path: '/' )
24
+ end
23
25
  end
24
26
  end
@@ -1,24 +1,26 @@
1
1
  require 'erb'
2
- class ShowExceptions
3
- attr_reader :app
2
+ module Bezel
3
+ class ShowExceptions
4
+ attr_reader :app
4
5
 
5
- def initialize(app)
6
- @app = app
7
- end
6
+ def initialize(app)
7
+ @app = app
8
+ end
8
9
 
9
- def call(env)
10
- begin
11
- app.call(env)
12
- rescue Exception => e
13
- render_exception(e)
10
+ def call(env)
11
+ begin
12
+ app.call(env)
13
+ rescue Exception => e
14
+ render_exception(e)
15
+ end
14
16
  end
15
- end
16
17
 
17
- private
18
+ private
18
19
 
19
- def render_exception(e)
20
- response = Rack::Response.new([], 500, 'Content_Type'=> 'text/html')
21
- response.write(e.message)
22
- response.finish
20
+ def render_exception(e)
21
+ response = Rack::Response.new([], 500, 'Content_Type'=> 'text/html')
22
+ response.write(e.message)
23
+ response.finish
24
+ end
23
25
  end
24
26
  end
data/lib/static_assets.rb CHANGED
@@ -1,36 +1,38 @@
1
- class StaticAssets
2
- def initialize(app)
3
- @app = app
4
- end
5
-
6
- def call(env)
7
- file_path = "." + env['PATH_INFO']
8
- res = Rack::Response.new
9
- extension = /\.(\w*$)/.match(file_path)[1]
10
- begin
11
- res['Content-Type'] = set_content_type(extension)
12
- content = File.read(file_path)
13
- res.write(content)
14
- rescue
15
- res.status = 404
1
+ module Bezel
2
+ class StaticAssets
3
+ def initialize(app)
4
+ @app = app
16
5
  end
17
6
 
18
- res.finish
7
+ def call(env)
8
+ file_path = "." + env['PATH_INFO']
9
+ res = Rack::Response.new
10
+ extension = /\.(\w*$)/.match(file_path)[1]
11
+ begin
12
+ res['Content-Type'] = set_content_type(extension)
13
+ content = File.read(file_path)
14
+ res.write(content)
15
+ rescue
16
+ res.status = 404
17
+ end
18
+
19
+ res.finish
20
+ end
19
21
  end
20
- end
21
22
 
22
- private
23
- def set_content_type(extension)
24
- case extension
25
- when "txt"
26
- "text/plain"
27
- when "jpg"
28
- "image/jpeg"
29
- when "zip"
30
- "application/zip"
31
- when "png"
32
- "image/png"
33
- else
34
- raise 'extension not supported'
23
+ private
24
+ def set_content_type(extension)
25
+ case extension
26
+ when "txt"
27
+ "text/plain"
28
+ when "jpg"
29
+ "image/jpeg"
30
+ when "zip"
31
+ "application/zip"
32
+ when "png"
33
+ "image/png"
34
+ else
35
+ raise 'extension not supported'
36
+ end
35
37
  end
36
38
  end
data/template/db/seeds.rb CHANGED
@@ -1,7 +1,5 @@
1
- module Bezel
2
- class Seed
3
- def self.populate
1
+ class Seed
2
+ def self.populate
4
3
 
5
- end
6
4
  end
7
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bezel-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Thompson
@@ -172,6 +172,7 @@ files:
172
172
  - lib/db_connection.rb
173
173
  - lib/flash.rb
174
174
  - lib/router.rb
175
+ - lib/server_connection.rb
175
176
  - lib/session.rb
176
177
  - lib/show_exceptions.rb
177
178
  - lib/static_assets.rb