pico_api 0.0.1 → 0.0.3

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
  SHA256:
3
- metadata.gz: 42f576489c0e3b0b4cc8ab9d23d3dd273f50f3fcd6cf29689b26a67ee6508c3f
4
- data.tar.gz: 83723e1d3095b13f302d016b8a3f2b166220a7e42842b569ef77cfd86f76648e
3
+ metadata.gz: 6d1191a8f8d535570f78985bbcb8fbd72c1ca6dae18c22c22721aaae7749e50d
4
+ data.tar.gz: ba4c1daa34d3f9dca5db1c2e3d2d617da6583b82394a62062cdbd919da7f34ab
5
5
  SHA512:
6
- metadata.gz: 7eb82db803e9e5f78d7c78ecf8a2054dfbd523f200331586e8ac1e9c45c38c837fdae794c4296c593627c97a976382aca69b77a478359d8473e882435dcb936f
7
- data.tar.gz: 43935b1f888497e2dafc4f488d53ecc4b55fdd48efa112ef6ca659b37cc94c4f8bbdef392ef30857ac0c474490a88d4e60cf8c1c2e2fb0186a6e719727fb17cf
6
+ metadata.gz: a886497c3c53c5ef5d9b7a64e0598ab397bb0409411f1463c4f45ae87a601cea58577a7daded0734ecb2fedbcb0aa8c746eb915e9775fe4a2b79352e6887a85e
7
+ data.tar.gz: a1c7f3f41ccb615fde6814e30afeb7e88c26349e181e1d7316fb79a8129bf7a529259e29291800c29111b5ce5b69abfad694e64f76901318efe01f13c2b135dd
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ group :test do
6
+ gem "rspec"
7
+ gem "pry"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ coderay (1.1.3)
5
+ diff-lcs (1.5.0)
6
+ method_source (1.0.0)
7
+ pry (0.14.1)
8
+ coderay (~> 1.1)
9
+ method_source (~> 1.0)
10
+ rspec (3.12.0)
11
+ rspec-core (~> 3.12.0)
12
+ rspec-expectations (~> 3.12.0)
13
+ rspec-mocks (~> 3.12.0)
14
+ rspec-core (3.12.0)
15
+ rspec-support (~> 3.12.0)
16
+ rspec-expectations (3.12.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.12.0)
19
+ rspec-mocks (3.12.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.12.0)
22
+ rspec-support (3.12.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ pry
29
+ rspec
30
+
31
+ BUNDLED WITH
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,14 +38,19 @@ 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
- - [ ] Create a Logger config
51
+ - [x] Create a Logger config
46
52
  - [ ] Create a testing environment
47
- - [ ] Allow multiple db gateways in the config
53
+ - [x] Allow multiple db gateways in the config
48
54
  - [ ] Add irb/pry console script
49
55
 
50
56
  ## Contributing
@@ -21,7 +21,7 @@ module PicoApi
21
21
 
22
22
  class Configuration
23
23
  attr_reader :db_config
24
- attr_accessor :namespace, :lib_path, :errors_map
24
+ attr_accessor :namespace, :lib_path, :errors_map, :logger
25
25
 
26
26
  def initialize(db_config)
27
27
  @db_config = db_config
@@ -9,15 +9,29 @@ module PicoApi
9
9
  attr_accessor :container
10
10
 
11
11
  def setup!
12
- database_config = PicoApi.configuration.db_config['default']
13
- adapter = database_config['adapter'].to_sym
14
- options = database_config['options'].symbolize_keys
15
- connection_string = database_config['connection_string']
12
+ database_config = PicoApi.configuration.db_config.deep_symbolize_keys
13
+ logger = PicoApi.configuration.logger
14
+ gateways = database_config.keys
16
15
 
17
- config = ROM::Configuration.new(adapter, connection_string, options)
18
- yield config if block_given?
16
+ configs = create_config(gateways, database_config)
17
+ cont = ROM.container(**configs) { |config| yield config if block_given? }
19
18
 
20
- @container = ROM.container(config)
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)
30
+ connection_string = database_config.dig(gateway, :connection_string)
31
+
32
+ memo[gateway] = [adapter, connection_string, **options]
33
+ memo
34
+ end
21
35
  end
22
36
  end
23
37
  end
@@ -1,9 +1,11 @@
1
1
  PicoApi.configure do |config|
2
2
  ## the base namespace of your app
3
- config.namespace = "<%= @project_name_camelcased %>"
3
+ config.namespace = "<%= @project_name_camelcased %>"
4
4
 
5
5
  ## the root directory where all the business logic resides
6
- config.lib_path = "lib/<%= @project_name_snakecased %>"
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
@@ -6,3 +6,9 @@ default:
6
6
  options:
7
7
  encoding:
8
8
 
9
+ # Additional gateways supported
10
+ # legacy:
11
+ # adapter:
12
+ # connection_string:
13
+ # options:
14
+ # encoding:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PicoApi
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.3'
5
5
  end
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.2.3'
26
- spec.add_runtime_dependency 'jsonapi-serializer', '~> 2.2.0'
27
- spec.add_runtime_dependency 'rackup', '~> 0.2.2'
28
- spec.add_runtime_dependency 'rake', '~> 13.0.6'
29
- spec.add_runtime_dependency 'roda', '~> 3.61.0'
30
- spec.add_runtime_dependency 'rom', '~> 5.2.6'
31
- spec.add_runtime_dependency 'rom-sql', '~> 3.5.0'
32
- spec.add_runtime_dependency 'zeitwerk', '~> 2.6.1'
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.1
4
+ version: 0.0.3
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-10-15 00:00:00.000000000 Z
11
+ date: 2022-11-06 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.2.3
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.2.3
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.2.0
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.2.0
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.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.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.0.6
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.0.6
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.61.0
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.61.0
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.2.6
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.2.6
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.0
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.0
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.1
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.1
124
+ version: '2.6'
125
125
  description: A tiny Rack-based ruby template for APIs
126
126
  email:
127
127
  executables:
@@ -130,6 +130,9 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
+ - ".rspec"
134
+ - Gemfile
135
+ - Gemfile.lock
133
136
  - LICENSE
134
137
  - Rakefile
135
138
  - Readme.md