itg 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/intializers/mongoid.rb +1 -0
- data/config/mongoid.yml +110 -0
- data/lib/itg/itg_api_key_authenticatable.rb +36 -0
- data/lib/itg/itg_api_key_base.rb +45 -0
- data/lib/itg/itg_model_base.rb +16 -0
- data/lib/itg/itg_mongo_base.rb +109 -0
- data/lib/itg/itg_printable.rb +32 -0
- data/lib/itg/itg_response.rb +7 -0
- data/lib/itg/itg_sec.rb +37 -0
- data/lib/itg/version.rb +2 -2
- data/lib/itg.rb +8 -3
- metadata +11 -5
- data/lib/itg/model_base.rb +0 -14
- data/lib/itg/mongo_base.rb +0 -107
- data/lib/itg/printable.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afb1a619f9859827f857cc4558a198ae8d753e3f86df4bb0c308df46abecd107
|
4
|
+
data.tar.gz: 5969d0683fc63c024cc789f5e3a8fcf39cdb1238ad8b416cb1f1c5222f2839b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 636803d0bbf4672919fc52e95c0cac4c6d4390af1463e304bfe96889b1d6d2ac39516d71ed3492833d83e25c4aabba0412c5a21cb04f77cfdda9f480064e2e40
|
7
|
+
data.tar.gz: 1ba56414129bef246771f1b7d401a6a26563af8d6de49e456ba27220f936781ff2b718c0f86412d959295bc82bdc6763da873c6b7fb269aa4ea9aff386e5d9e9
|
@@ -0,0 +1 @@
|
|
1
|
+
Mongoid.load!("mongoid.yml")
|
data/config/mongoid.yml
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
<% unless Rails.env.production? %>
|
2
|
+
<% raise "[mongoid] Credentials missing! (mongodb, env: #{Rails.env})" if Rails.application.credentials.mongodb.nil? %>
|
3
|
+
<% raise "[mongoid] Credentials missing! (mongodb.md, env: #{Rails.env})" if Rails.application.credentials.mongodb.md.nil? %>
|
4
|
+
<% raise "[mongoid] Credentials missing! (mongodb.dd, env: #{Rails.env})" if Rails.application.credentials.mongodb.dd.nil? %>
|
5
|
+
<% raise "[mongoid] Credentials missing! (mongodb.itg, env: #{Rails.env})" if Rails.application.credentials.mongodb.itg.nil? %>
|
6
|
+
<% raise "[mongoid] Credentials missing! (mongodb.test, env: #{Rails.env})" if Rails.application.credentials.mongodb.test.nil? %>
|
7
|
+
<% raise "[mongoid] Credentials missing! (mongodb.staging, env: #{Rails.env})" if Rails.application.credentials.mongodb.staging.nil? %>
|
8
|
+
<% end %>
|
9
|
+
<%# unless Rails.env.production? %>
|
10
|
+
# <%# raise "[mongoid] Credentials missing! (mongodb, env: #{Rails.env})" if Rails.application.credentials.mongodb.nil? %>
|
11
|
+
# <%# raise "[mongoid] Credentials missing! (mongodb.dd, env: #{Rails.env})" if Rails.application.credentials.mongodb.dd.nil? %>
|
12
|
+
# <%# raise "[mongoid] Credentials missing! (mongodb.md, env: #{Rails.env})" if Rails.application.credentials.mongodb.md.nil? %>
|
13
|
+
<%# end %>
|
14
|
+
development:
|
15
|
+
clients:
|
16
|
+
default:
|
17
|
+
# local server
|
18
|
+
database: itg_backend_dev
|
19
|
+
hosts:
|
20
|
+
- localhost:27017
|
21
|
+
options:
|
22
|
+
server_selection_timeout: 1
|
23
|
+
# MongoDb Atlas server
|
24
|
+
# uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.main.user %>:<%#= Rails.application.credentials.mongodb.main.psw %>@<%#= Rails.application.credentials.mongodb.main.cluster %>.mongodb.net/itg_backend?retryWrites=true&w=majority
|
25
|
+
# options:
|
26
|
+
# server_selection_timeout: 5
|
27
|
+
udd:
|
28
|
+
# local server
|
29
|
+
database: itg_backend_dev
|
30
|
+
hosts:
|
31
|
+
- localhost:27017
|
32
|
+
options:
|
33
|
+
server_selection_timeout: 1
|
34
|
+
# MongoDb Atlas server
|
35
|
+
# uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.dd.user %>:<%#= Rails.application.credentials.mongodb.dd.psw %>@<%#= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
|
36
|
+
# options:
|
37
|
+
# server_selection_timeout: 5
|
38
|
+
|
39
|
+
itgmain:
|
40
|
+
database: itg_main_dev
|
41
|
+
hosts:
|
42
|
+
- localhost:27017
|
43
|
+
options:
|
44
|
+
read:
|
45
|
+
mode: :primary
|
46
|
+
max_pool_size: 1
|
47
|
+
|
48
|
+
options:
|
49
|
+
raise_not_found_error: false
|
50
|
+
|
51
|
+
test:
|
52
|
+
clients:
|
53
|
+
default:
|
54
|
+
database: itg_backend_test
|
55
|
+
hosts:
|
56
|
+
- localhost:27017
|
57
|
+
options:
|
58
|
+
read:
|
59
|
+
mode: :primary
|
60
|
+
max_pool_size: 1
|
61
|
+
udd:
|
62
|
+
# local server
|
63
|
+
database: itg_backend_dev
|
64
|
+
hosts:
|
65
|
+
- localhost:27017
|
66
|
+
options:
|
67
|
+
server_selection_timeout: 1
|
68
|
+
# MongoDb Atlas server
|
69
|
+
# uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.dd.user %>:<%#= Rails.application.credentials.mongodb.dd.psw %>@<%#= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
|
70
|
+
# options:
|
71
|
+
# server_selection_timeout: 5
|
72
|
+
|
73
|
+
itgmain:
|
74
|
+
database: itg_main_test
|
75
|
+
hosts:
|
76
|
+
- localhost:27017
|
77
|
+
options:
|
78
|
+
read:
|
79
|
+
mode: :primary
|
80
|
+
max_pool_size: 1
|
81
|
+
|
82
|
+
options:
|
83
|
+
raise_not_found_error: false
|
84
|
+
|
85
|
+
staging:
|
86
|
+
clients:
|
87
|
+
default:
|
88
|
+
# uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.main.user %>:<%#= Rails.application.credentials.mongodb.main.psw %>@<%#= Rails.application.credentials.mongodb.main.cluster %>.mongodb.net/itg_backend?retryWrites=true&w=majority
|
89
|
+
uri: mongodb+srv://<%= Rails.application.credentials.mongodb.md.user %>:<%= Rails.application.credentials.mongodb.md.psw %>@<%= Rails.application.credentials.mongodb.md.cluster %>.mongodb.net/md?retryWrites=true&w=majority
|
90
|
+
options:
|
91
|
+
udd:
|
92
|
+
uri: mongodb+srv://<%= Rails.application.credentials.mongodb.dd.user %>:<%= Rails.application.credentials.mongodb.dd.psw %>@<%= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
|
93
|
+
options:
|
94
|
+
options:
|
95
|
+
raise_not_found_error: false
|
96
|
+
|
97
|
+
production:
|
98
|
+
clients:
|
99
|
+
default:
|
100
|
+
# uri: mongodb+srv://<%#= Rails.application.credentials.mongodb.main.user %>:<%#= Rails.application.credentials.mongodb.main.psw %>@<%#= Rails.application.credentials.mongodb.main.cluster %>.mongodb.net/itg_backend?retryWrites=true&w=majority
|
101
|
+
uri: mongodb+srv://<%= Rails.application.credentials.mongodb.md.user %>:<%= Rails.application.credentials.mongodb.md.psw %>@<%= Rails.application.credentials.mongodb.md.cluster %>.mongodb.net/md?retryWrites=true&w=majority
|
102
|
+
options:
|
103
|
+
udd:
|
104
|
+
uri: mongodb+srv://<%= Rails.application.credentials.mongodb.dd.user %>:<%= Rails.application.credentials.mongodb.dd.psw %>@<%= Rails.application.credentials.mongodb.dd.cluster %>.mongodb.net/udd-main?retryWrites=true&w=majority
|
105
|
+
options:
|
106
|
+
itgmain:
|
107
|
+
uri: mongodb+srv://<%= Rails.application.credentials.mongodb.itg.user %>:<%= Rails.application.credentials.mongodb.itg.psw %>@<%= Rails.application.credentials.mongodb.itg.cluster %>.mongodb.net/itg-main?retryWrites=true&w=majority
|
108
|
+
options:
|
109
|
+
options:
|
110
|
+
raise_not_found_error: false
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Itg
|
4
|
+
# Api Key Authenticatable class
|
5
|
+
module ApiKeyAuthenticatable
|
6
|
+
include ActionController::HttpAuthentication::Basic::ControllerMethods
|
7
|
+
include ActionController::HttpAuthentication::Token::ControllerMethods
|
8
|
+
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
attr_reader :current_api_key
|
12
|
+
attr_reader :current_bearer
|
13
|
+
|
14
|
+
# Use this to raise an error and automatically respond with a 401 HTTP status
|
15
|
+
# code when API key authentication fails
|
16
|
+
def authenticate_with_api_key!
|
17
|
+
@current_bearer = authenticate_or_request_with_http_token(&method(:authenticator))
|
18
|
+
end
|
19
|
+
|
20
|
+
# Use this for optional API key authentication
|
21
|
+
def authenticate_with_api_key
|
22
|
+
@current_bearer = authenticate_with_http_token(&method(:authenticator))
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_writer :current_api_key
|
28
|
+
attr_writer :current_bearer
|
29
|
+
|
30
|
+
def authenticator(token, options)
|
31
|
+
@current_api_key = ApiKey.authenticate_by_token token
|
32
|
+
|
33
|
+
current_api_key&.bearer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ItgApiKeyBase module
|
4
|
+
module Itg
|
5
|
+
module ApiKeyBase
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
# include Itg::MongoBase
|
9
|
+
# include Itg::Sec
|
10
|
+
# include Mongoid::Fields
|
11
|
+
#
|
12
|
+
# field :bearer_id, type: Integer
|
13
|
+
# field :bearer_type, type: String
|
14
|
+
# field :token_digest, type: String
|
15
|
+
#
|
16
|
+
# index({ bearer_id: 1, bearer_type: 1}, { name: "bearer_id_type_index" })
|
17
|
+
# index({ token_digest: 1 }, { unique: true, name: "token_digest_index" })
|
18
|
+
|
19
|
+
included do
|
20
|
+
include Itg::MongoBase
|
21
|
+
include Itg::Sec
|
22
|
+
|
23
|
+
# field :bearer_id, type: Integer
|
24
|
+
# field :bearer_type, type: String
|
25
|
+
# field :token_digest, type: String
|
26
|
+
#
|
27
|
+
# index({ bearer_id: 1, bearer_type: 1}, { name: "bearer_id_type_index" })
|
28
|
+
# index({ token_digest: 1 }, { unique: true, name: "token_digest_index" })
|
29
|
+
|
30
|
+
# Virtual attribute for raw token value, allowing us to respond with the
|
31
|
+
# API key's non-hashed token value. but only directly after creation.
|
32
|
+
# attr_accessor :token
|
33
|
+
#
|
34
|
+
# belongs_to :bearer, polymorphic: true
|
35
|
+
|
36
|
+
# Add virtual token attribute to serializable attributes, and exclude
|
37
|
+
# the token's HMAC digest
|
38
|
+
def serializable_hash(options = nil)
|
39
|
+
h = super options.merge(except: 'token_digest')
|
40
|
+
h.merge! 'token' => token if token.present?
|
41
|
+
h
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Itg
|
2
|
+
module ModelBase
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# field :language_code, type: String, default: 'el'
|
7
|
+
#
|
8
|
+
# scope :published, -> { where(published: true)}
|
9
|
+
# # scope :in_context, -> (context) { where(context: context)}
|
10
|
+
# scope :in_context, -> (context) { where(context: /#{context}/)}
|
11
|
+
# scope :for_locale, -> { where(language_code: '*').or(language_code: I18n.locale) }
|
12
|
+
# scope :by_dt_desc, -> { order(updated_at: :desc)}
|
13
|
+
# scope :by_importance, -> { order(importance: :desc)}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Itg
|
2
|
+
module MongoBase
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
include Mongoid::Fields
|
9
|
+
include Itg::Printable
|
10
|
+
|
11
|
+
# def self.udd_item
|
12
|
+
# # puts '[Mongo::Base.udd_item] start...'
|
13
|
+
# unless @udd_item_data
|
14
|
+
# udd_item_name = "model_#{model_name.to_s.underscore}"
|
15
|
+
# @udd_item_data = Udd.get_item(udd_item_name)
|
16
|
+
# if @udd_item_data
|
17
|
+
# @flds = @udd_item_data[:items].map { |k, v| k unless v[:is_field] == false}.compact
|
18
|
+
# @flds_required = @udd_item_data[:items].map { |k, v| k if v[:required] == true }.compact
|
19
|
+
# @sample_pairs = @udd_item_data[:items].map { |k, v| [k, v[:sample_value]] if v[:sample_value] }.compact.to_h
|
20
|
+
# @flds_string = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'string' && v[:is_field] != false }.compact
|
21
|
+
# @flds_boolean = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'boolean' && v[:is_field] != false }.compact
|
22
|
+
# @flds_number = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'number' && v[:is_field] != false }.compact
|
23
|
+
# @flds_date = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'date' && v[:is_field] != false }.compact
|
24
|
+
# @flds_datetime = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'datetime' && v[:is_field] != false }.compact
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# @udd_item_data
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# def self.udd_add_to_model_class(item_arr)
|
31
|
+
# field_name = item_arr.first
|
32
|
+
# item = item_arr.last
|
33
|
+
# return if item[:kind] == 'reference'
|
34
|
+
# # TODO: How can I have access to label and shot it in the form?
|
35
|
+
# # field field_name.to_sym, type: item[:kind].classify.constantize, default: item[:default], label: item[:label]
|
36
|
+
#
|
37
|
+
# # TODO: why the Boolean is not recognised? I have included Mongoid::Fields....
|
38
|
+
# field_type = item[:kind] == 'boolean' ? Mongoid::Boolean : item[:kind].classify.constantize
|
39
|
+
# field field_name.to_sym, type: field_type, default: item[:default]
|
40
|
+
# # field field_name.to_sym, type: Boolean, default: item[:default]
|
41
|
+
# if item[:required] == true
|
42
|
+
# if item[:validates_presence_msg]
|
43
|
+
# validates_presence_of field_name.to_sym, message: I18n.t(item[:validates_presence_msg])
|
44
|
+
# else
|
45
|
+
# validates_presence_of field_name.to_sym
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# validates_uniqueness_of field_name.to_sym if item[:unique] == true
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# def self.add_fields_to_model
|
52
|
+
# udd_item[:items].each(&method(:udd_add_to_model_class))
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# # cattr_reader :flds, :flds_required, :flds_string, :flds_boolean, :flds_number, :flds_date, :flds_datetime
|
56
|
+
# def self.flds
|
57
|
+
# udd_item
|
58
|
+
# @flds
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# def self.flds_required
|
62
|
+
# udd_item
|
63
|
+
# @flds_required
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# def self.sample_pairs
|
67
|
+
# udd_item
|
68
|
+
# @sample_pairs
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# def self.flds_string
|
72
|
+
# udd_item
|
73
|
+
# @flds_string
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# def self.flds_boolean
|
77
|
+
# udd_item
|
78
|
+
# @flds_boolean
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# def self.flds_number
|
82
|
+
# udd_item
|
83
|
+
# @flds_number
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# def self.flds_date
|
87
|
+
# udd_item
|
88
|
+
# @flds_date
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# def self.flds_datetime
|
92
|
+
# udd_item
|
93
|
+
# @flds_datetime
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# def to_s
|
97
|
+
# if (to_string_value = self.class.udd_item[:attrs][:to_string])
|
98
|
+
# if self.respond_to?(to_string_value)
|
99
|
+
# self.send(to_string_value)
|
100
|
+
# else
|
101
|
+
# raise "[Mongo::Base.to_s] there is no '#{to_string_value}' in '#{model_name}'"
|
102
|
+
# end
|
103
|
+
# else
|
104
|
+
# super
|
105
|
+
# end
|
106
|
+
# end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Printable concern class
|
4
|
+
module Itg
|
5
|
+
module Printable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
def itg_print(header: nil, prefix: '', allow_nested: true)
|
10
|
+
puts header if header
|
11
|
+
puts "#{prefix}print item....."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class_methods do
|
16
|
+
def itg_print_collection(items: nil, prefix: '', header: nil, nested: true)
|
17
|
+
items ||= all
|
18
|
+
header ||= name.pluralize
|
19
|
+
return unless items.count.positive?
|
20
|
+
|
21
|
+
puts "#{prefix}#{header} (#{items.count})"
|
22
|
+
items.each { |item| item.itg_print(prefix: prefix.gsub('-', ' '), allow_nested: nested) }
|
23
|
+
|
24
|
+
puts '' if nested && prefix.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def itg_print_db_info
|
28
|
+
puts "Database info: #{[collection_name, database_name, client_name].inspect}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/itg/itg_sec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Itg
|
4
|
+
# ItgSec concern class
|
5
|
+
module Sec
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
DB_NAME = begin
|
9
|
+
if Rails.env.production?
|
10
|
+
"itgsec"
|
11
|
+
else
|
12
|
+
"itgsecdev"
|
13
|
+
end
|
14
|
+
rescue StandardError
|
15
|
+
# Used only because the gem does not have the Rails initialized!
|
16
|
+
"itgsecdev"
|
17
|
+
end
|
18
|
+
CLIENT_NAME = "itgmain"
|
19
|
+
|
20
|
+
included do
|
21
|
+
begin
|
22
|
+
puts ">>>>>> itg_sec - include it....."
|
23
|
+
unless Rails.env.test?
|
24
|
+
store_in database: DB_NAME, client: CLIENT_NAME
|
25
|
+
puts "[itg_sec] set db details: #{DB_NAME}, #{CLIENT_NAME}"
|
26
|
+
end
|
27
|
+
self.itg_print_db_info
|
28
|
+
rescue NameError => e
|
29
|
+
# Ignored - Used only because the gem does not have the Rails initialized!
|
30
|
+
raise if e.message != "uninitialized constant Itg::Sec::Rails"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class_methods do
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/itg/version.rb
CHANGED
data/lib/itg.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "itg/version"
|
4
|
-
require_relative "itg/
|
5
|
-
require_relative "itg/
|
6
|
-
require_relative "itg/
|
4
|
+
require_relative "itg/itg_model_base"
|
5
|
+
require_relative "itg/itg_mongo_base"
|
6
|
+
require_relative "itg/itg_printable"
|
7
|
+
# require_relative "itg/itg_sec"
|
8
|
+
require_relative "itg/itg_api_key_base"
|
9
|
+
require_relative "itg/itg_api_key_authenticatable"
|
10
|
+
require_relative "itg/itg_response"
|
11
|
+
require_relative "itg/itg_sec"
|
7
12
|
|
8
13
|
module Itg
|
9
14
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aAon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -25,11 +25,17 @@ files:
|
|
25
25
|
- LICENSE.txt
|
26
26
|
- README.md
|
27
27
|
- Rakefile
|
28
|
+
- config/intializers/mongoid.rb
|
29
|
+
- config/mongoid.yml
|
28
30
|
- itg.gemspec
|
29
31
|
- lib/itg.rb
|
30
|
-
- lib/itg/
|
31
|
-
- lib/itg/
|
32
|
-
- lib/itg/
|
32
|
+
- lib/itg/itg_api_key_authenticatable.rb
|
33
|
+
- lib/itg/itg_api_key_base.rb
|
34
|
+
- lib/itg/itg_model_base.rb
|
35
|
+
- lib/itg/itg_mongo_base.rb
|
36
|
+
- lib/itg/itg_printable.rb
|
37
|
+
- lib/itg/itg_response.rb
|
38
|
+
- lib/itg/itg_sec.rb
|
33
39
|
- lib/itg/version.rb
|
34
40
|
- sig/itg.rbs
|
35
41
|
homepage: https://aaon.aggate.gr
|
data/lib/itg/model_base.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module ModelBase
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
# field :language_code, type: String, default: 'el'
|
6
|
-
#
|
7
|
-
# scope :published, -> { where(published: true)}
|
8
|
-
# # scope :in_context, -> (context) { where(context: context)}
|
9
|
-
# scope :in_context, -> (context) { where(context: /#{context}/)}
|
10
|
-
# scope :for_locale, -> { where(language_code: '*').or(language_code: I18n.locale) }
|
11
|
-
# scope :by_dt_desc, -> { order(updated_at: :desc)}
|
12
|
-
# scope :by_importance, -> { order(importance: :desc)}
|
13
|
-
end
|
14
|
-
end
|
data/lib/itg/mongo_base.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
module MongoBase
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
include Mongoid::Document
|
6
|
-
include Mongoid::Timestamps
|
7
|
-
include Mongoid::Fields
|
8
|
-
include Printable
|
9
|
-
|
10
|
-
# def self.udd_item
|
11
|
-
# # puts '[Mongo::Base.udd_item] start...'
|
12
|
-
# unless @udd_item_data
|
13
|
-
# udd_item_name = "model_#{model_name.to_s.underscore}"
|
14
|
-
# @udd_item_data = Udd.get_item(udd_item_name)
|
15
|
-
# if @udd_item_data
|
16
|
-
# @flds = @udd_item_data[:items].map { |k, v| k unless v[:is_field] == false}.compact
|
17
|
-
# @flds_required = @udd_item_data[:items].map { |k, v| k if v[:required] == true }.compact
|
18
|
-
# @sample_pairs = @udd_item_data[:items].map { |k, v| [k, v[:sample_value]] if v[:sample_value] }.compact.to_h
|
19
|
-
# @flds_string = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'string' && v[:is_field] != false }.compact
|
20
|
-
# @flds_boolean = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'boolean' && v[:is_field] != false }.compact
|
21
|
-
# @flds_number = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'number' && v[:is_field] != false }.compact
|
22
|
-
# @flds_date = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'date' && v[:is_field] != false }.compact
|
23
|
-
# @flds_datetime = @udd_item_data[:items].map { |k, v| k if v[:kind] == 'datetime' && v[:is_field] != false }.compact
|
24
|
-
# end
|
25
|
-
# end
|
26
|
-
# @udd_item_data
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# def self.udd_add_to_model_class(item_arr)
|
30
|
-
# field_name = item_arr.first
|
31
|
-
# item = item_arr.last
|
32
|
-
# return if item[:kind] == 'reference'
|
33
|
-
# # TODO: How can I have access to label and shot it in the form?
|
34
|
-
# # field field_name.to_sym, type: item[:kind].classify.constantize, default: item[:default], label: item[:label]
|
35
|
-
#
|
36
|
-
# # TODO: why the Boolean is not recognised? I have included Mongoid::Fields....
|
37
|
-
# field_type = item[:kind] == 'boolean' ? Mongoid::Boolean : item[:kind].classify.constantize
|
38
|
-
# field field_name.to_sym, type: field_type, default: item[:default]
|
39
|
-
# # field field_name.to_sym, type: Boolean, default: item[:default]
|
40
|
-
# if item[:required] == true
|
41
|
-
# if item[:validates_presence_msg]
|
42
|
-
# validates_presence_of field_name.to_sym, message: I18n.t(item[:validates_presence_msg])
|
43
|
-
# else
|
44
|
-
# validates_presence_of field_name.to_sym
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
# validates_uniqueness_of field_name.to_sym if item[:unique] == true
|
48
|
-
# end
|
49
|
-
#
|
50
|
-
# def self.add_fields_to_model
|
51
|
-
# udd_item[:items].each(&method(:udd_add_to_model_class))
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# # cattr_reader :flds, :flds_required, :flds_string, :flds_boolean, :flds_number, :flds_date, :flds_datetime
|
55
|
-
# def self.flds
|
56
|
-
# udd_item
|
57
|
-
# @flds
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# def self.flds_required
|
61
|
-
# udd_item
|
62
|
-
# @flds_required
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# def self.sample_pairs
|
66
|
-
# udd_item
|
67
|
-
# @sample_pairs
|
68
|
-
# end
|
69
|
-
#
|
70
|
-
# def self.flds_string
|
71
|
-
# udd_item
|
72
|
-
# @flds_string
|
73
|
-
# end
|
74
|
-
#
|
75
|
-
# def self.flds_boolean
|
76
|
-
# udd_item
|
77
|
-
# @flds_boolean
|
78
|
-
# end
|
79
|
-
#
|
80
|
-
# def self.flds_number
|
81
|
-
# udd_item
|
82
|
-
# @flds_number
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
# def self.flds_date
|
86
|
-
# udd_item
|
87
|
-
# @flds_date
|
88
|
-
# end
|
89
|
-
#
|
90
|
-
# def self.flds_datetime
|
91
|
-
# udd_item
|
92
|
-
# @flds_datetime
|
93
|
-
# end
|
94
|
-
#
|
95
|
-
# def to_s
|
96
|
-
# if (to_string_value = self.class.udd_item[:attrs][:to_string])
|
97
|
-
# if self.respond_to?(to_string_value)
|
98
|
-
# self.send(to_string_value)
|
99
|
-
# else
|
100
|
-
# raise "[Mongo::Base.to_s] there is no '#{to_string_value}' in '#{model_name}'"
|
101
|
-
# end
|
102
|
-
# else
|
103
|
-
# super
|
104
|
-
# end
|
105
|
-
# end
|
106
|
-
end
|
107
|
-
end
|
data/lib/itg/printable.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Printable concern class
|
4
|
-
module Printable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
def itg_print(header: nil, prefix: '', allow_nested: true)
|
9
|
-
puts header if header
|
10
|
-
puts "#{prefix}print item....."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class_methods do
|
15
|
-
def itg_print_collection(items: nil, prefix: '', header: nil, nested: true)
|
16
|
-
items ||= all
|
17
|
-
header ||= name.pluralize
|
18
|
-
return unless items.count.positive?
|
19
|
-
|
20
|
-
puts "#{prefix}#{header} (#{items.count})"
|
21
|
-
items.each { |item| item.itg_print(prefix: prefix.gsub('-', ' '), allow_nested: nested) }
|
22
|
-
|
23
|
-
puts '' if nested && prefix.empty?
|
24
|
-
end
|
25
|
-
|
26
|
-
def itg_print_db_info
|
27
|
-
puts "Database info: #{[collection_name, database_name, client_name].inspect}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|