tzispa 0.5.0 → 0.5.1

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: 4706212333c5bb1fb9c2aedf9606d11a6a33f005
4
- data.tar.gz: 007f42e55ec20c1928efba0a79da4fef5ab86986
3
+ metadata.gz: 894d9aa7667fefcfa69c76eff750c199591e0ef9
4
+ data.tar.gz: dda3f0712b977878773d7a036b285d0dfb23c856
5
5
  SHA512:
6
- metadata.gz: b551e4c9ec240ab5b8ea8bd260b69645a7574e7f60ed1ff79db903ab99ba47ab65fa16f36c940e42ab6322b2a825e88d16a43fdb0c7b357c8f5849f151ce3c57
7
- data.tar.gz: 0c0bbae489606f7e3a4a985ccbf6f37877c1caef08eba5f5468570b24ff56a2d28bf47004b9e53e0f6bb3b95fb4fae8d5aa31ca81bdf68abb9f5f54f4d5165bd
6
+ metadata.gz: e364cd1714699a89d1ab2a8fd7e9f2e7e05637b7d3ddf81c699f0e49ce25c69680c6d4cff1765ce915d9b4f6e02fa594bc616149a04da2f7b75b8555ea5da237
7
+ data.tar.gz: a2db16df3d8d02498227ac359d6c542104bbad2dcde768ce4f95dd8a19e9fe6d32e788a566a393e81022bd9bf522bd342f6dc3f440fc1692699b66fec287e08d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@ Tzispa
2
2
 
3
3
  General purpose web framework
4
4
 
5
+ ## v0.5.1
6
+ - Add result_json facility in Api::Handler
7
+ - Rack update requirement to 2.0
8
+ - Fix http_router not poulating env with rack 2.0
9
+ - Code optimizations in middlaware management
10
+
5
11
  ## v0.5.0
6
12
  - Add support for signed and unsigned api calls
7
13
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
+ require 'json'
4
5
 
5
6
  module Tzispa
6
7
  module Api
@@ -34,6 +35,10 @@ module Tzispa
34
35
  @detailed_error = detailed_error
35
36
  end
36
37
 
38
+ def result_json(status=HANDLED_UNDEFINED, data=nil, detailed_error=nil)
39
+ result response_verb: :json, status: status, data: data.to_json, detailed_error: detailed_error
40
+ end
41
+
37
42
  def message
38
43
  if @status.nil?
39
44
  nil
data/lib/tzispa/app.rb CHANGED
@@ -7,7 +7,6 @@ require 'tzispa/domain'
7
7
  require 'tzispa/routes'
8
8
  require 'tzispa/config/appconfig'
9
9
  require 'tzispa/middleware'
10
- require 'tzispa/http/context'
11
10
  require 'tzispa_data'
12
11
  require "tzispa_rig"
13
12
 
@@ -22,12 +21,13 @@ module Tzispa
22
21
  extend Forwardable
23
22
 
24
23
  attr_reader :domain, :config, :middleware, :repository, :engine, :logger
24
+ attr_accessor :routes
25
+
25
26
  def_delegator :@middleware, :use
26
27
  def_delegator :@domain, :name
27
28
 
28
29
 
29
30
  class << self
30
-
31
31
  def inherited(base)
32
32
  super
33
33
  base.class_eval do
@@ -51,31 +51,21 @@ module Tzispa
51
51
 
52
52
  def mount(path, builder)
53
53
  self.new.tap { |app|
54
- app.routes ||= Routes.new(path)
55
- yield(app.routes)
56
- app.middleware.load_app path, builder
54
+ app.routes ||= Routes.new(app, path)
55
+ yield(app.routes) if block_given?
56
+ builder.map path do
57
+ run app.middleware.builder
58
+ end
57
59
  }
58
60
  end
59
-
60
-
61
61
  end
62
62
 
63
- attr_accessor :routes
64
-
65
63
  def initialize(domain_name)
66
64
  @domain = Domain.new(domain_name)
67
65
  @config = Config::AppConfig.new(@domain).load!
68
66
  @middleware = Middleware.new self
69
67
  end
70
68
 
71
- def call(env)
72
- middleware.call(env)
73
- end
74
-
75
- def router
76
- routes&.router
77
- end
78
-
79
69
  def load!
80
70
  Mutex.new.synchronize {
81
71
  load_locales
@@ -86,10 +76,9 @@ module Tzispa
86
76
  @domain.require_dir 'helpers'
87
77
  @domain.require_dir 'api'
88
78
  @domain.require_dir 'middleware'
89
- @middleware.load!
90
79
  @loaded = true
91
80
  }
92
- self
81
+ self
93
82
  end
94
83
 
95
84
  private
@@ -7,18 +7,15 @@ module Tzispa
7
7
  class Context
8
8
  extend Forwardable
9
9
 
10
- attr_reader :env
10
+ attr_reader :app, :env
11
11
  def_delegators :app, :config, :logger, :domain, :repository
12
12
 
13
- def initialize(environment)
13
+ def initialize(app, environment)
14
14
  @env = environment
15
+ @app = app
15
16
  I18n.locale = config.locales.default.to_sym if config.respond_to?(:locales)
16
17
  end
17
18
 
18
- def app
19
- @app ||= env[Tzispa::ENV_TZISPA_APP]
20
- end
21
-
22
19
  end
23
20
 
24
21
  end
@@ -12,15 +12,18 @@ module Tzispa
12
12
 
13
13
  include Tzispa::Helpers::ErrorView
14
14
 
15
- attr_reader :context
15
+ attr_reader :context, :application
16
16
  def_delegators :@context, :request, :response, :config
17
17
 
18
- def initialize(callmethod=nil)
18
+ def initialize(app, callmethod=nil)
19
19
  @callmethod = callmethod
20
+ @application = app
20
21
  end
21
22
 
22
- def call(environment)
23
- @context = environment[Tzispa::ENV_TZISPA_CONTEXT]
23
+ def call(env)
24
+ @context = Tzispa::Http::Context.new(@application, env)
25
+ #env[Tzispa::ENV_TZISPA_CONTEXT] = @context
26
+ #@context = env[Tzispa::ENV_TZISPA_CONTEXT]
24
27
  invoke @callmethod if @callmethod
25
28
  response.finish
26
29
  end
@@ -24,15 +24,15 @@ module Tzispa
24
24
  GLOBAL_MESSAGE_FLASH = :__global_message_flash
25
25
 
26
26
 
27
- def initialize(environment)
28
- super(environment)
27
+ def initialize(app, environment)
28
+ super(app, environment)
29
29
  @request = Tzispa::Http::Request.new(environment)
30
30
  @response = Tzispa::Http::Response.new
31
31
  session[:id] ||= SecureRandom.uuid if app.config.sessions.enabled
32
32
  end
33
33
 
34
34
  def router_params
35
- env['router.params']
35
+ env['router.params'] || Hash.new
36
36
  end
37
37
 
38
38
  def layout
@@ -39,7 +39,7 @@ module Tzispa
39
39
  if calculate_content_length?
40
40
  # if some other code has already set Content-Length, don't muck with it
41
41
  # currently, this would be the static file-handler
42
- headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
42
+ headers["Content-Length"] = body.inject(0) { |l, p| l + p.bytesize }.to_s
43
43
  end
44
44
  headers['X-Powered-By'] = "#{Tzispa::FRAMEWORK_NAME}"
45
45
  [status.to_i, headers, result]
@@ -60,6 +60,6 @@ module Tzispa
60
60
  end
61
61
 
62
62
  end
63
-
63
+
64
64
  end
65
65
  end
@@ -1,37 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tzispa/http/context'
4
+
3
5
  module Tzispa
6
+
4
7
  class Middleware
5
8
 
9
+ attr_reader :application, :stack
10
+
6
11
  def initialize(app)
7
12
  @stack = []
8
13
  @application = app
9
14
  end
10
15
 
11
- def load!
12
- @builder = ::Rack::Builder.new
13
- load_default_stack
14
- @stack.each { |m, args, block| @builder.use load_middleware(m), *args, &block }
15
- @builder.run @application.router
16
- self
17
- end
18
-
19
- def load_app(path, builder)
20
- app = @application
21
- builder.map path do
22
- run app.load!
23
- end
24
- end
25
-
26
- def call(env)
27
- begin
28
- env[Tzispa::ENV_TZISPA_APP] = @application
29
- env[Tzispa::ENV_TZISPA_CONTEXT] = Tzispa::Http::Context.new(env)
30
- @builder.call(env)
31
- rescue => ex
32
- @application.logger.error "#{ex.message} (#{ex.class}):\n #{ex.backtrace&.join("\n\t")}"
33
- env[Tzispa::ENV_TZISPA_CONTEXT].response.status = 500
34
- env[Tzispa::ENV_TZISPA_CONTEXT].response.finish
16
+ def builder
17
+ mw = self
18
+ @builder ||= ::Rack::Builder.new do
19
+ #mw.load_default_stack
20
+ app = mw.application.load!
21
+ mw.stack.each { |m, args, block| use mw.load(m), *args, &block }
22
+ run app.routes.router
35
23
  end
36
24
  end
37
25
 
@@ -39,9 +27,7 @@ module Tzispa
39
27
  @stack.unshift [middleware, args, blk]
40
28
  end
41
29
 
42
- private
43
-
44
- def load_middleware(middleware)
30
+ def load(middleware)
45
31
  case middleware
46
32
  when String
47
33
  Object.const_get(middleware)
@@ -52,8 +38,8 @@ module Tzispa
52
38
 
53
39
  def load_default_stack
54
40
  @default_stack_loaded ||= begin
55
- #use Rack::MethodOverride
56
- true
41
+ app = application.load!
42
+ #use TzispaEnv, app
57
43
  end
58
44
  end
59
45
 
data/lib/tzispa/routes.rb CHANGED
@@ -5,6 +5,7 @@ require 'http_router'
5
5
  require 'tzispa/utils/string'
6
6
  require 'tzispa/controller/http_error'
7
7
 
8
+
8
9
  module Tzispa
9
10
 
10
11
  class Routes
@@ -13,10 +14,11 @@ module Tzispa
13
14
 
14
15
  attr_reader :router, :map_path
15
16
 
16
- def initialize(map_path=nil)
17
+ def initialize(app, root=nil)
17
18
  @router = HttpRouter.new
19
+ @app = app
18
20
  @router.default Tzispa::Controller::HttpError.new('error_404')
19
- @map_path = map_path unless map_path=='/'
21
+ @map_path = root unless root=='/'
20
22
  end
21
23
 
22
24
  def path(path_id, params={})
@@ -35,12 +37,13 @@ module Tzispa
35
37
  controller_module = CONTROLLERS_BASE
36
38
  require "tzispa/controller/#{req_controller}"
37
39
  end
38
- @router.add(path, methods ? {request_method: methods} : nil ).tap { |rule|
39
- rule.to TzString.constantize("#{controller_module}::#{controller}").new(callmethod)
40
+ @router.add(path, methods ? {request_method: methods} : nil).tap { |rule|
41
+ rule.to TzString.constantize("#{controller_module}::#{controller}").new(@app, callmethod)
40
42
  rule.name = route_id
41
43
  }
42
44
  end
43
45
 
46
+
44
47
  def index(path, methods=nil, controller=nil)
45
48
  add :index, path, methods, controller || 'layout:render!'
46
49
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tzispa
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  FRAMEWORK_NAME = 'Tzispa'
6
6
  GEM_NAME = 'tzispa'
7
7
  end
data/tzispa.gemspec CHANGED
@@ -15,8 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.required_ruby_version = '~> 2.3'
17
17
 
18
- s.add_dependency 'rack', '~> 1.5'
19
- s.add_dependency 'puma', '~> 3.1'
18
+ s.add_dependency 'rack', '~> 2.0', '>= 2.0.1'
20
19
  s.add_dependency 'i18n', '~> 0.7.0'
21
20
  s.add_dependency 'http_router', '~> 0.11.2'
22
21
  s.add_dependency 'moneta', '~> 0.8.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -16,28 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
19
+ version: '2.0'
20
+ - - ">="
25
21
  - !ruby/object:Gem::Version
26
- version: '1.5'
27
- - !ruby/object:Gem::Dependency
28
- name: puma
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.1'
22
+ version: 2.0.1
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
27
  - - "~>"
39
28
  - !ruby/object:Gem::Version
40
- version: '3.1'
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.1
41
33
  - !ruby/object:Gem::Dependency
42
34
  name: i18n
43
35
  requirement: !ruby/object:Gem::Requirement