mrpin-sdk 1.0.35 → 1.0.36
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 +4 -4
- data/lib/mrpin/all_files.rb +6 -6
- data/lib/mrpin/api/platform/report/handler_report_error.rb +6 -7
- data/lib/mrpin/config/initializers.rb +2 -2
- data/lib/mrpin/controllers/system_controller_base.rb +4 -3
- data/lib/mrpin/core/app_info/app_info_base.rb +0 -9
- data/lib/mrpin/core/base/model_base.rb +5 -4
- data/lib/mrpin/core/bundles/bundle_base.rb +14 -22
- data/lib/mrpin/core/constants/constants_remote.rb +11 -0
- data/lib/mrpin/core/remote/socket/websocket/manager_remote_web_sockets.rb +28 -3
- data/lib/mrpin/core/statistic/error_client_base.rb +6 -6
- data/lib/mrpin/core/uploaders/carrierwave/base/file_uploader_helpers_base.rb +15 -12
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_local.rb +41 -41
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_s3.rb +10 -16
- data/lib/mrpin/core/utils/utils_admin.rb +22 -0
- data/lib/mrpin/core/utils/utils_io.rb +25 -16
- data/lib/mrpin/core/utils/utils_url.rb +37 -0
- data/lib/mrpin/core/with_json/manager_with_json_data.rb +29 -20
- data/mrpin-sdk.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f805b31680bb18b542ea039773dfddc3568f6538
|
4
|
+
data.tar.gz: b541f32b158b63fee08cd0dce3eb8c6cd177f45a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77c97d8806f5933b3ae1dd9fcca4b4829d39b67a498c025ca18c7e0aa2e19fa1fb775d6f7ae8962de36ba6ae03ca3f1e666a95b112c316de05388cc144651f59
|
7
|
+
data.tar.gz: e0f6b9f43a729cf665026420605a0cc1b6a83abd25f61aecc4619883837a0d287978a7f5717982a88ea4bea8e12b5ce197c691508d1f224dee7c6450a8783527
|
data/lib/mrpin/all_files.rb
CHANGED
@@ -15,9 +15,9 @@ require_at_first_dirs =
|
|
15
15
|
)
|
16
16
|
|
17
17
|
require_at_first_dirs.each do |path|
|
18
|
-
|
18
|
+
path_absolute = File.join(File.dirname(__FILE__), path, '**/*.rb')
|
19
19
|
|
20
|
-
Dir[
|
20
|
+
Dir[path_absolute].each do |file|
|
21
21
|
require file
|
22
22
|
end
|
23
23
|
end
|
@@ -42,15 +42,15 @@ dirs_ignore =
|
|
42
42
|
)
|
43
43
|
|
44
44
|
dirs_ignore.each do |dir|
|
45
|
-
|
45
|
+
path_absolute = File.join(File.dirname(__FILE__), dir, '**/*.rb')
|
46
46
|
|
47
|
-
files_ignore += Dir[
|
47
|
+
files_ignore += Dir[path_absolute]
|
48
48
|
end
|
49
49
|
|
50
50
|
dirs.each do |dir|
|
51
|
-
|
51
|
+
path_absolute = File.join(File.dirname(__FILE__), dir, '**/*.rb')
|
52
52
|
|
53
|
-
files = Dir[
|
53
|
+
files = Dir[path_absolute]
|
54
54
|
|
55
55
|
files -= files_ignore
|
56
56
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module Api
|
2
|
+
#todo:review and implement
|
2
3
|
class HandlerReportError < HandlerBase
|
3
4
|
|
4
5
|
#
|
@@ -13,8 +14,6 @@ module Api
|
|
13
14
|
def initialize(options = nil)
|
14
15
|
super(options)
|
15
16
|
|
16
|
-
@aws_uploader = AppInfo.instance.aws_uploader
|
17
|
-
|
18
17
|
end
|
19
18
|
|
20
19
|
public
|
@@ -51,11 +50,11 @@ module Api
|
|
51
50
|
|
52
51
|
s3_key = File.join(file_path, file_name)
|
53
52
|
|
54
|
-
file_info = @aws_uploader.upload_data_to_s3(player_logs, bucket_name, s3_key)
|
55
|
-
|
56
|
-
error.logs_files << file_info.url_s3
|
57
|
-
|
58
|
-
error.logs_to_save_left = error.logs_to_save_left - 1
|
53
|
+
# file_info = @aws_uploader.upload_data_to_s3(player_logs, bucket_name, s3_key)
|
54
|
+
#
|
55
|
+
# error.logs_files << file_info.url_s3
|
56
|
+
#
|
57
|
+
# error.logs_to_save_left = error.logs_to_save_left - 1
|
59
58
|
end
|
60
59
|
|
61
60
|
player_errors_count = error.players_ids_map[player_id] || 0
|
@@ -179,9 +179,10 @@ class SystemControllerBase < ApplicationControllerBase
|
|
179
179
|
|
180
180
|
private
|
181
181
|
def authenticated_url(key, bucket_name, expires_in = 1.hour)
|
182
|
-
|
183
|
-
|
184
|
-
object
|
182
|
+
#todo:review
|
183
|
+
# s3 = AppInfo.instance.aws_uploader.s3
|
184
|
+
# object = s3.buckets[bucket_name].objects[key]
|
185
|
+
# object.url_for(:read, expires_in: expires_in).to_s
|
185
186
|
end
|
186
187
|
|
187
188
|
public
|
@@ -14,8 +14,6 @@ class AppInfoBase
|
|
14
14
|
|
15
15
|
attr_reader :managers_bundles_map
|
16
16
|
|
17
|
-
attr_reader :aws_uploader
|
18
|
-
|
19
17
|
attr_reader :boot_time
|
20
18
|
|
21
19
|
attr_reader :config
|
@@ -94,11 +92,6 @@ class AppInfoBase
|
|
94
92
|
result
|
95
93
|
end
|
96
94
|
|
97
|
-
public
|
98
|
-
def data_location
|
99
|
-
'/data/assets_dynamic'
|
100
|
-
end
|
101
|
-
|
102
95
|
public
|
103
96
|
def is_server_on_maintenance?
|
104
97
|
@state == EAppState::EAS_MAINTENANCE
|
@@ -192,8 +185,6 @@ class AppInfoBase
|
|
192
185
|
def initialize(options = nil)
|
193
186
|
init_logger
|
194
187
|
|
195
|
-
@aws_uploader = AWSUploader.new
|
196
|
-
|
197
188
|
begin
|
198
189
|
|
199
190
|
self.state = EAppState::EAS_INIT_CONFIG
|
@@ -39,7 +39,7 @@ class ModelBase
|
|
39
39
|
context.configure field_name
|
40
40
|
else
|
41
41
|
case field_name
|
42
|
-
when :_type
|
42
|
+
when :_type, /\Auploader_/
|
43
43
|
context.configure field_name do
|
44
44
|
visible false
|
45
45
|
end
|
@@ -50,11 +50,12 @@ class ModelBase
|
|
50
50
|
end
|
51
51
|
read_only true
|
52
52
|
end
|
53
|
-
|
54
53
|
when /\Aurl_/
|
55
54
|
context.configure field_name do
|
56
55
|
pretty_value do
|
57
|
-
|
56
|
+
unless value.nil?
|
57
|
+
UtilsAdmin.tag_img(bindings[:view], value, 25, 25)
|
58
|
+
end
|
58
59
|
end
|
59
60
|
end
|
60
61
|
else
|
@@ -96,7 +97,7 @@ class ModelBase
|
|
96
97
|
when /\Aurl_/
|
97
98
|
context.configure field_name do
|
98
99
|
pretty_value do
|
99
|
-
|
100
|
+
UtilsAdmin.tag_img(bindings[:view], value, 100, 100)
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
@@ -5,22 +5,16 @@ class BundleBase < ModelBase
|
|
5
5
|
|
6
6
|
include Mongoid::Timestamps
|
7
7
|
|
8
|
-
|
9
|
-
include FileUploaderHelpersS3
|
10
|
-
else
|
11
|
-
include FileUploaderHelpersLocal
|
12
|
-
end
|
13
|
-
|
8
|
+
include FileUploaderHelpersLocal
|
14
9
|
|
15
10
|
#
|
16
11
|
# admin
|
17
12
|
#
|
18
13
|
|
19
|
-
|
20
14
|
public
|
21
15
|
def self.configure_admin_list(section, field_name)
|
22
16
|
case field_name
|
23
|
-
when :
|
17
|
+
when :_id, :url, :created_at
|
24
18
|
section.configure field_name do
|
25
19
|
visible false
|
26
20
|
end
|
@@ -31,9 +25,7 @@ class BundleBase < ModelBase
|
|
31
25
|
|
32
26
|
public
|
33
27
|
def self.configure_admin_edit(section, field_name)
|
34
|
-
|
35
28
|
case field_name
|
36
|
-
|
37
29
|
when :build_type
|
38
30
|
section.configure field_name, :enum do
|
39
31
|
enum(EBuildType.values_list)
|
@@ -83,23 +75,11 @@ class BundleBase < ModelBase
|
|
83
75
|
# Properties
|
84
76
|
#
|
85
77
|
|
86
|
-
private
|
87
|
-
def url_uploaders_map
|
88
|
-
{
|
89
|
-
:url => :uploader_bundle
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
78
|
private
|
94
79
|
def class_info
|
95
80
|
BundleInfoBase
|
96
81
|
end
|
97
82
|
|
98
|
-
private
|
99
|
-
def upload_file_path(url_field)
|
100
|
-
"bundles/#{self.build_type}"
|
101
|
-
end
|
102
|
-
|
103
83
|
#
|
104
84
|
# Methods
|
105
85
|
#
|
@@ -146,6 +126,18 @@ class BundleBase < ModelBase
|
|
146
126
|
public
|
147
127
|
mount_uploader :uploader_bundle, FileUploader
|
148
128
|
|
129
|
+
protected
|
130
|
+
def get_path_for_uploader_relative(field_name)
|
131
|
+
"bundles/#{self.build_type}/#{self.name}"
|
132
|
+
end
|
133
|
+
|
134
|
+
protected
|
135
|
+
def url_uploaders_map
|
136
|
+
{
|
137
|
+
:url => :uploader_bundle
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
149
141
|
#
|
150
142
|
# scopes
|
151
143
|
#
|
@@ -11,4 +11,15 @@ class Constants
|
|
11
11
|
|
12
12
|
THREADS_HANDLERS_COUNT = Rails.env.production? ? 10 : 2
|
13
13
|
|
14
|
+
public
|
15
|
+
def self.get_dir_assets_dynamic
|
16
|
+
result = '/data/assets_dynamic'
|
17
|
+
|
18
|
+
if Rails.env.development?
|
19
|
+
result = File.join(Rails.root.to_s, 'public', result)
|
20
|
+
end
|
21
|
+
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
14
25
|
end
|
@@ -25,15 +25,40 @@ class ManagerRemoteWebSockets < ManagerRemoteSocketBase
|
|
25
25
|
|
26
26
|
public
|
27
27
|
def start!(callback = nil)
|
28
|
+
start_server_websocket(callback)
|
29
|
+
start_server_websocket_secure(nil)
|
28
30
|
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def start_server_websocket(callback)
|
36
|
+
@port = Constants::REMOTE_PORT_WEBSOCKET
|
37
|
+
start_server(@port, nil, callback)
|
38
|
+
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
def start_server_websocket_secure(callback)
|
29
44
|
path_private_key = ENV['SERVER_PRIVATE_KEY']
|
30
45
|
path_certificate = ENV['SERVER_CERTIFICATE']
|
31
46
|
|
32
|
-
|
47
|
+
can_start_server = true
|
33
48
|
|
34
|
-
|
49
|
+
if path_private_key.nil?
|
50
|
+
can_start_server = false
|
51
|
+
else
|
52
|
+
can_start_server = can_start_server && File.exist?(path_private_key)
|
53
|
+
end
|
54
|
+
|
55
|
+
if path_certificate.nil?
|
56
|
+
can_start_server = false
|
57
|
+
else
|
58
|
+
can_start_server = can_start_server && File.exist?(path_certificate)
|
59
|
+
end
|
35
60
|
|
36
|
-
if
|
61
|
+
if can_start_server
|
37
62
|
tls_options =
|
38
63
|
{
|
39
64
|
private_key_file: path_private_key,
|
@@ -125,12 +125,12 @@ class ErrorClientBase < ModelBase
|
|
125
125
|
|
126
126
|
private
|
127
127
|
def cleanup_logs
|
128
|
-
|
129
|
-
aws_uploader = AppInfo.instance.aws_uploader
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
128
|
+
#todo:review
|
129
|
+
# aws_uploader = AppInfo.instance.aws_uploader
|
130
|
+
#
|
131
|
+
# self.logs_files.each do |url_log_file|
|
132
|
+
# aws_uploader.delete_file_from_s3_by_uri(nil, url_log_file)
|
133
|
+
# end
|
134
134
|
end
|
135
135
|
|
136
136
|
end
|
@@ -27,14 +27,14 @@ module FileUploaderHelpersBase
|
|
27
27
|
protected
|
28
28
|
def delete_uploaded_files_if_error
|
29
29
|
if self.new_record? && !errors.empty?
|
30
|
-
|
31
30
|
delete_uploaded_files
|
32
31
|
|
33
|
-
url_uploaders_map.each_key do |
|
34
|
-
self.send("#{
|
32
|
+
url_uploaders_map.each_key do |field_name|
|
33
|
+
self.send("#{field_name}=", nil)
|
35
34
|
end
|
36
|
-
|
37
35
|
end
|
36
|
+
|
37
|
+
nil
|
38
38
|
end
|
39
39
|
|
40
40
|
#
|
@@ -42,10 +42,10 @@ module FileUploaderHelpersBase
|
|
42
42
|
#
|
43
43
|
|
44
44
|
protected
|
45
|
-
def get_upload_file_name(
|
46
|
-
result = "#{self.id.to_s}_#{
|
45
|
+
def get_upload_file_name(field_name, file_path)
|
46
|
+
result = "#{self.id.to_s}_#{field_name}_#{Time.now.to_i}"
|
47
47
|
|
48
|
-
extension = File.extname
|
48
|
+
extension = File.extname(file_path)
|
49
49
|
|
50
50
|
unless extension.nil?
|
51
51
|
result += extension.downcase
|
@@ -54,13 +54,16 @@ module FileUploaderHelpersBase
|
|
54
54
|
result
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
def
|
59
|
-
|
60
|
-
|
57
|
+
protected
|
58
|
+
def get_path_for_uploader_relative(field_name)
|
59
|
+
assert(false, 'Please override')
|
60
|
+
end
|
61
61
|
|
62
|
-
|
62
|
+
protected
|
63
|
+
def get_path_for_uploader_absolute(field_name)
|
63
64
|
end
|
64
65
|
|
65
66
|
|
67
|
+
|
68
|
+
|
66
69
|
end
|
@@ -14,6 +14,11 @@ module FileUploaderHelpersLocal
|
|
14
14
|
# properties
|
15
15
|
#
|
16
16
|
|
17
|
+
protected
|
18
|
+
def delete_uploaded_files_after_destroy?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
17
22
|
#
|
18
23
|
# methods
|
19
24
|
#
|
@@ -21,64 +26,62 @@ module FileUploaderHelpersLocal
|
|
21
26
|
# default constructor
|
22
27
|
protected
|
23
28
|
def try_update_uploaded_files
|
24
|
-
url_uploaders_map.each do |
|
29
|
+
self.url_uploaders_map.each do |field_name, uploader_field|
|
30
|
+
uploader_value = self.send(uploader_field)
|
25
31
|
|
26
|
-
|
32
|
+
return unless self.changed_attributes.keys.include?(uploader_field)
|
33
|
+
return unless uploader_value.present?
|
34
|
+
|
35
|
+
path_source = ''
|
27
36
|
|
28
37
|
begin
|
29
|
-
|
38
|
+
path_source = uploader_value.file.file.to_s
|
30
39
|
|
31
40
|
# delete old file if was uploaded
|
32
|
-
|
41
|
+
path_relative_old = self.send(field_name)
|
33
42
|
|
34
|
-
|
43
|
+
UtilsIO.try_remove_file_relative(path_relative_old)
|
35
44
|
|
36
|
-
|
37
|
-
path = upload_file_full_path(url_field)
|
38
|
-
name = get_upload_file_name(url_field, file_to_upload)
|
45
|
+
path_absolute = get_path_for_uploader_absolute(field_name)
|
39
46
|
|
40
|
-
|
47
|
+
# create required dirs
|
48
|
+
FileUtils.mkdir_p(path_absolute)
|
41
49
|
|
42
|
-
|
50
|
+
name = get_upload_file_name(field_name, path_source)
|
43
51
|
|
44
|
-
|
52
|
+
path_destination = File.join(path_absolute, name)
|
45
53
|
|
54
|
+
# upload new file
|
55
|
+
upload_file(field_name, path_source, path_destination)
|
46
56
|
rescue Exception => e
|
47
57
|
errors[:base] << e.to_s
|
48
58
|
ensure
|
49
|
-
|
50
|
-
|
51
|
-
FileUtils.rm_rf(file_path) if File.exists?(file_path)
|
59
|
+
File.delete(path_source) if File.exist?(path_source)
|
52
60
|
end
|
53
|
-
|
54
61
|
end
|
55
62
|
|
56
63
|
nil
|
57
64
|
end
|
58
65
|
|
59
|
-
|
60
|
-
def upload_file(
|
61
|
-
|
62
|
-
|
63
|
-
FileUtils.mkdir_p(file_dir)
|
66
|
+
protected
|
67
|
+
def upload_file(field_name, path_source, path_destination)
|
68
|
+
assert(!File.exist?(path_destination), "file #{path_destination} already exist")
|
64
69
|
|
65
|
-
FileUtils.copy(
|
70
|
+
FileUtils.copy(path_source, path_destination)
|
66
71
|
|
67
|
-
|
72
|
+
path_relative = UtilsIO.to_path_relative(path_destination)
|
68
73
|
|
69
|
-
self.send("#{
|
74
|
+
self.send("#{field_name}=", path_relative)
|
70
75
|
|
71
76
|
nil
|
72
77
|
end
|
73
78
|
|
74
79
|
|
75
80
|
protected
|
76
|
-
def get_upload_file_name(
|
77
|
-
|
81
|
+
def get_upload_file_name(field_name, file_path)
|
82
|
+
result = "#{field_name}_#{Time.now.to_i}"
|
78
83
|
|
79
|
-
|
80
|
-
|
81
|
-
extension = File.extname file_path
|
84
|
+
extension = File.extname(file_path)
|
82
85
|
|
83
86
|
unless extension.nil?
|
84
87
|
result += extension.downcase
|
@@ -88,24 +91,21 @@ module FileUploaderHelpersLocal
|
|
88
91
|
end
|
89
92
|
|
90
93
|
protected
|
91
|
-
def
|
92
|
-
|
93
|
-
url = self.send(url_field)
|
94
|
-
delete_file_local(url)
|
95
|
-
end
|
94
|
+
def get_path_for_uploader_absolute(field_name)
|
95
|
+
path_relative = get_path_for_uploader_relative(field_name)
|
96
96
|
|
97
|
-
|
97
|
+
UtilsIO.to_path_absolute(path_relative)
|
98
98
|
end
|
99
99
|
|
100
|
-
|
101
|
-
def
|
102
|
-
return
|
103
|
-
|
104
|
-
local_path = UtilsIO.to_local_path(url)
|
100
|
+
protected
|
101
|
+
def delete_uploaded_files
|
102
|
+
return unless delete_uploaded_files_after_destroy?
|
105
103
|
|
106
|
-
|
104
|
+
url_uploaders_map.each_key do |field_name|
|
105
|
+
path_relative = self.send(field_name)
|
106
|
+
UtilsIO.try_remove_file_relative(path_relative)
|
107
|
+
end
|
107
108
|
|
108
109
|
nil
|
109
110
|
end
|
110
|
-
|
111
111
|
end
|
@@ -15,26 +15,18 @@ module FileUploaderHelpersS3
|
|
15
15
|
#
|
16
16
|
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
protected
|
21
|
-
def upload_file_path(url_field)
|
22
|
-
assert(false, 'Please override')
|
23
|
-
end
|
24
|
-
|
25
18
|
private
|
26
19
|
def aws_uploader
|
27
20
|
@aws_uploader ||= AppInfo.instance.aws_uploader
|
28
21
|
end
|
29
22
|
|
30
|
-
|
31
23
|
#
|
32
24
|
# Methods
|
33
25
|
#
|
34
26
|
|
35
27
|
protected
|
36
28
|
def try_update_uploaded_files
|
37
|
-
url_uploaders_map.each do |
|
29
|
+
url_uploaders_map.each do |field_name, uploader_field|
|
38
30
|
|
39
31
|
next unless self.send(uploader_field).present?
|
40
32
|
|
@@ -42,19 +34,19 @@ module FileUploaderHelpersS3
|
|
42
34
|
file_to_upload = self.send(uploader_field).file.file.to_s
|
43
35
|
|
44
36
|
# delete old file if was uploaded
|
45
|
-
old_url = self.send(
|
37
|
+
old_url = self.send(field_name)
|
46
38
|
|
47
39
|
delete_file_from_s3(old_url)
|
48
40
|
|
49
41
|
# upload new file
|
50
|
-
path =
|
51
|
-
name = get_upload_file_name(
|
42
|
+
path = get_path_for_uploader_absolute(field_name)
|
43
|
+
name = get_upload_file_name(field_name, file_to_upload)
|
52
44
|
|
53
45
|
s3_key = File.join(path, name)
|
54
46
|
|
55
47
|
s3_file_info = aws_uploader.upload_file_to_s3(file_to_upload, AWSUploader::BUCKET_NAME_DEFAULT, s3_key)
|
56
48
|
|
57
|
-
self.send("#{
|
49
|
+
self.send("#{field_name}=", s3_file_info.url_cloud_front)
|
58
50
|
|
59
51
|
rescue Exception => e
|
60
52
|
errors[:base] << e.to_s
|
@@ -62,7 +54,7 @@ module FileUploaderHelpersS3
|
|
62
54
|
ensure
|
63
55
|
file_path = File.dirname(file_to_upload)
|
64
56
|
|
65
|
-
FileUtils.rm_rf(file_path) if File.
|
57
|
+
FileUtils.rm_rf(file_path) if File.exist?(file_path)
|
66
58
|
end
|
67
59
|
|
68
60
|
end
|
@@ -70,12 +62,14 @@ module FileUploaderHelpersS3
|
|
70
62
|
|
71
63
|
protected
|
72
64
|
def delete_uploaded_files
|
73
|
-
url_uploaders_map.each do |
|
74
|
-
url = self.send(
|
65
|
+
url_uploaders_map.each do |field_name, uploader_field|
|
66
|
+
url = self.send(field_name)
|
75
67
|
delete_file_from_s3(url)
|
76
68
|
end
|
77
69
|
end
|
78
70
|
|
71
|
+
|
72
|
+
|
79
73
|
private
|
80
74
|
def delete_file_from_s3(url)
|
81
75
|
unless url.nil? || url.blank?
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module UtilsAdmin
|
2
|
+
|
3
|
+
#
|
4
|
+
# properties
|
5
|
+
#
|
6
|
+
|
7
|
+
#
|
8
|
+
# methods
|
9
|
+
#
|
10
|
+
|
11
|
+
public
|
12
|
+
def self.tag_img(context, link, width, height)
|
13
|
+
return if link.nil? || link.blank?
|
14
|
+
|
15
|
+
link = UtilsURL.to_path_absolute(link)
|
16
|
+
|
17
|
+
context.link_to(context.tag(:img, {src: link, height: width, width: height}), link.html_safe, target: '_blank')
|
18
|
+
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -1,29 +1,38 @@
|
|
1
1
|
module UtilsIO
|
2
|
-
|
3
|
-
def self.
|
4
|
-
|
2
|
+
public
|
3
|
+
def self.to_path_relative(path_absolute)
|
4
|
+
if path_absolute.nil?
|
5
|
+
puts 'UtilsIO::to_path_relative arg is nil'
|
6
|
+
return ''
|
7
|
+
end
|
8
|
+
|
9
|
+
root_dir = Constants.get_dir_assets_dynamic
|
10
|
+
|
11
|
+
path_absolute.gsub(root_dir, '')
|
5
12
|
end
|
6
13
|
|
7
14
|
public
|
8
|
-
def self.
|
9
|
-
|
15
|
+
def self.to_path_absolute(path_relative)
|
16
|
+
if path_relative.nil?
|
17
|
+
puts 'UtilsIO::to_path_absolute arg is nil'
|
18
|
+
return ''
|
19
|
+
end
|
10
20
|
|
11
|
-
|
21
|
+
root_dir = Constants.get_dir_assets_dynamic
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
File.join(protocol, AppInfo.instance.host, file_path)
|
23
|
+
File.join(root_dir, path_relative)
|
16
24
|
end
|
17
25
|
|
18
26
|
public
|
19
|
-
def self.
|
20
|
-
|
27
|
+
def self.try_remove_file_relative(path_relative)
|
28
|
+
return if path_relative.blank?
|
29
|
+
|
30
|
+
path_absolute = UtilsIO.to_path_absolute(path_relative)
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
file_path = file_path.gsub('http://', '')
|
32
|
+
if File.exist?(path_absolute)
|
33
|
+
File.delete(path_absolute)
|
34
|
+
end
|
26
35
|
|
27
|
-
|
36
|
+
nil
|
28
37
|
end
|
29
38
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module UtilsURL
|
2
|
+
|
3
|
+
public
|
4
|
+
def self.to_path_absolute(path_relative)
|
5
|
+
result = ''
|
6
|
+
|
7
|
+
if path_relative.nil?
|
8
|
+
puts 'UtilsURL::to_path_absolute arg is nil'
|
9
|
+
return result
|
10
|
+
end
|
11
|
+
|
12
|
+
protocol = Rails.env.development? ? 'http://' : 'https://'
|
13
|
+
|
14
|
+
result = File.join(protocol, AppInfo.instance.host, path_relative)
|
15
|
+
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
public
|
20
|
+
def self.to_path_relative(path_absolute)
|
21
|
+
result = ''
|
22
|
+
|
23
|
+
if path_absolute.nil?
|
24
|
+
puts 'UtilsURL::to_path_relative arg is nil'
|
25
|
+
return result
|
26
|
+
end
|
27
|
+
|
28
|
+
result = path_absolute
|
29
|
+
|
30
|
+
result.gsub!(AppInfo.instance.host, '')
|
31
|
+
result.gsub!('https://', '')
|
32
|
+
result.gsub!('http://', '')
|
33
|
+
|
34
|
+
result
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -37,8 +37,6 @@ class ManagerWithJsonData < ManagerBase
|
|
37
37
|
def post_init
|
38
38
|
super
|
39
39
|
|
40
|
-
@root_dir = Rails.env.development? ? File.join(Rails.root.to_s, 'public') : AppInfo.instance.data_location
|
41
|
-
|
42
40
|
nil
|
43
41
|
end
|
44
42
|
|
@@ -51,16 +49,17 @@ class ManagerWithJsonData < ManagerBase
|
|
51
49
|
|
52
50
|
protected
|
53
51
|
def check_json_data_client
|
52
|
+
pattern_json = File.join(self.data_client_folder, '*.json')
|
53
|
+
pattern_json = UtilsIO.to_path_absolute(pattern_json)
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
data_client_path = File.join(@root_dir, self.data_client_folder, self.data_client_filename)
|
58
|
-
|
59
|
-
Dir[pattern_json].each do |file_path|
|
55
|
+
data_client_path = File.join(self.data_client_folder, self.data_client_filename)
|
56
|
+
data_client_path = UtilsIO.to_path_absolute(data_client_path)
|
60
57
|
|
61
|
-
|
58
|
+
Dir[pattern_json].each do |path_absolute|
|
59
|
+
if path_absolute.include?(data_client_path)
|
60
|
+
path_relative = UtilsIO.to_path_relative(path_absolute)
|
62
61
|
|
63
|
-
@url_client_data =
|
62
|
+
@url_client_data = UtilsURL.to_path_absolute(path_relative)
|
64
63
|
break
|
65
64
|
end
|
66
65
|
end
|
@@ -72,25 +71,35 @@ class ManagerWithJsonData < ManagerBase
|
|
72
71
|
|
73
72
|
public
|
74
73
|
def generate_client_json
|
75
|
-
|
76
|
-
file_path = UtilsIO.to_local_path(@url_client_data)
|
74
|
+
try_remove_json_old
|
77
75
|
|
78
|
-
|
79
|
-
|
76
|
+
content = self.get_json_data_client
|
77
|
+
|
78
|
+
path_absolute = UtilsIO.to_path_absolute(self.data_client_folder)
|
79
|
+
|
80
|
+
FileUtils.mkdir_p(path_absolute)
|
80
81
|
|
81
|
-
|
82
|
+
file_name = self.data_client_filename + '_' + Time.now.to_i.to_s + '.json'
|
82
83
|
|
83
|
-
|
84
|
+
path_absolute_with_name = File.join(path_absolute, file_name)
|
84
85
|
|
85
|
-
|
86
|
+
File.write(path_absolute_with_name, content)
|
86
87
|
|
87
|
-
|
88
|
+
path_relative_with_name = UtilsIO.to_path_relative(path_absolute_with_name)
|
88
89
|
|
89
|
-
|
90
|
+
@url_client_data = UtilsURL.to_path_absolute(path_relative_with_name)
|
91
|
+
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
|
95
|
+
protected
|
96
|
+
def try_remove_json_old
|
97
|
+
return if @url_client_data.nil?
|
90
98
|
|
91
|
-
|
99
|
+
path_relative = UtilsURL.to_path_relative(@url_client_data)
|
100
|
+
path_absolute = UtilsIO.to_path_absolute(path_relative)
|
92
101
|
|
93
|
-
|
102
|
+
File.delete(path_absolute) if File.exist?(path_absolute)
|
94
103
|
|
95
104
|
nil
|
96
105
|
end
|
data/mrpin-sdk.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'mrpin-sdk'
|
7
|
-
spec.version = '1.0.
|
7
|
+
spec.version = '1.0.36'
|
8
8
|
spec.authors = %w(Gregory Tkach Yakupov Dmitrij)
|
9
9
|
spec.email = %w(gregory.tkach@gmail.com yakupov.dmitrij@gmail.com)
|
10
10
|
spec.description = %q{Mrpin sdk for backend development.}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mrpin-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-04-
|
14
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -441,8 +441,10 @@ files:
|
|
441
441
|
- lib/mrpin/core/uploaders/carrierwave/zip_uploader.rb
|
442
442
|
- lib/mrpin/core/utils/mongo.rb
|
443
443
|
- lib/mrpin/core/utils/sorter_base.rb
|
444
|
+
- lib/mrpin/core/utils/utils_admin.rb
|
444
445
|
- lib/mrpin/core/utils/utils_io.rb
|
445
446
|
- lib/mrpin/core/utils/utils_string.rb
|
447
|
+
- lib/mrpin/core/utils/utils_url.rb
|
446
448
|
- lib/mrpin/core/utils/utils_zip.rb
|
447
449
|
- lib/mrpin/core/with_json/manager_with_json_data.rb
|
448
450
|
- lib/mrpin/libs.rb
|