tzispa_rig 0.5.8 → 0.5.9

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
  SHA1:
3
- metadata.gz: 8f61d5a234b8c0d9a4fe0529eaf9a6f1ebfc42ae
4
- data.tar.gz: 5510913797929897ee62fd403be11c355ff33803
3
+ metadata.gz: 371ebdba52c779a4986180fa1e1ea1b2223e58d1
4
+ data.tar.gz: 30ee8041f9280987c82ce7c4d8ee8964eba42ae5
5
5
  SHA512:
6
- metadata.gz: 376431a516f426e4499847f872a4edd5b46397a1d679a550cfb4aded98517706fd76cfe6daaa6ad99dd18e52a50b67890b87aea70564abf430920d6452504e81
7
- data.tar.gz: a511a3a564960b49ef9d8a51a3e792f7a96eae4b51188b6e3dc01c1eb27478b3d7907024eadbf31ec41ae1412232004e04f7643310f5d84daae43a08b591d24e
6
+ metadata.gz: d9713e8b8baddd622ee606eff3297543ae3ed39b9214c46b666f48954a653bb5d823f584d32d6457861017f3716c75678e60ed5b23a40a81d9934ac675874682
7
+ data.tar.gz: 2a1501316acd49e085b0729f61fb05c33054ac78307335a724695a4a9bfdf4b3ee5d6936bb60234a33f952ed39c277d45310beb285787b7fa15cca459bf25f47
data/CHANGELOG.md CHANGED
@@ -2,8 +2,11 @@ Tzispa Rig
2
2
 
3
3
  Rig templates implementation
4
4
 
5
+ ## v0.5.9
6
+ - classes constants autoloading
7
+
5
8
  ## v0.5.8
6
- - engine class renmaed to factory
9
+ - engine class renamed to factory
7
10
 
8
11
  ## v0.5.6
9
12
  - bugs fix
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tzispa/rig/handler'
4
+ require 'tzispa_annotations'
5
+
6
+ module Tzispa
7
+ module Rig
8
+ class AnnotatedHandler < Tzispa::Rig::Handler
9
+ extend Tzispa::Annotations
10
+ include Tzispa::Annotations::Builtin
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'tzispa/helpers/provider'
5
+ require 'tzispa/helpers/sign_requirer'
6
+ require 'tzispa/helpers/hooks/before'
7
+ require 'tzispa/helpers/hooks/after'
8
+ require_relative 'handler_error'
9
+
10
+ module Tzispa
11
+ module Rig
12
+
13
+ class ApiException < StandardError; end
14
+ class UnknownHandlerVerb < ApiException
15
+ def initialize(s, name)
16
+ super("Unknown verb: '#{s}' called in api handler '#{name}'")
17
+ end
18
+ end
19
+ class InvalidSign < ApiException; end
20
+
21
+ class Handler
22
+ extend Forwardable
23
+
24
+ include Tzispa::Rig::HandlerError
25
+ include Tzispa::Helpers::Provider
26
+ include Tzispa::Helpers::SignRequirer
27
+ include Tzispa::Helpers::Hooks::Before
28
+ include Tzispa::Helpers::Hooks::After
29
+
30
+ using Tzispa::Utils::TzString
31
+
32
+ attr_reader :context, :type, :data, :error, :rescue_hook, :status
33
+ def_delegators :@context, :request, :response, :app, :repository,
34
+ :config, :logger, :error_log, :info_log
35
+
36
+ def initialize(context)
37
+ @context = context
38
+ @error = nil
39
+ @status = nil
40
+ @rescue_hook = nil
41
+ end
42
+
43
+ def result(type:, data: nil)
44
+ @type = type
45
+ @data = data
46
+ end
47
+
48
+ def result_json(data)
49
+ result type: :json, data: data
50
+ end
51
+
52
+ def result_download(data)
53
+ result type: :download, data: data
54
+ end
55
+
56
+ def result_redirect(data = nil)
57
+ result type: :redirect, data: data
58
+ end
59
+
60
+ def error_status(error_code, http_status = nil)
61
+ @error = error_code
62
+ @status = http_status
63
+ result_json error_message: error_message
64
+ end
65
+
66
+ def run!(verb, predicate = nil)
67
+ raise UnknownHandlerVerb.new(verb, self.class.name) unless provides? verb
68
+ raise InvalidSign if sign_required? && !sign_valid?
69
+ do_before
70
+ send verb, *(predicate&.split(','))
71
+ do_after
72
+ end
73
+
74
+ def redirect_url(url)
75
+ if url && !url.strip.empty?
76
+ url.start_with?('#') ? "#{request.referer}#{url}" : url
77
+ else
78
+ request.referer
79
+ end
80
+ end
81
+
82
+ protected
83
+
84
+ def static_path_sign?
85
+ context.path_sign? context.router_params[:sign],
86
+ context.router_params[:handler],
87
+ context.router_params[:verb],
88
+ context.router_params[:predicate]
89
+ end
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'i18n'
4
+ require 'tzispa/utils/string'
5
+
6
+ module Tzispa
7
+ module Rig
8
+ module HandlerError
9
+
10
+ using Tzispa::Utils::TzString
11
+
12
+ HANDLER_OK = :ok
13
+
14
+ def error?
15
+ @error && @error != HANDLER_OK
16
+ end
17
+
18
+ def error_message
19
+ I18n.t(error_id, default: error.to_s) if error
20
+ end
21
+
22
+ def error_id
23
+ "#{self.class.name.dottize}.#{error}" if error
24
+ end
25
+
26
+ def http_bad_request(code = nil)
27
+ error_status code || :bad_request, 400
28
+ end
29
+
30
+ def http_unauthorized(code = nil)
31
+ error_status code || :unauthorized, 401
32
+ end
33
+
34
+ def http_forbidden(code = nil)
35
+ error_status code || :forbidden, 403
36
+ end
37
+
38
+ def http_not_found(code = nil)
39
+ error_status code || :not_found, 404
40
+ end
41
+
42
+ def http_not_aceptable(code = nil)
43
+ error_status code || :not_acceptable, 406
44
+ end
45
+
46
+ def http_conflict(code = nil)
47
+ error_status code || :conflict, 409
48
+ end
49
+
50
+ def http_gone(code = nil)
51
+ error_status code || :gone, 410
52
+ end
53
+
54
+ def http_token_required(code = nil)
55
+ error_status code || :token_required, 499
56
+ end
57
+
58
+ def http_server_error(code = nil)
59
+ error_status code || :internal_server_error, 500
60
+ end
61
+
62
+ def http_not_implemented(code = nil)
63
+ error_status code || :not_implemented, 501
64
+ end
65
+
66
+ def http_bad_gateway(code = nil)
67
+ error_status code || :bad_gateway, 502
68
+ end
69
+
70
+ def http_service_unavailable(code = nil)
71
+ error_status code || :service_unavailable, 503
72
+ end
73
+
74
+ end
75
+ end
76
+ end
File without changes
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'forwardable'
4
4
  require 'tzispa/rig/parameters'
5
- require 'tzispa/rig/parsernext'
5
+ require 'tzispa/rig/parser_next'
6
6
  require 'tzispa/rig/template_binder'
7
7
  require 'tzispa/rig/helpers/template_maker'
8
8
 
@@ -75,7 +75,7 @@ module Tzispa
75
75
  def load!
76
76
  raise Tzispa::Rig::NotFound.new(filename) unless exist?
77
77
  ::File.open(filename, "r:#{encoding}") do |f|
78
- @content = String.new
78
+ @content = +''
79
79
  @modified = f.mtime
80
80
  f.each { |line| @content << line }
81
81
  @loaded = true
@@ -139,7 +139,7 @@ module Tzispa
139
139
  end
140
140
 
141
141
  def modified?
142
- super || (parser && parser.childrens.index(&:modified?))
142
+ super || parser&.childrens&.index(&:modified?)
143
143
  end
144
144
 
145
145
  def valid?
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Rig
5
5
 
6
- VERSION = '0.5.8'
6
+ VERSION = '0.5.9'
7
7
  GEM_NAME = 'tzispa_rig'
8
8
 
9
9
  end
data/lib/tzispa/rig.rb CHANGED
@@ -3,13 +3,14 @@
3
3
  module Tzispa
4
4
  module Rig
5
5
 
6
- require 'tzispa/rig/version'
7
- require 'tzispa/rig/parameters'
8
- require 'tzispa/rig/token'
9
- require 'tzispa/rig/parsernext'
10
- require 'tzispa/rig/template'
11
- require 'tzispa/rig/binder'
12
- require 'tzispa/rig/factory'
6
+ autoload :Parameters, 'tzispa/rig/parameters'
7
+ autoload :Token, 'tzispa/rig/token'
8
+ autoload :Parsernext, 'tzispa/rig/parser_next'
9
+ autoload :Template, 'tzispa/rig/template'
10
+ autoload :Binder, 'tzispa/rig/binder'
11
+ autoload :Factory, 'tzispa/rig/factory'
12
+ autoload :Handler, 'tzispa/rig/handler'
13
+ autoload :AnnotatedHandler, 'tzispa/rig/annotated_handler'
13
14
 
14
15
  end
15
16
  end
data/lib/tzispa_rig.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Tzispa
2
2
  module Rig
3
3
 
4
+ require 'tzispa/rig/version'
4
5
  require 'tzispa/rig'
5
6
 
6
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa_rig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.5.9
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: 2017-08-22 00:00:00.000000000 Z
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzispa_utils
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tzispa_annotations
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: moneta
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -63,11 +77,14 @@ files:
63
77
  - README.md
64
78
  - Rakefile
65
79
  - lib/tzispa/rig.rb
80
+ - lib/tzispa/rig/annotated_handler.rb
66
81
  - lib/tzispa/rig/binder.rb
67
82
  - lib/tzispa/rig/factory.rb
83
+ - lib/tzispa/rig/handler.rb
84
+ - lib/tzispa/rig/handler_error.rb
68
85
  - lib/tzispa/rig/helpers/template_maker.rb
69
86
  - lib/tzispa/rig/parameters.rb
70
- - lib/tzispa/rig/parsernext.rb
87
+ - lib/tzispa/rig/parser_next.rb
71
88
  - lib/tzispa/rig/syntax.rb
72
89
  - lib/tzispa/rig/template.rb
73
90
  - lib/tzispa/rig/template_binder.rb
@@ -97,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
114
  requirements:
98
115
  - - "~>"
99
116
  - !ruby/object:Gem::Version
100
- version: '2.3'
117
+ version: '2.4'
101
118
  required_rubygems_version: !ruby/object:Gem::Requirement
102
119
  requirements:
103
120
  - - ">="
@@ -105,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
122
  version: '0'
106
123
  requirements: []
107
124
  rubyforge_project:
108
- rubygems_version: 2.6.11
125
+ rubygems_version: 2.6.13
109
126
  signing_key:
110
127
  specification_version: 4
111
128
  summary: General purpose template engine