roda-endpoints 0.3.2 → 0.3.3

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: f7372255aca1de1a82109d126d17cf936e6efc0e
4
- data.tar.gz: 1ca0b7962cbf1a076da564075699a6798d4f63d2
3
+ metadata.gz: 4e63ead2c011c6f56649e0e2b415888e59c3da9b
4
+ data.tar.gz: 1103b4c76e38b565eea322ad02f7e1eda7e0ca90
5
5
  SHA512:
6
- metadata.gz: 340dd36e447f1b258ba11600adff69f14a6d8d571111aafffc12b28601764b82af8100ca48b81f807166b9870c0455e08b0faee90ba4646e8ed27a19ae1ebc9d
7
- data.tar.gz: 218a1625f5ec243816a6901c4da4584a0ef525be2d125932cbbb185980614836154f8766d5b38e2038debe1a6425f7f14a3e88942b76b2879e9eb53652b117c0
6
+ metadata.gz: 4a5d7d870f36259ffc222e569c8c4b96e71c0107675fdcc0f1912a9ddc82973d96e395e77193c2e60ca29c5233078147907aa86b7b955e57d43521d677e919f1
7
+ data.tar.gz: c76f5fead6207851a7b0c312f2cefcede79fdda9c258c51567e691073d442b37d190db52b1faebee8fba9d2cb06367cc118f6335d629dd20a8b82f6da2df6dfe
@@ -30,7 +30,12 @@ class Roda
30
30
  # @param [Symbol] name
31
31
  # @param [Hash] params
32
32
  def child(name: item_name, type: Item, **params)
33
- super(name: name, type: type, **params)
33
+ super(
34
+ name: name,
35
+ type: type,
36
+ last_modified: @last_modified || Undefined,
37
+ **params
38
+ )
34
39
  end
35
40
 
36
41
  # @return [Symbol]
@@ -37,7 +37,7 @@ class Roda
37
37
 
38
38
  # @return [ROM::Struct]
39
39
  def entity
40
- @entity ||= fetch_entity
40
+ @entity ||= fetch_entity if id
41
41
  end
42
42
 
43
43
  attr_writer :entity
@@ -49,7 +49,7 @@ class Roda
49
49
 
50
50
  # @return [Time]
51
51
  def last_modified
52
- @last_modified ? entity.public_send(@last_modified) : super
52
+ @last_modified && entity ? entity.public_send(@last_modified) : super
53
53
  end
54
54
 
55
55
  route do |r, endpoint|
@@ -13,7 +13,7 @@ class Roda
13
13
 
14
14
  # @return [Time]
15
15
  def last_modified
16
- root.order(Sequel.desc(:updated_at)).first.updated_at
16
+ root.order(Sequel.desc(:updated_at)).first&.updated_at
17
17
  end
18
18
 
19
19
  # @param [Integer] id
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Roda
4
4
  module Endpoints
5
- VERSION = '0.3.2'
5
+ VERSION = '0.3.3'
6
6
  end
7
7
  end
@@ -97,11 +97,13 @@ class Roda
97
97
  item: { on: :id },
98
98
  type: Roda::Endpoints::Endpoint::Collection,
99
99
  on: name.to_s,
100
+ parent: root_endpoint,
100
101
  **kwargs)
101
102
  endpoint name: name,
102
103
  item: item,
103
104
  type: type,
104
105
  on: on,
106
+ parent: parent,
105
107
  **kwargs do |endpoint|
106
108
  yield endpoint if block_given?
107
109
  end
@@ -179,6 +181,7 @@ class Roda
179
181
  parent: current_endpoint,
180
182
  on: name,
181
183
  **kwargs)
184
+ parent ||= root_endpoint
182
185
  on on do |*captures|
183
186
  with_current_endpoint parent.child(
184
187
  name: name,
@@ -226,11 +229,15 @@ class Roda
226
229
 
227
230
  # @return [<Endpoint>]
228
231
  def endpoints
229
- @endpoints ||= [Roda::Endpoints::Endpoint.new(
232
+ @endpoints ||= [root_endpoint]
233
+ end
234
+
235
+ def root_endpoint
236
+ @root_endpoint ||= Roda::Endpoints::Endpoint.new(
230
237
  name: :root,
231
238
  ns: nil,
232
239
  container: roda_class.opts[:endpoints][:container]
233
- )]
240
+ )
234
241
  end
235
242
 
236
243
  def with_current_endpoint(endpoint)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-endpoints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Semyonov