roda-endpoints 0.2.0 → 0.3.0

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: aecfae0fdfb0156f3821d1273697d8ec24b698f6
4
- data.tar.gz: 8218ec6e8c89ab3a3967b23f14148a14e3098fcc
3
+ metadata.gz: c4c0a8fcc37a1cbc7990da886c1222bac0409c40
4
+ data.tar.gz: 05d751cf1cbb8ee521d75e31a74d4fbcd431c8b4
5
5
  SHA512:
6
- metadata.gz: 5d247edfad454ac8b11e196bbb1f88b91c663ea881a4241af55edb079c2f8cd9dfced72fea2f9a1cafd2ad8750b3e0d78a13b993aee7448ae29fbe7beea8e92c
7
- data.tar.gz: a7055fce9bc21bf0bd3d5054cd6d218029c1cfba764b48ee06c0e80243f84603a256ae08202345115bcbd32ed9d2c044c930c5fae347cd38f56dfef565cad153
6
+ metadata.gz: 97d1319b4411dae6b2b2e8b3945e5931d8c66f1b287eded402807dd35432038db8ba1b0d6ef13dcd5f943596e1d1334d95571a71ddcfc191fa754dd866366332
7
+ data.tar.gz: '05785933922272fb8d9bec0e39e73358be4472bc4a09434ca8923b5ddc0122984c4ae6b5ffb04f09af3845c17059f6cbdc7230d9a2739de90773573a0ad985e3'
@@ -22,6 +22,7 @@ class Roda
22
22
 
23
23
  # @param [Symbol] key
24
24
  def define_attribute(key)
25
+ self.attributes ||= superclass.attributes
25
26
  self.attributes += [key]
26
27
  attr_reader key
27
28
  end
@@ -9,7 +9,9 @@ class Roda
9
9
  # @param name [String]
10
10
  # @param repository [String]
11
11
  # @param attributes [{Symbol=>Object}]
12
- def initialize(name:, repository: "repositories.#{name}", **attributes)
12
+ def initialize(name:,
13
+ repository: "repositories.#{Inflecto.pluralize(name)}",
14
+ **attributes)
13
15
  @repository_key = repository
14
16
  super(name: name, **attributes)
15
17
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'roda/endpoints/endpoint/singleton'
4
4
  require 'roda/endpoints/endpoint/data'
5
+ require 'forwardable'
5
6
 
6
7
  class Roda
7
8
  module Endpoints
@@ -9,6 +10,8 @@ class Roda
9
10
  # HTTP endpoint representing a specific item of collection uniquely
10
11
  # identified by some parameter.
11
12
  class Item < Singleton
13
+ extend Forwardable
14
+
12
15
  prepend Data
13
16
 
14
17
  self.attributes += %i(id by on)
@@ -23,13 +26,15 @@ class Roda
23
26
 
24
27
  # @return [Integer]
25
28
  def id
26
- captures.first
29
+ @id ||= captures.first
27
30
  end
28
31
 
29
32
  # @return [Endpoint::Collection]
30
33
  def collection
31
34
  parent
32
35
  end
36
+
37
+ def_delegator :collection, :repository
33
38
  end
34
39
  end
35
40
  end
@@ -10,6 +10,7 @@ class Roda
10
10
  # HTTP endpoint representing a specific item of collection uniquely
11
11
  # identified by some parameter.
12
12
  class Singleton < Roda::Endpoints::Endpoint
13
+ prepend Data
13
14
  prepend Caching
14
15
 
15
16
  self.attributes += %i(finder last_modified)
@@ -35,7 +35,7 @@ class Roda
35
35
  # @param attributes [{Symbol=>Object}]
36
36
  def initialize(**attributes)
37
37
  self.class.defaults.merge(attributes).each do |key, value|
38
- # singleton_class.define_attribute(key) unless known_attribute?(key)
38
+ singleton_class.define_attribute(key) unless respond_to?(key)
39
39
  instance_variable_set(:"@#{key}", value)
40
40
  end
41
41
  end
@@ -48,8 +48,10 @@ class Roda
48
48
  # @param [Symbol] shortcut
49
49
  # @param [Proc] block
50
50
  def define(shortcut, &block)
51
+ key = key_for(shortcut)
52
+ return if container.key? key
51
53
  container.register(
52
- key_for(shortcut),
54
+ key,
53
55
  Dry.Transaction(
54
56
  container: container,
55
57
  endpoint: endpoint,
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Roda
4
4
  module Endpoints
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -56,7 +56,6 @@ class Roda
56
56
  end
57
57
 
58
58
  # `Roda::RodaRequest` instant extensions.
59
- # rubocop:disable Metrics/ModuleLength
60
59
  module RequestMethods
61
60
  # Implements collection endpoint using given args
62
61
  #
@@ -152,9 +151,8 @@ class Roda
152
151
 
153
152
  # @overload singleton(name, entity, type:, **kwargs)
154
153
  # @overload singleton(name:, entity:, type:, **kwargs)
155
- def singleton(*args,
156
- name: args.first,
157
- entity: args.last,
154
+ def singleton(name, *args,
155
+ entity: args.first,
158
156
  type: Roda::Endpoints::Endpoint::Singleton,
159
157
  **kwargs)
160
158
  endpoint(
data/rakelib/bundler.rake CHANGED
@@ -1,2 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  require 'bundler/gem_tasks'
3
+
4
+ task release: :default
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Semyonov