scf_core 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5725126a380791370fbb3a1c3f31b8f90ad4763f2024e7fcee1a36b464a9a630
4
+ data.tar.gz: 4edc490e9c2d2de7717218b0d7a5da95b32401319a9973eb1f9ecdf3ba0c3c4d
5
+ SHA512:
6
+ metadata.gz: 2ab7c166bb5eb54d39718c8d4604b15b865d208a33d499f30b70f5c3a12824264a3034e478e03292a39430bdade3dc0edefabe2eea963a43d4ac782519870047
7
+ data.tar.gz: 28c3eaa830828349700bd0d701e8aa56d47873169b7cdf68eb3f6c5ec59a887cc8858cce031c2276a8a32b6de4313e7180e8550dcca2ca07f566d49b960227fb
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Asrat
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Scf::Core
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "scf_core"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install scf_core
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,142 @@
1
+ module Scf
2
+ module Core
3
+ module Common
4
+ extend ActiveSupport::Concern
5
+ include Pagination
6
+
7
+ included do
8
+ before_action :set_clazz
9
+ before_action :set_object, only: %i[show update]
10
+ end
11
+
12
+ def index
13
+ data = nil
14
+ options = {}
15
+ if block_given?
16
+ incoming = yield
17
+ if incoming.instance_of?(Array)
18
+ data, options = incoming
19
+ elsif incoming.instance_of?(Hash)
20
+ options = incoming
21
+ else
22
+ data = incoming
23
+ end
24
+ else
25
+ data = @clazz.all
26
+ end
27
+ total = data.count
28
+ data = data.then(&paginate) if params[:page]
29
+ result = {
30
+ success: true,
31
+ data: serialize(data, options)
32
+ }
33
+ if params[:page]
34
+ result[:page] = params[:page]
35
+ result[:total] = total
36
+ end
37
+
38
+ render json: result
39
+ end
40
+
41
+ def show
42
+ data = nil
43
+ options = {}
44
+ if block_given?
45
+ incoming = yield
46
+ if incoming.instance_of?(Array)
47
+ data, options = incoming
48
+ elsif incoming.instance_of?(Hash)
49
+ data = @obj
50
+ options = incoming
51
+ else
52
+ data = incoming
53
+ end
54
+ else
55
+ data = @obj
56
+ end
57
+ result = {
58
+ success: true,
59
+ data: serialize(data, options)
60
+ }
61
+ render json: result
62
+ end
63
+
64
+ def create
65
+ obj = nil
66
+ options = {}
67
+ if block_given?
68
+ incoming = yield
69
+ if incoming.instance_of?(Array)
70
+ obj, options = incoming
71
+ elsif incoming.instance_of?(Hash)
72
+ obj = @clazz.new(model_params)
73
+ options = incoming
74
+ else
75
+ obj = incoming
76
+ end
77
+ else
78
+ obj = @clazz.new(model_params)
79
+ end
80
+
81
+ if obj.save
82
+ result = {
83
+ success: true,
84
+ data: serialize(obj, options)
85
+ }
86
+ render json: result, status: :created
87
+ else
88
+ render json: {success: false, error: obj.errors.full_messages[0]}, status: 422
89
+ end
90
+ rescue StandardError => e
91
+ render json: {success: false, error: e.message}
92
+ end
93
+
94
+ def update
95
+ obj = nil
96
+ options = {}
97
+ if block_given?
98
+ incoming = yield
99
+ if incoming.instance_of?(Array)
100
+ obj, options = incoming
101
+ elsif incoming.instance_of?(Hash)
102
+ obj = set_object
103
+ options = incoming
104
+ else
105
+ obj = incoming
106
+ end
107
+ else
108
+ obj = set_object
109
+ end
110
+
111
+ if obj.update(model_params)
112
+ result = {
113
+ success: true,
114
+ data: serialize(obj, options)
115
+ }
116
+ render json: result
117
+ else
118
+ render json: {success: false, error: obj.errors.full_messages[0]}, status: 422
119
+ end
120
+ rescue StandardError => e
121
+ render json: {success: false, error: e.message}
122
+ end
123
+
124
+ private
125
+
126
+ def serialize(data, options = {})
127
+ ActiveModelSerializers::SerializableResource.new(data, options)
128
+ end
129
+
130
+ def set_clazz
131
+ @clazz = "Scf::Core::#{controller_name.classify}".constantize
132
+ end
133
+
134
+ def set_object
135
+ @obj = @clazz.find(params[:id])
136
+ end
137
+
138
+ # This class should be overridden by respective child controllers
139
+ def model_params; end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,35 @@
1
+ module Scf
2
+ module Core
3
+ module Pagination
4
+ extend ActiveSupport::Concern
5
+
6
+ def default_per_page
7
+ 25
8
+ end
9
+
10
+ def page_no
11
+ params[:page]&.to_i || 1
12
+ end
13
+
14
+ def per_page
15
+ params[:per_page]&.to_i || default_per_page
16
+ end
17
+
18
+ def paginate_offset
19
+ (page_no - 1) * per_page
20
+ end
21
+
22
+ def order_by
23
+ params.fetch(:order_by, :id)
24
+ end
25
+
26
+ def order_direction
27
+ params.fetch(:order_direction, :asc)
28
+ end
29
+
30
+ def paginate
31
+ ->(it) { it.limit(per_page).offset(paginate_offset).order("#{order_by}": order_direction) }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ module Scf
2
+ module Core
3
+ class ApplicationController < ActionController::API
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Scf
2
+ module Core
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module Scf
2
+ module Core
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: "from@example.com"
5
+ layout "mailer"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Scf
2
+ module Core
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ Sentry.init do |config|
2
+ config.dsn = 'https://67ed384c7ed38457afd8773c2cb39231@o4508856449105920.ingest.de.sentry.io/4508856451006544'
3
+ config.breadcrumbs_logger = [:active_support_logger, :http_logger]
4
+
5
+ # Add data like request headers and IP for users,
6
+ # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info
7
+ config.send_default_pii = true
8
+
9
+ # Set traces_sample_rate to 1.0 to capture 100%
10
+ # of transactions for tracing.
11
+ # We recommend adjusting this value in production.
12
+ config.traces_sample_rate = 1.0
13
+ # or
14
+ config.traces_sampler = lambda do |context|
15
+ true
16
+ end
17
+ # Set profiles_sample_rate to profile 100%
18
+ # of sampled transactions.
19
+ # We recommend adjusting this value in production.
20
+ config.profiles_sample_rate = 1.0
21
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Scf::Core::Engine.routes.draw do
2
+ end
@@ -0,0 +1,7 @@
1
+ local:
2
+ service: S3
3
+ endpoint: http://127.0.0.1:9000
4
+ access_key_id: minioadmin
5
+ secret_access_key: minioadmin
6
+ bucket: scf-core-bucket
7
+ force_path_style: true
@@ -0,0 +1,22 @@
1
+ module Scf
2
+ module Core
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Scf::Core
5
+ config.generators.api_only = true
6
+
7
+ config.generators do |g|
8
+ g.test_framework :rspec, routing_specs: false
9
+ g.fixture_replacement :factory_bot
10
+ g.factory_bot dir: "spec/factories"
11
+ end
12
+
13
+ initializer "scf_core.factories", after: "factory_bot.set_factory_paths" do
14
+ FactoryBot.definition_file_paths << File.expand_path("../../../spec/factories", __dir__) if defined?(FactoryBot)
15
+ end
16
+
17
+ initializer :append_migrations do |app|
18
+ app.config.paths["db/migrate"].concat(config.paths["db/migrate"].expanded) unless app.root.to_s.match(root.to_s + File::SEPARATOR)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module Scf
2
+ module Core
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
data/lib/scf/core.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "scf/core/version"
2
+ require "scf/core/engine"
3
+
4
+ module Scf
5
+ module Core
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :scf_core do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,311 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scf_core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Asrat
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-02-24 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: active_model_serializers
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.10'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.10'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ancestry
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.1'
40
+ - !ruby/object:Gem::Dependency
41
+ name: bcrypt
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.1'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: httparty
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.21'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.21'
68
+ - !ruby/object:Gem::Dependency
69
+ name: image_processing
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.12'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.12'
82
+ - !ruby/object:Gem::Dependency
83
+ name: jwt
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.7'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '2.7'
96
+ - !ruby/object:Gem::Dependency
97
+ name: noticed
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.6'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.6'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rails
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '7.1'
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '7.1'
124
+ - !ruby/object:Gem::Dependency
125
+ name: ransack
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
131
+ type: :runtime
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.0'
138
+ - !ruby/object:Gem::Dependency
139
+ name: database_cleaner-active_record
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '2.0'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '2.0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: factory_bot_rails
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '6.2'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '6.2'
166
+ - !ruby/object:Gem::Dependency
167
+ name: faker
168
+ requirement: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.0'
173
+ type: :development
174
+ prerelease: false
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '3.0'
180
+ - !ruby/object:Gem::Dependency
181
+ name: letter_opener
182
+ requirement: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '1.8'
187
+ type: :development
188
+ prerelease: false
189
+ version_requirements: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '1.8'
194
+ - !ruby/object:Gem::Dependency
195
+ name: rspec-rails
196
+ requirement: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '6.0'
201
+ type: :development
202
+ prerelease: false
203
+ version_requirements: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '6.0'
208
+ - !ruby/object:Gem::Dependency
209
+ name: rspec-retry
210
+ requirement: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '0.6'
215
+ type: :development
216
+ prerelease: false
217
+ version_requirements: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - "~>"
220
+ - !ruby/object:Gem::Version
221
+ version: '0.6'
222
+ - !ruby/object:Gem::Dependency
223
+ name: rubocop-rspec
224
+ requirement: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - "~>"
227
+ - !ruby/object:Gem::Version
228
+ version: '2.22'
229
+ type: :development
230
+ prerelease: false
231
+ version_requirements: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - "~>"
234
+ - !ruby/object:Gem::Version
235
+ version: '2.22'
236
+ - !ruby/object:Gem::Dependency
237
+ name: shoulda-matchers
238
+ requirement: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - "~>"
241
+ - !ruby/object:Gem::Version
242
+ version: '5.2'
243
+ type: :development
244
+ prerelease: false
245
+ version_requirements: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '5.2'
250
+ - !ruby/object:Gem::Dependency
251
+ name: simplecov
252
+ requirement: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - "~>"
255
+ - !ruby/object:Gem::Version
256
+ version: '0.22'
257
+ type: :development
258
+ prerelease: false
259
+ version_requirements: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - "~>"
262
+ - !ruby/object:Gem::Version
263
+ version: '0.22'
264
+ description: An engine which contains core models for Supply Chain Financing.
265
+ email:
266
+ - asratextras77@gmail.com
267
+ executables: []
268
+ extensions: []
269
+ extra_rdoc_files: []
270
+ files:
271
+ - MIT-LICENSE
272
+ - README.md
273
+ - Rakefile
274
+ - app/controllers/concerns/scf/core/common.rb
275
+ - app/controllers/concerns/scf/core/pagination.rb
276
+ - app/controllers/scf/core/application_controller.rb
277
+ - app/jobs/scf/core/application_job.rb
278
+ - app/mailers/scf/core/application_mailer.rb
279
+ - app/models/scf/core/application_record.rb
280
+ - config/initializers/sentry.rb
281
+ - config/routes.rb
282
+ - config/storage.yml
283
+ - lib/scf/core.rb
284
+ - lib/scf/core/engine.rb
285
+ - lib/scf/core/version.rb
286
+ - lib/tasks/scf/core_tasks.rake
287
+ homepage: https://www.mks.com
288
+ licenses:
289
+ - MIT
290
+ metadata:
291
+ homepage_uri: https://www.mks.com
292
+ source_code_uri: https://github.com
293
+ changelog_uri: https://github.com/
294
+ rdoc_options: []
295
+ require_paths:
296
+ - lib
297
+ required_ruby_version: !ruby/object:Gem::Requirement
298
+ requirements:
299
+ - - ">="
300
+ - !ruby/object:Gem::Version
301
+ version: '3.2'
302
+ required_rubygems_version: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ requirements: []
308
+ rubygems_version: 3.6.2
309
+ specification_version: 4
310
+ summary: An Engine for Supply Chain Financing
311
+ test_files: []