metatron 0.2.8 → 0.3.1

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: f308e72dd77b3d49526080eec9ad9de69365d4892b0fa4b113530d42ecf3305b
4
- data.tar.gz: 5501df686f100f401984f103c42ebbe41f93eb2d8fb992f19cd2231a94175fa2
3
+ metadata.gz: 7be8fd32bdf4ce62a28058510331ae0add378955f77e26b15fd77c9a3e5e1e40
4
+ data.tar.gz: 32193fca77a3b4d6015090c7aa4ae47921c18a808872d0b6fa1552303c50916b
5
5
  SHA512:
6
- metadata.gz: 75604561c430cbdabe5093c7cc593c8e8c145b0bae8a0427d60e26ac368a27f3794beb3e956a0458ad95b90c1ac76c886896381fcd845120645b97d2dec48c86
7
- data.tar.gz: ae099c61283a7b99b22e5f76a48f4ce24847f2ef8d50e5b477a00bc68a5f57654a5349ba63127451d7c9c43ba1db7cef4be31e110227db00e19d8a2143c570b0
6
+ metadata.gz: dedc229ae2283d2fec91477289aabd079e8c2bdab5d682dc40cf0376191e0e1dd158374e2b984afa7b0145ac18bb8830d4f0c1d9edea28b7001dfc64f3dce63a
7
+ data.tar.gz: 49092eadfc7a43b1d3bb8e5ac65c1bc56c2780b2dc08841da8842e66dcd041497e97efab209def7b5ffbee1dac01dd2a426514f11d9c428755794796c20db3f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- metatron (0.2.8)
4
+ metatron (0.3.1)
5
5
  json (~> 2.6)
6
6
  puma (~> 6.3)
7
7
  sinatra (~> 2.2)
@@ -150,4 +150,4 @@ DEPENDENCIES
150
150
  yard (~> 0.9)
151
151
 
152
152
  BUNDLED WITH
153
- 2.4.17
153
+ 2.4.19
@@ -9,9 +9,21 @@ module Metatron
9
9
  end
10
10
 
11
11
  post "/" do
12
+ # TODO: move this to Sinatra's `etag` helper when Metacontroller is RFC compliant
13
+ if (provided_etag = calculate_etag) &&
14
+ (match_header = request.env["HTTP_IF_NONE_MATCH"]) &&
15
+ match_header.split(/,\s?/).include?("\"#{provided_etag}\"")
16
+ halt 304
17
+ end
18
+
19
+ # If the etag is available, use it, otherwise proceed with the sync
20
+ headers "ETag" => "\"#{provided_etag}\"" if provided_etag
12
21
  data = sync
13
22
  data[:children] = data[:children]&.map { |c| c.respond_to?(:render) ? c.render : c }
14
23
  halt(data.to_json)
15
24
  end
25
+
26
+ def calculate_etag = nil
27
+ def sync = raise NotImplementedError
16
28
  end
17
29
  end
@@ -34,20 +34,25 @@ module Metatron
34
34
  @initializers ||= []
35
35
  end
36
36
 
37
- private
37
+ def self.nearest_metatron_ancestor
38
+ return self if metatron_template_class?
38
39
 
39
- def run_initializers
40
- self.class.initializers.each { |initializer| send(initializer.to_sym) }
40
+ ancestors.find { _1.respond_to?(:metatron_template_class?) && _1.metatron_template_class? }
41
41
  end
42
42
 
43
- def find_kind
44
- return self.class.name.split("::").last if metatron_template?
43
+ def self.metatron_template_class?
44
+ return true if name == "Metatron::Template"
45
+ return false if name.start_with?("Metatron::Templates::Concerns")
45
46
 
46
- self.class.ancestors.find { |klass| metatron_template?(klass) }.name.split("::").last
47
+ name.start_with?("Metatron::Templates::")
47
48
  end
48
49
 
49
- def metatron_template?(klass = self)
50
- klass.name.include?("Metatron::Templates") && !klass.name.include?("Concerns")
50
+ private
51
+
52
+ def run_initializers
53
+ self.class.nearest_metatron_ancestor.initializers.each { send(_1.to_sym) }
51
54
  end
55
+
56
+ def find_kind = self.class.nearest_metatron_ancestor.name.split("::").last
52
57
  end
53
58
  end
@@ -3,7 +3,7 @@
3
3
  module Metatron
4
4
  VERSION = [
5
5
  0, # major
6
- 2, # minor
7
- 8 # patch
6
+ 3, # minor
7
+ 1 # patch
8
8
  ].join(".")
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-05 00:00:00.000000000 Z
11
+ date: 2023-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json