roda-endpoints 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/lib/roda/endpoints/endpoint/class_interface.rb +2 -8
- data/lib/roda/endpoints/endpoint/collection.rb +3 -3
- data/lib/roda/endpoints/endpoint/data.rb +8 -6
- data/lib/roda/endpoints/endpoint/item.rb +0 -18
- data/lib/roda/endpoints/endpoint/singleton.rb +19 -3
- data/lib/roda/endpoints/endpoint/transactions.rb +20 -9
- data/lib/roda/endpoints/endpoint.rb +10 -4
- data/lib/roda/endpoints/repository.rb +2 -2
- data/lib/roda/endpoints/version.rb +1 -1
- data/lib/roda/plugins/endpoints.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d27908a4d47343597580a44f31b0b70ffe4f4989
|
4
|
+
data.tar.gz: a3133effde967ed1f347b7f0d32193c3535d78c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48fc583f0aa6e9e8b2ffa32df5767f3cffde042f4f75aa3a8f1d11a98854e27c988c65fecf969ec7bbec6f8ccf2d646f7ae6d8bd4b78cf497eb44a9a4a0de98b
|
7
|
+
data.tar.gz: 62f7f1602928453c90ad979f695940c041aefc1f507971d0972ac9e0d273a70ad10700a5379425101b9972f4ad467f0cbae59afd9a226297f0dba5b972bedd70
|
data/.rubocop.yml
CHANGED
@@ -38,13 +38,6 @@ class Roda
|
|
38
38
|
child.defaults = defaults.dup
|
39
39
|
child.statuses = statuses.dup
|
40
40
|
child.verbs = verbs.dup
|
41
|
-
# child.verbs.each do |verb|
|
42
|
-
# key = "operations.#{child.type}.#{verb}"
|
43
|
-
# implementation = "operations.#{type}.#{verb}"
|
44
|
-
# container.register key do
|
45
|
-
# Endpoints.container.resolve implementation
|
46
|
-
# end
|
47
|
-
# end
|
48
41
|
child.transactions = transactions.dup
|
49
42
|
child.route(&@route_block)
|
50
43
|
super
|
@@ -76,7 +69,8 @@ class Roda
|
|
76
69
|
end
|
77
70
|
end
|
78
71
|
define_method(verb, &block)
|
79
|
-
|
72
|
+
key = "operations.#{type}.#{verb}"
|
73
|
+
container.register key, block
|
80
74
|
end
|
81
75
|
|
82
76
|
# @param [String, Symbol] key
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'roda/endpoints/endpoint'
|
3
4
|
require 'roda/endpoints/endpoint/data'
|
4
5
|
require 'roda/endpoints/endpoint/caching'
|
5
|
-
require 'roda/endpoints/endpoint'
|
6
6
|
require 'inflecto'
|
7
7
|
require 'rom/sql'
|
8
8
|
|
@@ -11,8 +11,8 @@ class Roda
|
|
11
11
|
class Endpoint
|
12
12
|
# HTTP endpoint representing a collection of items of the same type.
|
13
13
|
class Collection < Roda::Endpoints::Endpoint
|
14
|
-
|
15
|
-
|
14
|
+
include Data
|
15
|
+
include Caching
|
16
16
|
|
17
17
|
self.attributes += %i(item)
|
18
18
|
self.defaults = defaults.merge(
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'roda/endpoints'
|
4
|
+
require 'inflecto'
|
5
|
+
|
3
6
|
class Roda
|
4
7
|
module Endpoints
|
5
8
|
# Generic HTTP endpoint abstraction.
|
@@ -21,12 +24,11 @@ class Roda
|
|
21
24
|
|
22
25
|
# @return [ROM::Repository]
|
23
26
|
def repository
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
super.merge(repository: @repository_key)
|
27
|
+
if @repository_key.is_a?(String)
|
28
|
+
container[@repository_key]
|
29
|
+
else
|
30
|
+
@repository_key
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'roda/endpoints/endpoint/singleton'
|
4
|
-
require 'roda/endpoints/endpoint/data'
|
5
4
|
require 'forwardable'
|
6
5
|
|
7
6
|
class Roda
|
@@ -12,23 +11,6 @@ class Roda
|
|
12
11
|
class Item < Singleton
|
13
12
|
extend Forwardable
|
14
13
|
|
15
|
-
prepend Data
|
16
|
-
|
17
|
-
self.attributes += %i(id by on)
|
18
|
-
self.defaults = defaults.merge(
|
19
|
-
by: :fetch,
|
20
|
-
on: :id,
|
21
|
-
finder: -> { repository.public_send(by, id) }
|
22
|
-
)
|
23
|
-
|
24
|
-
# @return [Symbol]
|
25
|
-
attr_reader :by
|
26
|
-
|
27
|
-
# @return [Integer]
|
28
|
-
def id
|
29
|
-
@id ||= captures.first
|
30
|
-
end
|
31
|
-
|
32
14
|
# @return [Endpoint::Collection]
|
33
15
|
def collection
|
34
16
|
parent
|
@@ -10,15 +10,31 @@ 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
|
-
|
14
|
-
|
13
|
+
include Data
|
14
|
+
include Caching
|
15
15
|
|
16
16
|
self.attributes += %i(finder last_modified)
|
17
|
-
self.defaults = defaults.merge(
|
17
|
+
self.defaults = defaults.merge(
|
18
|
+
last_modified: :updated_at,
|
19
|
+
by: :fetch,
|
20
|
+
on: :id,
|
21
|
+
finder: -> { repository.public_send(by, id) }
|
22
|
+
)
|
23
|
+
|
24
|
+
# @return [Symbol]
|
25
|
+
attr_reader :by
|
26
|
+
|
27
|
+
# @return [Symbol]
|
28
|
+
attr_reader :on
|
18
29
|
|
19
30
|
# @return [Symbol]
|
20
31
|
attr_reader :finder
|
21
32
|
|
33
|
+
# @return [Integer]
|
34
|
+
def id
|
35
|
+
@id ||= captures.first
|
36
|
+
end
|
37
|
+
|
22
38
|
# @return [ROM::Struct]
|
23
39
|
def entity
|
24
40
|
@entity ||= fetch_entity
|
@@ -10,19 +10,30 @@ class Roda
|
|
10
10
|
module Transactions
|
11
11
|
# @return [Endpoints::Transactions]
|
12
12
|
def transactions
|
13
|
-
endpoint
|
14
|
-
@transactions ||=
|
15
|
-
begin
|
16
|
-
transactions = Endpoints::Transactions.new(endpoint: self)
|
17
|
-
self.class.transactions.each do |(name, block)|
|
18
|
-
transactions.define(name) { instance_exec(endpoint, &block) }
|
19
|
-
end
|
20
|
-
transactions
|
21
|
-
end
|
13
|
+
@transactions ||= Endpoints::Transactions.new(endpoint: self)
|
22
14
|
yield @transaction if block_given?
|
23
15
|
@transactions
|
24
16
|
end
|
25
17
|
|
18
|
+
def prepare_transactions!
|
19
|
+
return if @transactions_prepared
|
20
|
+
endpoint = self
|
21
|
+
self.class.transactions.each do |(name, block)|
|
22
|
+
transactions.define(name) do
|
23
|
+
instance_exec(endpoint, &block)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
verbs.each do |verb|
|
27
|
+
key = "operations.#{ns}.#{verb}"
|
28
|
+
next if container.key?(key)
|
29
|
+
operation = method(verb)
|
30
|
+
container.register key do |*args|
|
31
|
+
endpoint.instance_exec(*args, &operation)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@transactions_prepared = true
|
35
|
+
end
|
36
|
+
|
26
37
|
# @param [Symbol, String] name
|
27
38
|
# @param [Proc] block
|
28
39
|
def step(name, only: [], **kwargs, &block)
|
@@ -7,6 +7,8 @@ require 'roda/endpoints/endpoint/namespace'
|
|
7
7
|
require 'roda/endpoints/endpoint/transactions'
|
8
8
|
require 'roda/endpoints/endpoint/validations'
|
9
9
|
require 'roda/endpoints/endpoint/verbs'
|
10
|
+
require 'roda/endpoints/endpoint/data'
|
11
|
+
require 'roda/endpoints/endpoint/caching'
|
10
12
|
require 'dry/monads'
|
11
13
|
|
12
14
|
class Roda
|
@@ -40,13 +42,16 @@ class Roda
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
|
45
|
+
include Namespace
|
44
46
|
prepend Verbs
|
45
|
-
|
47
|
+
include Validations
|
46
48
|
include Transactions
|
47
|
-
|
49
|
+
include Lookup
|
48
50
|
|
49
|
-
|
51
|
+
# @return [Array]
|
52
|
+
attr_reader :captures
|
53
|
+
# @return [String, Symbol]
|
54
|
+
attr_reader :on
|
50
55
|
|
51
56
|
# @return [Symbol]
|
52
57
|
def type
|
@@ -74,6 +79,7 @@ class Roda
|
|
74
79
|
def route
|
75
80
|
prepare_validations!
|
76
81
|
prepare_verbs!
|
82
|
+
prepare_transactions!
|
77
83
|
self.class.route
|
78
84
|
end
|
79
85
|
|
@@ -13,13 +13,13 @@ class Roda
|
|
13
13
|
|
14
14
|
# @return [Time]
|
15
15
|
def last_modified
|
16
|
-
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
|
20
20
|
# @return [ROM::Struct]
|
21
21
|
def fetch(id)
|
22
|
-
root.fetch(id)
|
22
|
+
root.fetch(id.to_i)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|