tzispa 0.5.2 → 0.5.3

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: 4d78240cf37311944ed49b7ddda2d5aa8d51001a
4
- data.tar.gz: 104801e65d22dc5d76345003f0111d2a6a1d5a23
3
+ metadata.gz: 5aaff71883d0b89db28bc7727a27444804d79081
4
+ data.tar.gz: bf58b21bba595c299eb6148420b01184f3b54a07
5
5
  SHA512:
6
- metadata.gz: 2856238cca15d665edacf4e0b51a521183dbe3c327c3717b91423bb17fa5c39671b5eae45e3dd00415fdb3ef9f1ff44f9ac4a649dcab6575bcb79c6d09229f29
7
- data.tar.gz: 33c353d4fece24681e7280f0d2ae45e42c8262f4fea8ef45cbd99dfa561eaeb2e89b710a35b1634494defd087b5b430aa708d1a990e6377b1e91c3bb94097f22
6
+ metadata.gz: 4ed1dcd8ef017e2a3ff31655f0ddb110cf37aaf02af048822363a02fe3cbc355bcb3701335348aecbb2d3b23291996343e089140ebae0f4ebaaa92cd72b9be72
7
+ data.tar.gz: 42447d848724c471e471f0c3ce8a7ef3fc6a3c56b78631585df10ccaa2bf5ece5487c1a9df7e32bb98b3217d95f68ab765f337414d4b9b7552dc9867e6fd5895
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@ Tzispa
2
2
 
3
3
  General purpose web framework
4
4
 
5
+ ## v0.5.3
6
+ - Add basic inter-app operability for api and url calls
7
+
5
8
  ## v0.5.2
6
9
  - Api download data[:path] must contain full path to the file
7
10
 
data/lib/tzispa/app.rb CHANGED
@@ -28,18 +28,10 @@ module Tzispa
28
28
 
29
29
 
30
30
  class << self
31
- def inherited(base)
32
- super
33
- base.class_eval do
34
- synchronize do
35
- applications.add(base)
36
- end
37
- end
38
- end
39
31
 
40
32
  def applications
41
33
  synchronize do
42
- @@applications ||= Set.new
34
+ @@applications ||= Hash.new{ |hash, key| raise UnknownApplication.new("#{key}") }
43
35
  end
44
36
  end
45
37
 
@@ -49,8 +41,13 @@ module Tzispa
49
41
  }
50
42
  end
51
43
 
44
+ def [](name)
45
+ applications[name]
46
+ end
47
+
52
48
  def mount(path, builder)
53
49
  self.new.tap { |app|
50
+ add(app)
54
51
  app.routes ||= Routes.new(app, path)
55
52
  yield(app.routes) if block_given?
56
53
  builder.map path do
@@ -58,6 +55,16 @@ module Tzispa
58
55
  end
59
56
  }
60
57
  end
58
+
59
+ private
60
+
61
+ def add(app)
62
+ synchronize do
63
+ raise DuplicateDomain.new("You have try to add an app with a duplicate domain name #{app.name}") if applications.has_key? app.name
64
+ applications[app.name] = app
65
+ end
66
+ end
67
+
61
68
  end
62
69
 
63
70
  def initialize(domain_name)
@@ -81,6 +88,10 @@ module Tzispa
81
88
  self
82
89
  end
83
90
 
91
+ def [](domain)
92
+ self.class[domain]
93
+ end
94
+
84
95
  private
85
96
 
86
97
  def load_locales
@@ -90,5 +101,12 @@ module Tzispa
90
101
  end
91
102
  end
92
103
 
104
+ public
105
+
106
+ class ApplicationError < StandardError; end
107
+ class UnknownApplication < ApplicationError; end
108
+ class DuplicateDomain < ApplicationError; end
109
+
110
+
93
111
  end
94
112
  end
@@ -77,19 +77,35 @@ module Tzispa
77
77
  app.routes.path path_id, params
78
78
  end
79
79
 
80
+ def app_path(app_name, path_id, params={})
81
+ app[app_name].routes.path path_id, params
82
+ end
83
+
80
84
  def canonical_url(path_id, params={})
81
85
  app.config.canonical_url + path(path_id, params)
82
86
  end
83
87
 
84
- def api(handler, verb, predicate, sufix)
85
- canonical_url :api, handler: handler, verb: verb, predicate: predicate, sufix: sufix
88
+ def app_canonical_url(app_name, path_id, params={})
89
+ app[app_name].config.canonical_url + app_path(app_name, path_id, params)
86
90
  end
87
91
 
88
- def sapi(handler, verb, predicate, sufix)
89
- sign = sign_array [handler, verb, predicate], app.config.salt
90
- canonical_url :sapi, sign: sign, handler: handler, verb: verb, predicate: predicate, sufix: sufix
92
+ def api(handler, verb, predicate, sufix, app_name)
93
+ unless app_name
94
+ canonical_url :api, handler: handler, verb: verb, predicate: predicate, sufix: sufix
95
+ else
96
+ app_canonical_url app_name, :api, handler: handler, verb: verb, predicate: predicate, sufix: sufix
97
+ end
91
98
  end
92
99
 
100
+ def sapi(handler, verb, predicate, sufix, app_name = nil)
101
+ unless app_name
102
+ sign = sign_array [handler, verb, predicate], app.config.salt
103
+ canonical_url :sapi, sign: sign, handler: handler, verb: verb, predicate: predicate, sufix: sufix
104
+ else
105
+ sign = sign_array [handler, verb, predicate], app[:app_name].config.salt
106
+ app_canonical_url app_name, :sapi, sign: sign, handler: handler, verb: verb, predicate: predicate, sufix: sufix
107
+ end
108
+ end
93
109
 
94
110
  end
95
111
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tzispa
4
- VERSION = '0.5.2'
4
+ VERSION = '0.5.3'
5
5
  FRAMEWORK_NAME = 'Tzispa'
6
6
  GEM_NAME = 'tzispa'
7
7
  end
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.2
4
+ version: 0.5.3
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-10-03 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack