hecks-adapters-resource-server 0.1.16.rc → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cli/cli.rb +1 -0
- data/lib/cli/generate_resource_server.rb +21 -0
- data/lib/cli/templates/resource_server/config.ru.tt +8 -0
- data/lib/hecks-adapters-resource-server.rb +45 -44
- data/lib/methods.rb +10 -11
- data/lib/methods/create.rb +42 -43
- data/lib/methods/delete.rb +31 -32
- data/lib/methods/read.rb +31 -32
- data/lib/methods/update.rb +43 -44
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 528dd6c903cd3519469532cc68b927276f49bf25
|
4
|
+
data.tar.gz: d2f5f0dd80b8dc6366a9209dfe4d61957a54bc17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef2084e368fac97ec3210f2e58e854817f4f73699dd62fecf2759623b8a2bfd219a66541af4b4b51738551fd3e5ad49de4ef1baa7989beb0d065b571397eb19
|
7
|
+
data.tar.gz: 1c1e2b14fe7f5365969fe2671834c4462869b6fc1dee7be1a690f26e990dd88dd88fdb4abf6905f5cf5ee61b6057df9a27eaa3025b0ed18deddc984d7f720202
|
data/lib/cli/cli.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'generate_resource_server'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module HecksAdapters
|
2
|
+
class ResourceServer
|
3
|
+
module CLI
|
4
|
+
class GenerateResourceServer < Thor::Group
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
File.dirname(__FILE__) + '/templates/'
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_aggregate_folder
|
12
|
+
directory('resource_server', '.')
|
13
|
+
end
|
14
|
+
|
15
|
+
def domain
|
16
|
+
File.basename(Dir.getwd)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,51 +3,52 @@ require 'sinatra'
|
|
3
3
|
require 'hecks-application'
|
4
4
|
require 'json'
|
5
5
|
require_relative 'methods'
|
6
|
+
require_relative 'cli/cli'
|
7
|
+
|
8
|
+
module HecksAdapters
|
9
|
+
# Wrap your domain in a cozy Resource Server. This file maps the routes to
|
10
|
+
# methods on your domain models
|
11
|
+
class ResourceServer < Sinatra::Base
|
12
|
+
configure do
|
13
|
+
set :raise_errors, true
|
14
|
+
set :show_exceptions, false
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(app: nil, application_adapter:)
|
18
|
+
super(app)
|
19
|
+
@methods = Methods.new(application_adapter: application_adapter)
|
20
|
+
end
|
6
21
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
set :raise_errors, true
|
12
|
-
set :show_exceptions, false
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(app: nil, application_adapter:)
|
16
|
-
super(app)
|
17
|
-
@methods = Methods.new(application_adapter: application_adapter)
|
18
|
-
end
|
19
|
-
|
20
|
-
get '/:module_name/:id' do |module_name, id|
|
21
|
-
command = methods.read.call(id: id, module_name: module_name)
|
22
|
-
body command.result
|
23
|
-
status command.status
|
24
|
-
end
|
25
|
-
|
26
|
-
post '/:module_name' do |module_name|
|
27
|
-
command = methods.create.call(body: request.body, module_name: module_name)
|
28
|
-
status command.status
|
29
|
-
body command.result
|
30
|
-
end
|
31
|
-
|
32
|
-
put '/:module_name/:id' do |module_name, id|
|
33
|
-
command = methods.update.call(
|
34
|
-
id: id,
|
35
|
-
body: request.body,
|
36
|
-
module_name: module_name
|
37
|
-
)
|
38
|
-
status command.status
|
39
|
-
body command.result
|
40
|
-
end
|
41
|
-
|
42
|
-
delete '/:module_name/:id' do |module_name, id|
|
43
|
-
command = methods.delete.call(id: id, module_name: module_name)
|
44
|
-
status command.status
|
45
|
-
body command.result
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
attr_reader :methods
|
22
|
+
get '/:module_name/:id' do |module_name, id|
|
23
|
+
command = methods.read.call(id: id, module_name: module_name)
|
24
|
+
body command.result
|
25
|
+
status command.status
|
51
26
|
end
|
27
|
+
|
28
|
+
post '/:module_name' do |module_name|
|
29
|
+
command = methods.create.call(body: request.body, module_name: module_name)
|
30
|
+
status command.status
|
31
|
+
body command.result
|
32
|
+
end
|
33
|
+
|
34
|
+
put '/:module_name/:id' do |module_name, id|
|
35
|
+
command = methods.update.call(
|
36
|
+
id: id,
|
37
|
+
body: request.body,
|
38
|
+
module_name: module_name
|
39
|
+
)
|
40
|
+
status command.status
|
41
|
+
body command.result
|
42
|
+
end
|
43
|
+
|
44
|
+
delete '/:module_name/:id' do |module_name, id|
|
45
|
+
command = methods.delete.call(id: id, module_name: module_name)
|
46
|
+
status command.status
|
47
|
+
body command.result
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_reader :methods
|
52
53
|
end
|
53
54
|
end
|
data/lib/methods.rb
CHANGED
@@ -4,18 +4,17 @@ require_relative 'methods/read'
|
|
4
4
|
require_relative 'methods/update'
|
5
5
|
require_relative 'methods/delete'
|
6
6
|
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
module HecksAdapters
|
8
|
+
class ResourceServer
|
9
|
+
# CRUD methods for your domain
|
10
|
+
class Methods
|
11
|
+
attr_reader :create, :read, :update, :delete
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
13
|
+
def initialize(application_adapter:)
|
14
|
+
@create = Create.new(application_adapter: application_adapter)
|
15
|
+
@read = Read.new(application_adapter: application_adapter)
|
16
|
+
@update = Update.new(application_adapter: application_adapter)
|
17
|
+
@delete = Delete.new(application_adapter: application_adapter)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
data/lib/methods/create.rb
CHANGED
@@ -1,47 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
2
|
+
module HecksAdapters
|
3
|
+
class ResourceServer < Sinatra::Base
|
4
|
+
class Methods
|
5
|
+
# Create a resource
|
6
|
+
class Create
|
7
|
+
attr_reader :result
|
8
|
+
|
9
|
+
def initialize(application_adapter:)
|
10
|
+
@application_adapter = application_adapter
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(body:, module_name:)
|
14
|
+
@body = body.read
|
15
|
+
@module_name = module_name.to_sym
|
16
|
+
run_command
|
17
|
+
build_json
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def status
|
22
|
+
return 500 if command_result.errors.count.positive?
|
23
|
+
200
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :application_adapter, :body, :module_name, :command_result
|
29
|
+
|
30
|
+
def build_json
|
31
|
+
@result = JSON.generate(command_result.to_h)
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_command
|
35
|
+
@command_result = application_adapter.call(
|
36
|
+
module_name: module_name,
|
37
|
+
command_name: :create,
|
38
|
+
args: params
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def params
|
43
|
+
JSON.parse(body, symbolize_names: true)
|
45
44
|
end
|
46
45
|
end
|
47
46
|
end
|
data/lib/methods/delete.rb
CHANGED
@@ -1,43 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module HecksAdapters
|
3
|
+
class ResourceServer < Sinatra::Base
|
4
|
+
class Methods
|
5
|
+
# Delete a resource
|
6
|
+
class Delete
|
7
|
+
attr_reader :result
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def initialize(application_adapter:)
|
10
|
+
@application_adapter = application_adapter
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def call(id:, module_name:)
|
14
|
+
@id = id
|
15
|
+
@module_name = module_name.to_sym
|
16
|
+
run_command
|
17
|
+
convert_to_json
|
18
|
+
self
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def status
|
22
|
+
return 500 if command_result.errors.count.positive?
|
23
|
+
200
|
24
|
+
end
|
25
25
|
|
26
|
-
|
26
|
+
private
|
27
27
|
|
28
|
-
|
28
|
+
attr_reader :application_adapter, :module_name, :id, :command_result
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
def convert_to_json
|
31
|
+
@result = JSON.generate(command_result.to_h)
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
34
|
+
def run_command
|
35
|
+
@command_result = application_adapter.call(
|
36
|
+
module_name: module_name,
|
37
|
+
command_name: :delete,
|
38
|
+
args: { id: id }
|
39
|
+
)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
data/lib/methods/read.rb
CHANGED
@@ -1,42 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
module HecksAdapters
|
3
|
+
class ResourceServer < Sinatra::Base
|
4
|
+
class Methods
|
5
|
+
# Read a resource
|
6
|
+
class Read
|
7
|
+
attr_reader :result, :status
|
8
|
+
def initialize(application_adapter:)
|
9
|
+
@application_adapter = application_adapter
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def call(id:, module_name:)
|
13
|
+
@id = id
|
14
|
+
@module_name = module_name.to_sym
|
15
|
+
run_query
|
16
|
+
convert_to_json
|
17
|
+
self
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def status
|
21
|
+
return 404 if command_result.nil?
|
22
|
+
200
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
private
|
26
26
|
|
27
|
-
|
27
|
+
attr_reader :application_adapter, :id, :module_name, :command_result
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def convert_to_json
|
30
|
+
@result = command_result.to_json
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
33
|
+
def run_query
|
34
|
+
@command_result = application_adapter.query(
|
35
|
+
query_name: :find_by_id,
|
36
|
+
module_name: module_name,
|
37
|
+
args: { id: id }
|
38
|
+
)
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
data/lib/methods/update.rb
CHANGED
@@ -1,48 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
2
|
+
module HecksAdapters
|
3
|
+
class ResourceServer < Sinatra::Base
|
4
|
+
class Methods
|
5
|
+
# Update a resource
|
6
|
+
class Update
|
7
|
+
attr_reader :result
|
8
|
+
|
9
|
+
def initialize(application_adapter:)
|
10
|
+
@application_adapter = application_adapter
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(id:, body:, module_name:)
|
14
|
+
@id = id
|
15
|
+
@body = body.read
|
16
|
+
@module_name = module_name.to_sym
|
17
|
+
run_command
|
18
|
+
convert_to_json
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def status
|
23
|
+
return 500 if command.result[:errors].count.positive?
|
24
|
+
200
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_accessor :application_adapter, :id, :body, :module_name, :command
|
30
|
+
|
31
|
+
def convert_to_json
|
32
|
+
@result = JSON.generate(command.to_h)
|
33
|
+
end
|
34
|
+
|
35
|
+
def run_command
|
36
|
+
@command = application_adapter.call(
|
37
|
+
module_name: module_name,
|
38
|
+
command_name: :update,
|
39
|
+
args: params
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def params
|
44
|
+
JSON.parse(body, symbolize_names: true).merge(id: id)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hecks-adapters-resource-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Young
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hecks-application
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sinatra
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,9 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- lib/cli/cli.rb
|
62
|
+
- lib/cli/generate_resource_server.rb
|
63
|
+
- lib/cli/templates/resource_server/config.ru.tt
|
61
64
|
- lib/hecks-adapters-resource-server.rb
|
62
65
|
- lib/methods.rb
|
63
66
|
- lib/methods/create.rb
|
@@ -79,13 +82,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
82
|
version: '0'
|
80
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
84
|
requirements:
|
82
|
-
- - "
|
85
|
+
- - ">="
|
83
86
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
87
|
+
version: '0'
|
85
88
|
requirements: []
|
86
89
|
rubyforge_project:
|
87
90
|
rubygems_version: 2.6.10
|
88
91
|
signing_key:
|
89
92
|
specification_version: 4
|
90
|
-
summary: Drive a resourceful web server with Domains created using
|
93
|
+
summary: Drive a resourceful web server with Domains created using HecksDomain generators
|
91
94
|
test_files: []
|