pico_api 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/Gemfile.lock +1 -94
- data/Readme.md +9 -2
- data/lib/pico_api/configuration.rb +10 -14
- data/lib/pico_api/database.rb +17 -9
- data/lib/pico_api/generators/templates/config/boot.erb +1 -1
- data/lib/pico_api/generators/templates/config/configuration.erb +4 -2
- data/lib/pico_api/version.rb +1 -1
- data/pico_api.gemspec +8 -8
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e00987197e956e77af63d09b3d1d458e335857f6a376076824c0f35da7154295
|
4
|
+
data.tar.gz: 4bed688ad8bd088af9bc9c4532b2b1fde95f215a1da74c8bb161980f5a3a5e64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cb58169f60fd534f1f1dc79beccdc36c698dab9fcd2b3300783ba2e627a4f68db2eb70f2bdfb26217d11747d4c5837a202218209edbc05a12dafb9e77204d2d
|
7
|
+
data.tar.gz: 41e81c723e248df1d4cadaf0055f63ae662025113137f5b2fd57889eba9ca6336c63b825afe8158c53bed903faa6ee40120c2f7d3e7fe1ed607d106ed1fcf849
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,98 +1,12 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
pico_api (0.0.1)
|
5
|
-
erb (~> 2.2.3)
|
6
|
-
jsonapi-serializer (~> 2.2.0)
|
7
|
-
rackup (~> 0.2.2)
|
8
|
-
rake (~> 13.0.6)
|
9
|
-
roda (~> 3.61.0)
|
10
|
-
rom (~> 5.2.6)
|
11
|
-
rom-sql (~> 3.5.0)
|
12
|
-
zeitwerk (~> 2.6.1)
|
13
|
-
|
14
1
|
GEM
|
15
2
|
remote: https://rubygems.org/
|
16
3
|
specs:
|
17
|
-
activesupport (7.0.4)
|
18
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
-
i18n (>= 1.6, < 2)
|
20
|
-
minitest (>= 5.1)
|
21
|
-
tzinfo (~> 2.0)
|
22
|
-
cgi (0.3.3)
|
23
4
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.1.10)
|
25
5
|
diff-lcs (1.5.0)
|
26
|
-
dry-container (0.11.0)
|
27
|
-
concurrent-ruby (~> 1.0)
|
28
|
-
dry-core (0.9.1)
|
29
|
-
concurrent-ruby (~> 1.0)
|
30
|
-
zeitwerk (~> 2.6)
|
31
|
-
dry-equalizer (0.3.0)
|
32
|
-
dry-inflector (0.3.0)
|
33
|
-
dry-initializer (3.1.1)
|
34
|
-
dry-logic (1.3.0)
|
35
|
-
concurrent-ruby (~> 1.0)
|
36
|
-
dry-core (~> 0.9, >= 0.9)
|
37
|
-
zeitwerk (~> 2.6)
|
38
|
-
dry-struct (1.5.2)
|
39
|
-
dry-core (~> 0.9, >= 0.9)
|
40
|
-
dry-types (~> 1.6)
|
41
|
-
ice_nine (~> 0.11)
|
42
|
-
zeitwerk (~> 2.6)
|
43
|
-
dry-types (1.6.1)
|
44
|
-
concurrent-ruby (~> 1.0)
|
45
|
-
dry-container (~> 0.3)
|
46
|
-
dry-core (~> 0.9, >= 0.9)
|
47
|
-
dry-inflector (~> 0.1, >= 0.1.2)
|
48
|
-
dry-logic (~> 1.3, >= 1.3)
|
49
|
-
zeitwerk (~> 2.6)
|
50
|
-
erb (2.2.3)
|
51
|
-
cgi
|
52
|
-
i18n (1.12.0)
|
53
|
-
concurrent-ruby (~> 1.0)
|
54
|
-
ice_nine (0.11.2)
|
55
|
-
jsonapi-serializer (2.2.0)
|
56
|
-
activesupport (>= 4.2)
|
57
6
|
method_source (1.0.0)
|
58
|
-
minitest (5.16.3)
|
59
7
|
pry (0.14.1)
|
60
8
|
coderay (~> 1.1)
|
61
9
|
method_source (~> 1.0)
|
62
|
-
rack (3.0.0)
|
63
|
-
rackup (0.2.2)
|
64
|
-
rack (>= 3.0.0.beta1)
|
65
|
-
webrick
|
66
|
-
rake (13.0.6)
|
67
|
-
roda (3.61.0)
|
68
|
-
rack
|
69
|
-
rom (5.2.6)
|
70
|
-
rom-changeset (~> 5.2, >= 5.2.3)
|
71
|
-
rom-core (~> 5.2, >= 5.2.5)
|
72
|
-
rom-repository (~> 5.2, >= 5.2.2)
|
73
|
-
rom-changeset (5.2.3)
|
74
|
-
dry-core (~> 0.4)
|
75
|
-
rom-core (~> 5.2)
|
76
|
-
transproc (~> 1.0, >= 1.1.0)
|
77
|
-
rom-core (5.2.6)
|
78
|
-
concurrent-ruby (~> 1.1)
|
79
|
-
dry-container (~> 0.7)
|
80
|
-
dry-core (~> 0.4)
|
81
|
-
dry-equalizer (~> 0.2)
|
82
|
-
dry-inflector (~> 0.1)
|
83
|
-
dry-initializer (~> 3.0, >= 3.0.1)
|
84
|
-
dry-struct (~> 1.0)
|
85
|
-
dry-types (~> 1.0)
|
86
|
-
transproc (~> 1.0, >= 1.1.0)
|
87
|
-
rom-repository (5.2.2)
|
88
|
-
dry-core (~> 0.4)
|
89
|
-
dry-initializer (~> 3.0, >= 3.0.1)
|
90
|
-
rom-core (~> 5.2, >= 5.2.2)
|
91
|
-
rom-sql (3.5.0)
|
92
|
-
dry-core (~> 0.5, >= 0.5)
|
93
|
-
dry-types (~> 1.0)
|
94
|
-
rom (~> 5.2, >= 5.2.1)
|
95
|
-
sequel (>= 4.49)
|
96
10
|
rspec (3.12.0)
|
97
11
|
rspec-core (~> 3.12.0)
|
98
12
|
rspec-expectations (~> 3.12.0)
|
@@ -106,20 +20,13 @@ GEM
|
|
106
20
|
diff-lcs (>= 1.2.0, < 2.0)
|
107
21
|
rspec-support (~> 3.12.0)
|
108
22
|
rspec-support (3.12.0)
|
109
|
-
sequel (5.62.0)
|
110
|
-
transproc (1.1.1)
|
111
|
-
tzinfo (2.0.5)
|
112
|
-
concurrent-ruby (~> 1.0)
|
113
|
-
webrick (1.7.0)
|
114
|
-
zeitwerk (2.6.4)
|
115
23
|
|
116
24
|
PLATFORMS
|
117
25
|
ruby
|
118
26
|
|
119
27
|
DEPENDENCIES
|
120
|
-
pico_api!
|
121
28
|
pry
|
122
|
-
rspec
|
29
|
+
rspec
|
123
30
|
|
124
31
|
BUNDLED WITH
|
125
32
|
2.1.4
|
data/Readme.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Pico API
|
2
2
|
|
3
3
|
A tiny boilerplate JSON API template in ruby. Its minimal footprint makes it ideal for microservices or even full blown APIs.
|
4
|
-
It has been created for those who don't need the RAILS "magic" and bloat. Can easily create different architectures, like STAR, CQRS..., and MVC.
|
4
|
+
It has been created for those who don't need the RAILS "magic" and bloat. Can easily create different architectures, like STAR, CQRS, DDD..., and MVC.
|
5
5
|
|
6
6
|
Pico API is just a collection of the fastest ruby libraries put together to form a basic API environment, with the JSON:API specification. It doesn't create any folder structures for your business logic, it only creates the initial configurations to get you started.
|
7
7
|
|
@@ -9,6 +9,7 @@ Example demo project can be found [here](https://github.com/alexavlonitis/pico_a
|
|
9
9
|
|
10
10
|
## Libraries Used
|
11
11
|
|
12
|
+
- Rack -> Backbone
|
12
13
|
- [roda](https://github.com/jeremyevans/roda) -> Routing
|
13
14
|
- [rom-rb](https://github.com/rom-rb/rom) -> ORM
|
14
15
|
- [jsonapi serializer](https://github.com/jsonapi-serializer/jsonapi-serializer) -> Fast-jsonapi fork
|
@@ -37,15 +38,21 @@ Migration info: https://rom-rb.org/5.0/learn/sql/migrations/
|
|
37
38
|
- Run the migrations: `rake db:migrate`
|
38
39
|
- Run the server: `rackup -p 3001`
|
39
40
|
|
41
|
+
### Routing
|
42
|
+
|
43
|
+
Routing info: https://github.com/jeremyevans/roda
|
44
|
+
|
45
|
+
Add routing info in `config/application.rb` file
|
40
46
|
|
41
47
|
## Development
|
42
48
|
- [x] Create Database config
|
43
49
|
- [x] Hook a json-api library
|
44
50
|
- [x] Handle Errors
|
45
|
-
- [
|
51
|
+
- [x] Create a Logger config
|
46
52
|
- [ ] Create a testing environment
|
47
53
|
- [x] Allow multiple db gateways in the config
|
48
54
|
- [ ] Add irb/pry console script
|
55
|
+
- [ ] Seperate configs to different environments (dev, prod, etc..)
|
49
56
|
|
50
57
|
## Contributing
|
51
58
|
|
@@ -6,7 +6,12 @@ require 'yaml'
|
|
6
6
|
module PicoApi
|
7
7
|
class << self
|
8
8
|
def configuration
|
9
|
-
@configuration ||= Configuration.new
|
9
|
+
@configuration ||= Configuration.new(db_config)
|
10
|
+
end
|
11
|
+
|
12
|
+
def db_config
|
13
|
+
template = ERB.new(File.new('./config/database.yml').read)
|
14
|
+
YAML.safe_load(template.result(binding))
|
10
15
|
end
|
11
16
|
|
12
17
|
def configure
|
@@ -15,20 +20,11 @@ module PicoApi
|
|
15
20
|
end
|
16
21
|
|
17
22
|
class Configuration
|
18
|
-
|
19
|
-
|
20
|
-
def db_yaml_path
|
21
|
-
@db_yaml_path || "/config/database.yml"
|
22
|
-
end
|
23
|
-
|
24
|
-
def db_config
|
25
|
-
YAML.safe_load(read_db_yaml_file.result(binding))
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
23
|
+
attr_reader :db_config
|
24
|
+
attr_accessor :namespace, :lib_path, :errors_map, :logger
|
29
25
|
|
30
|
-
def
|
31
|
-
|
26
|
+
def initialize(db_config)
|
27
|
+
@db_config = db_config
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
data/lib/pico_api/database.rb
CHANGED
@@ -9,21 +9,29 @@ module PicoApi
|
|
9
9
|
attr_accessor :container
|
10
10
|
|
11
11
|
def setup!
|
12
|
-
database_config = PicoApi.configuration.db_config.
|
12
|
+
database_config = PicoApi.configuration.db_config.deep_symbolize_keys
|
13
|
+
logger = PicoApi.configuration.logger
|
13
14
|
gateways = database_config.keys
|
14
15
|
|
15
|
-
configs = gateways
|
16
|
-
|
17
|
-
|
16
|
+
configs = create_config(gateways, database_config)
|
17
|
+
cont = ROM.container(**configs) { |config| yield config if block_given? }
|
18
|
+
|
19
|
+
gateways.each { |gateway| cont.gateways[gateway].use_logger(logger) } if logger
|
20
|
+
|
21
|
+
@container = cont
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def create_config(gateways, database_config)
|
27
|
+
gateways.inject({}) do |memo, gateway|
|
28
|
+
adapter = database_config.dig(gateway, :adapter)&.to_sym
|
29
|
+
options = database_config.dig(gateway, :options)
|
18
30
|
connection_string = database_config.dig(gateway, :connection_string)
|
19
31
|
|
20
|
-
memo[gateway] = [adapter, connection_string, options]
|
32
|
+
memo[gateway] = [adapter, connection_string, **options]
|
21
33
|
memo
|
22
34
|
end
|
23
|
-
|
24
|
-
@container = ROM.container(**configs) do |config|
|
25
|
-
yield config if block_given?
|
26
|
-
end
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
PicoApi.configure do |config|
|
2
2
|
## the base namespace of your app
|
3
|
-
config.namespace
|
3
|
+
config.namespace = "<%= @project_name_camelcased %>"
|
4
4
|
|
5
5
|
## the root directory where all the business logic resides
|
6
|
-
config.lib_path
|
6
|
+
config.lib_path = "lib/<%= @project_name_snakecased %>"
|
7
|
+
|
8
|
+
config.logger = Logger.new(STDOUT) if ENV['LOG_TO_STDOUT'] == 'true'
|
7
9
|
|
8
10
|
## Add your custom exception mappings -> { exception: status_code }.
|
9
11
|
# PicoApi serializes runtime exceptions to json-api specification error objects
|
data/lib/pico_api/version.rb
CHANGED
data/pico_api.gemspec
CHANGED
@@ -22,12 +22,12 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
spec.executables << 'pico_api'
|
24
24
|
|
25
|
-
spec.add_runtime_dependency 'erb', '~> 2
|
26
|
-
spec.add_runtime_dependency 'jsonapi-serializer', '~> 2
|
27
|
-
spec.add_runtime_dependency 'rackup', '~> 0.2
|
28
|
-
spec.add_runtime_dependency 'rake', '~> 13
|
29
|
-
spec.add_runtime_dependency 'roda', '~> 3
|
30
|
-
spec.add_runtime_dependency 'rom', '~> 5
|
31
|
-
spec.add_runtime_dependency 'rom-sql', '~> 3.5
|
32
|
-
spec.add_runtime_dependency 'zeitwerk', '~> 2.6
|
25
|
+
spec.add_runtime_dependency 'erb', '~> 2'
|
26
|
+
spec.add_runtime_dependency 'jsonapi-serializer', '~> 2'
|
27
|
+
spec.add_runtime_dependency 'rackup', '~> 0.2'
|
28
|
+
spec.add_runtime_dependency 'rake', '~> 13'
|
29
|
+
spec.add_runtime_dependency 'roda', '~> 3'
|
30
|
+
spec.add_runtime_dependency 'rom', '~> 5'
|
31
|
+
spec.add_runtime_dependency 'rom-sql', '~> 3.5'
|
32
|
+
spec.add_runtime_dependency 'zeitwerk', '~> 2.6'
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pico_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Avlonitis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erb
|
@@ -16,112 +16,112 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2
|
19
|
+
version: '2'
|
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: 2
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jsonapi-serializer
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2
|
33
|
+
version: '2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rackup
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2
|
47
|
+
version: '0.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.2
|
54
|
+
version: '0.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 13
|
61
|
+
version: '13'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 13
|
68
|
+
version: '13'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: roda
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3
|
75
|
+
version: '3'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3
|
82
|
+
version: '3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rom
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 5
|
89
|
+
version: '5'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 5
|
96
|
+
version: '5'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rom-sql
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 3.5
|
103
|
+
version: '3.5'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 3.5
|
110
|
+
version: '3.5'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: zeitwerk
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.6
|
117
|
+
version: '2.6'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.6
|
124
|
+
version: '2.6'
|
125
125
|
description: A tiny Rack-based ruby template for APIs
|
126
126
|
email:
|
127
127
|
executables:
|