mrpin-sdk 0.3.141 → 1.0.2
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/.gitignore +47 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/app/assets/stylesheets/mrpin/sign_in.css +32 -0
- data/app/assets/stylesheets/mrpin.css.scss +3 -0
- data/app/views/devise/sessions/new.html.erb +16 -0
- data/app/views/layouts/devise.html.erb +12 -0
- data/lib/mrpin/all_files.rb +48 -0
- data/lib/mrpin/api/base/api_object.rb +48 -0
- data/lib/mrpin/api/base/handler_base.rb +86 -0
- data/lib/mrpin/api/base/request_base.rb +15 -0
- data/lib/mrpin/api/base/response_base.rb +29 -0
- data/lib/mrpin/api/bundles/init/handler_bundles_init.rb +36 -0
- data/lib/mrpin/api/bundles/init/request_bundles_init.rb +7 -0
- data/lib/mrpin/api/bundles/init/response_bundles_init.rb +5 -0
- data/lib/mrpin/api/packs/requests_pack.rb +38 -0
- data/lib/mrpin/api/packs/responses_pack.rb +38 -0
- data/lib/mrpin/api/platform/base/handler_platform_base.rb +26 -0
- data/lib/mrpin/api/platform/base/request_platform_base.rb +54 -0
- data/lib/mrpin/api/platform/report/handler_report_error.rb +74 -0
- data/lib/mrpin/api/platform/report/request_report_error.rb +20 -0
- data/lib/mrpin/api/standard/response_error.rb +19 -0
- data/lib/mrpin/api/standard/response_ok.rb +18 -0
- data/lib/mrpin/api/standard/response_session_end.rb +21 -0
- data/lib/mrpin/api/standard/response_with_url_data.rb +7 -0
- data/lib/mrpin/api/system/echo/handler_system_echo.rb +25 -0
- data/lib/mrpin/api/system/echo/request_system_echo.rb +19 -0
- data/lib/mrpin/config/initializers/00_carrier_wave.rb +4 -0
- data/lib/mrpin/config/initializers/01_devise.rb +264 -0
- data/lib/mrpin/config/initializers/02_mongo.rb +2 -0
- data/lib/mrpin/config/initializers/03_i18n.rb +3 -0
- data/lib/mrpin/config/initializers.rb +7 -0
- data/lib/mrpin/config/locales/rails_admin.en.yml +10 -0
- data/lib/mrpin/controllers/application_controller_base.rb +14 -0
- data/lib/mrpin/controllers/system_controller_base.rb +222 -0
- data/lib/mrpin/core/admin/admin_user.rb +39 -0
- data/lib/mrpin/core/admin/e_admin_user_role.rb +4 -0
- data/lib/mrpin/core/app_config_base.rb +48 -0
- data/lib/mrpin/core/app_info/app_info_base.rb +413 -0
- data/lib/mrpin/core/app_info/e_app_state.rb +13 -0
- data/lib/mrpin/core/base/amf_serializable.rb +16 -0
- data/lib/mrpin/core/base/enum_base.rb +12 -0
- data/lib/mrpin/core/base/info_base.rb +18 -0
- data/lib/mrpin/core/base/manager_base.rb +74 -0
- data/lib/mrpin/core/base/manager_with_json_data.rb +98 -0
- data/lib/mrpin/core/base/model_base.rb +219 -0
- data/lib/mrpin/core/bundles/bundle_base.rb +197 -0
- data/lib/mrpin/core/bundles/bundle_info_base.rb +29 -0
- data/lib/mrpin/core/bundles/e_build_type.rb +7 -0
- data/lib/mrpin/core/bundles/manager_bundles_base.rb +56 -0
- data/lib/mrpin/core/constants/constants_remote.rb +14 -0
- data/lib/mrpin/core/currency_exchanger/base/exchanger_base.rb +21 -0
- data/lib/mrpin/core/currency_exchanger/currency_exchanger.rb +40 -0
- data/lib/mrpin/core/currency_exchanger/e_currency_type.rb +8 -0
- data/lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb +40 -0
- data/lib/mrpin/core/currency_exchanger/local/exchanger_local.rb +23 -0
- data/lib/mrpin/core/currency_exchanger/yahoo/exchanger_yahoo.rb +34 -0
- data/lib/mrpin/core/exceptions/assertion_error.rb +3 -0
- data/lib/mrpin/core/extensions/hash.rb +25 -0
- data/lib/mrpin/core/extensions/mongoid_id_alias.rb +7 -0
- data/lib/mrpin/core/extensions/object.rb +57 -0
- data/lib/mrpin/core/extensions/thread.rb +23 -0
- data/lib/mrpin/core/extensions/time.rb +5 -0
- data/lib/mrpin/core/logger/logger_sdk.rb +14 -0
- data/lib/mrpin/core/platform/e_platform_type.rb +14 -0
- data/lib/mrpin/core/player/e_player_role.rb +7 -0
- data/lib/mrpin/core/player/e_sex_type.rb +7 -0
- data/lib/mrpin/core/player/player_statistic_base.rb +50 -0
- data/lib/mrpin/core/purchase/e_sale_type.rb +7 -0
- data/lib/mrpin/core/remote/e_response_type.rb +4 -0
- data/lib/mrpin/core/remote/http/manager_remote_http.rb +107 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_api.rb +43 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_disconnect.rb +69 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_handle.rb +155 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_sessions.rb +41 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_statistic.rb +41 -0
- data/lib/mrpin/core/remote/socket/base/extensions/network_interface_helper.rb +53 -0
- data/lib/mrpin/core/remote/socket/base/manager_remote_socket_base.rb +131 -0
- data/lib/mrpin/core/remote/socket/base/socket_client_base.rb +181 -0
- data/lib/mrpin/core/remote/socket/base/socket_client_crossdomain.rb +33 -0
- data/lib/mrpin/core/remote/socket/flash/manager_remote_socket_flash.rb +51 -0
- data/lib/mrpin/core/remote/socket/flash/socket_client_flash.rb +21 -0
- data/lib/mrpin/core/remote/socket/unity/manager_remote_socket_unity.rb +58 -0
- data/lib/mrpin/core/remote/socket/unity/socket_client_unity.rb +19 -0
- data/lib/mrpin/core/remote/socket/websocket/manager_remote_web_sockets.rb +101 -0
- data/lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb +129 -0
- data/lib/mrpin/core/remote/socket/with_policy/socket_client_with_policy.rb +66 -0
- data/lib/mrpin/core/review.rb +231 -0
- data/lib/mrpin/core/scheduler/manager_scheduler.rb +66 -0
- data/lib/mrpin/core/statistic/error_client_base.rb +136 -0
- data/lib/mrpin/core/statistic/error_server_base.rb +93 -0
- data/lib/mrpin/core/statistic/manager_statistics_base.rb +221 -0
- data/lib/mrpin/core/statistic/statistic_application_base.rb +88 -0
- data/lib/mrpin/core/statistic/statistic_config_base.rb +38 -0
- data/lib/mrpin/core/statistic/system_handler_profiler.rb +85 -0
- data/lib/mrpin/core/string/e_language_type.rb +29 -0
- data/lib/mrpin/core/string/e_string_type_base.rb +14 -0
- data/lib/mrpin/core/string/localization_base.rb +77 -0
- data/lib/mrpin/core/string/localization_base_map.rb +303 -0
- data/lib/mrpin/core/string/manager_string_base.rb +159 -0
- data/lib/mrpin/core/threads/thread_with_task.rb +62 -0
- data/lib/mrpin/core/uploaders/aws/aws_file_info.rb +16 -0
- data/lib/mrpin/core/uploaders/aws/aws_uploader.rb +229 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader.rb +7 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_base.rb +66 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_local.rb +111 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_s3.rb +87 -0
- data/lib/mrpin/core/uploaders/carrierwave/zip_uploader.rb +10 -0
- data/lib/mrpin/core/utils/mongo.rb +41 -0
- data/lib/mrpin/core/utils/sorter_base.rb +344 -0
- data/lib/mrpin/core/utils/utils_io.rb +27 -0
- data/lib/mrpin/core/utils/utils_string.rb +17 -0
- data/lib/mrpin/core/utils/utils_zip.rb +58 -0
- data/lib/mrpin/libs/rails_admin/localization.rb +70 -0
- data/lib/mrpin/libs.rb +11 -0
- data/lib/mrpin/rails/engine.rb +11 -0
- data/lib/mrpin/vendors.rb +19 -0
- data/lib/mrpin/version.rb +3 -0
- data/lib/mrpin-sdk.rb +6 -0
- data/mrpin-sdk.gemspec +54 -0
- metadata +163 -96
@@ -0,0 +1,13 @@
|
|
1
|
+
class EAppState < EnumBase
|
2
|
+
|
3
|
+
EAS_INIT_MANAGERS = 'init_managers'
|
4
|
+
EAS_POST_INIT = 'post_init'
|
5
|
+
EAS_LOAD_INIT_DATA = 'load_init_data'
|
6
|
+
EAS_INIT_PERIODICAL_TASKS = 'init_periodical_tasks'
|
7
|
+
EAS_START_MANAGER_TASKS = 'start_manager_tasks'
|
8
|
+
EAS_START_REMOTE_SERVERS = 'start_remote_servers'
|
9
|
+
EAS_LAUNCH_COMPLETE = 'launch_complete'
|
10
|
+
EAS_MAINTENANCE = 'maintenance'
|
11
|
+
EAS_SHUTDOWN_STARTED = 'shutdown_started'
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class InfoBase
|
2
|
+
|
3
|
+
def self.attributes
|
4
|
+
if @attributes.nil?
|
5
|
+
@attributes = self.instance_methods.select { |method| method =~ /=$/ }
|
6
|
+
@attributes -= self.ignored_methods
|
7
|
+
@attributes.map! { |attribute| attribute.to_s.chop.to_sym } # delete last symbol '='
|
8
|
+
end
|
9
|
+
|
10
|
+
@attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.ignored_methods
|
14
|
+
[:===, :==, :!=]
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class ManagerBase
|
2
|
+
|
3
|
+
#
|
4
|
+
# Properties
|
5
|
+
#
|
6
|
+
|
7
|
+
#
|
8
|
+
# Events
|
9
|
+
#
|
10
|
+
|
11
|
+
public
|
12
|
+
def on_server_shutdown
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
# calls at fourth
|
17
|
+
public
|
18
|
+
def on_data_loaded
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
# calls at last
|
23
|
+
public
|
24
|
+
def on_server_started
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
public
|
29
|
+
def on_server_maintenance_on
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Methods
|
35
|
+
#
|
36
|
+
|
37
|
+
# calls at first
|
38
|
+
# default constructor
|
39
|
+
def initialize(options = nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
# calls at second
|
43
|
+
public
|
44
|
+
def post_init
|
45
|
+
@logger = AppInfo.instance.logger
|
46
|
+
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# calls at third
|
51
|
+
public
|
52
|
+
def load_init_data
|
53
|
+
invalidate_cache
|
54
|
+
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# calls at fifth
|
59
|
+
public
|
60
|
+
def start_tasks
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
# calls each N minutes
|
65
|
+
public
|
66
|
+
def invalidate_cache
|
67
|
+
end
|
68
|
+
|
69
|
+
# calls each N minutes
|
70
|
+
public
|
71
|
+
def cleanup_data
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class ManagerWithJsonData < ManagerBase
|
2
|
+
|
3
|
+
#
|
4
|
+
# properties
|
5
|
+
#
|
6
|
+
|
7
|
+
attr_reader :url_client_data
|
8
|
+
|
9
|
+
protected
|
10
|
+
def data_client_folder
|
11
|
+
assert(false, 'please override')
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def data_client_filename
|
16
|
+
'info'
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
def get_json_data_client
|
21
|
+
assert(false, 'please override')
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# methods
|
26
|
+
#
|
27
|
+
|
28
|
+
# default constructor
|
29
|
+
public
|
30
|
+
def initialize(options = nil)
|
31
|
+
super(options)
|
32
|
+
|
33
|
+
@url_client_data = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
public
|
37
|
+
def post_init
|
38
|
+
super
|
39
|
+
|
40
|
+
@root_dir = Rails.env.development? ? File.join(Rails.root.to_s, 'public') : "/usr/local/#{AppInfo.instance.server_name}"
|
41
|
+
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
public
|
46
|
+
def load_init_data
|
47
|
+
super
|
48
|
+
|
49
|
+
check_json_data_client
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
def check_json_data_client
|
54
|
+
|
55
|
+
pattern_json = File.join(@root_dir, self.data_client_folder, '*.json')
|
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|
|
60
|
+
|
61
|
+
if file_path.include?(data_client_path)
|
62
|
+
|
63
|
+
@url_client_data = UtilsIO.to_domain_path(file_path)
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
@logger.warn "not found any client json file for #{self.class}" if @url_client_data.nil?
|
69
|
+
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
|
73
|
+
public
|
74
|
+
def generate_client_json
|
75
|
+
unless @url_client_data.nil?
|
76
|
+
file_path = UtilsIO.to_local_path(@url_client_data)
|
77
|
+
|
78
|
+
File.delete(file_path) if File.exist?(file_path)
|
79
|
+
end
|
80
|
+
|
81
|
+
file_content_json = self.get_json_data_client
|
82
|
+
|
83
|
+
data_client_folder = File.join(@root_dir, self.data_client_folder)
|
84
|
+
|
85
|
+
FileUtils.mkdir_p(data_client_folder)
|
86
|
+
|
87
|
+
file_name = File.join(data_client_folder, self.data_client_filename)
|
88
|
+
|
89
|
+
file_name += '_' + Time.now.to_i.to_s + '.json'
|
90
|
+
|
91
|
+
File.write(file_name, file_content_json)
|
92
|
+
|
93
|
+
@url_client_data = UtilsIO.to_domain_path(file_name)
|
94
|
+
|
95
|
+
nil
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
#todo:review
|
2
|
+
class ModelBase
|
3
|
+
|
4
|
+
include AMFSerializable
|
5
|
+
|
6
|
+
#
|
7
|
+
# admin
|
8
|
+
#
|
9
|
+
|
10
|
+
#
|
11
|
+
# properties
|
12
|
+
#
|
13
|
+
|
14
|
+
public
|
15
|
+
def self.admin_group
|
16
|
+
self.name.underscore.split('_').first
|
17
|
+
end
|
18
|
+
|
19
|
+
public
|
20
|
+
def self.configure_admin_list(context, field_name)
|
21
|
+
model_class = get_class_by_name(context.abstract_model.model_name)
|
22
|
+
|
23
|
+
is_mongoid_field = false
|
24
|
+
is_mongoid_relation_field = false
|
25
|
+
|
26
|
+
if model_class.include?(Mongoid::Document)
|
27
|
+
if model_class.fields.include?(field_name.to_s)
|
28
|
+
is_mongoid_field = true
|
29
|
+
end
|
30
|
+
|
31
|
+
if model_class.relations.keys.include?(field_name.to_s)
|
32
|
+
is_mongoid_relation_field = true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if is_mongoid_field && model_class.fields[field_name.to_s].type == Mongoid::Boolean
|
37
|
+
context.configure field_name
|
38
|
+
elsif is_mongoid_relation_field
|
39
|
+
context.configure field_name
|
40
|
+
else
|
41
|
+
case field_name
|
42
|
+
when :_type
|
43
|
+
context.configure field_name do
|
44
|
+
visible false
|
45
|
+
end
|
46
|
+
when /_at\z/
|
47
|
+
context.configure field_name do
|
48
|
+
pretty_value do
|
49
|
+
Time.at(value).to_s(:short) unless value.nil?
|
50
|
+
end
|
51
|
+
read_only true
|
52
|
+
end
|
53
|
+
|
54
|
+
when /\Aurl_/
|
55
|
+
context.configure field_name do
|
56
|
+
pretty_value do
|
57
|
+
bindings[:view].link_to(bindings[:view].tag(:img, {src: value, height: 25, width: 25}), value.html_safe, target: '_blank') unless value.nil?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
else
|
61
|
+
context.configure field_name do
|
62
|
+
pretty_value { value }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
public
|
69
|
+
def self.configure_admin_edit(context, field_name)
|
70
|
+
case field_name
|
71
|
+
when :_type, :created_at, :updated_at
|
72
|
+
context.configure field_name do
|
73
|
+
visible false
|
74
|
+
end
|
75
|
+
else
|
76
|
+
context.configure field_name
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
public
|
81
|
+
def self.configure_admin_show(context, field_name)
|
82
|
+
case field_name
|
83
|
+
|
84
|
+
when :_type
|
85
|
+
context.configure field_name do
|
86
|
+
visible false
|
87
|
+
end
|
88
|
+
|
89
|
+
when /_at\z/
|
90
|
+
context.configure field_name do
|
91
|
+
pretty_value do
|
92
|
+
Time.at(value).to_s(:short)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
when /\Aurl_/
|
97
|
+
context.configure field_name do
|
98
|
+
pretty_value do
|
99
|
+
bindings[:view].link_to(bindings[:view].tag(:img, {src: value, height: 100, width: 100}), value.html_safe, target: '_blank') unless value.nil?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
else
|
104
|
+
context.configure field_name
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
public
|
109
|
+
def self.sort_by_for_admin_list(section)
|
110
|
+
section.sort_by :_id
|
111
|
+
end
|
112
|
+
|
113
|
+
public
|
114
|
+
def self.filters_for_admin_list(section)
|
115
|
+
section.filters []
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# scopes
|
120
|
+
#
|
121
|
+
|
122
|
+
public
|
123
|
+
def self.init_scopes
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
protected
|
128
|
+
def self.add_scope(scope_name, criteria)
|
129
|
+
scope scope_name.to_sym, -> { where(criteria) }
|
130
|
+
end
|
131
|
+
|
132
|
+
public
|
133
|
+
def self.need_show_for_admin_user?(user)
|
134
|
+
user.role == EAdminUserRole::EAUR_ADMIN
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Properties
|
139
|
+
#
|
140
|
+
|
141
|
+
protected
|
142
|
+
def class_info
|
143
|
+
@class_info = nil
|
144
|
+
end
|
145
|
+
|
146
|
+
#
|
147
|
+
# Methods
|
148
|
+
#
|
149
|
+
|
150
|
+
# default constructor
|
151
|
+
def initialize(options = nil)
|
152
|
+
super
|
153
|
+
end
|
154
|
+
|
155
|
+
public
|
156
|
+
def create_info
|
157
|
+
return nil if class_info.nil?
|
158
|
+
|
159
|
+
result = class_info.new
|
160
|
+
|
161
|
+
class_info.attributes.each do |attribute_name|
|
162
|
+
next unless self.respond_to? attribute_name
|
163
|
+
|
164
|
+
attribute_value = get_attribute_value(attribute_name)
|
165
|
+
|
166
|
+
result.send("#{attribute_name}=", attribute_value)
|
167
|
+
end
|
168
|
+
|
169
|
+
result
|
170
|
+
end
|
171
|
+
|
172
|
+
public
|
173
|
+
def create_info_with_check
|
174
|
+
return nil if class_info.nil?
|
175
|
+
|
176
|
+
result = class_info.new
|
177
|
+
|
178
|
+
class_info.attributes.each do |attribute_name|
|
179
|
+
if (self.respond_to?(attribute_name) && self.has_attribute?(attribute_name)) || attribute_name.to_s == 'id'
|
180
|
+
|
181
|
+
attribute_value = get_attribute_value(attribute_name)
|
182
|
+
|
183
|
+
result.send("#{attribute_name}=", attribute_value)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
result
|
188
|
+
end
|
189
|
+
|
190
|
+
protected
|
191
|
+
def get_attribute_value(attribute_name)
|
192
|
+
result = self.send(attribute_name)
|
193
|
+
|
194
|
+
if result.is_a? (Array)
|
195
|
+
result_array = []
|
196
|
+
|
197
|
+
result.each do |attribute_element|
|
198
|
+
if attribute_element.kind_of? (ModelBase)
|
199
|
+
result_array << attribute_element.create_info
|
200
|
+
else
|
201
|
+
result_array << attribute_element
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
result = result_array
|
206
|
+
|
207
|
+
elsif result.kind_of? (ModelBase)
|
208
|
+
result = result.create_info
|
209
|
+
end
|
210
|
+
|
211
|
+
result
|
212
|
+
end
|
213
|
+
|
214
|
+
public
|
215
|
+
def clone_model
|
216
|
+
self.class.new(self.as_json)
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
class BundleBase < ModelBase
|
2
|
+
|
3
|
+
include Mongoid::Document
|
4
|
+
prepend MongoidIdAlias
|
5
|
+
|
6
|
+
include Mongoid::Timestamps
|
7
|
+
|
8
|
+
if Rails.env.production?
|
9
|
+
include FileUploaderHelpersS3
|
10
|
+
else
|
11
|
+
include FileUploaderHelpersLocal
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
#
|
16
|
+
# admin
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
public
|
21
|
+
def self.configure_admin_list(section, field_name)
|
22
|
+
case field_name
|
23
|
+
when :uploader_bundle, :_id, :url, :created_at
|
24
|
+
section.configure field_name do
|
25
|
+
visible false
|
26
|
+
end
|
27
|
+
else
|
28
|
+
super(section, field_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
public
|
33
|
+
def self.configure_admin_edit(section, field_name)
|
34
|
+
|
35
|
+
case field_name
|
36
|
+
|
37
|
+
when :build_type
|
38
|
+
section.configure field_name, :enum do
|
39
|
+
enum(EBuildType.values_list)
|
40
|
+
end
|
41
|
+
when :version
|
42
|
+
section.configure field_name do
|
43
|
+
read_only true
|
44
|
+
end
|
45
|
+
when :url
|
46
|
+
section.configure field_name do
|
47
|
+
read_only true
|
48
|
+
help 'Required. Please upload file'
|
49
|
+
end
|
50
|
+
|
51
|
+
else
|
52
|
+
super(section, field_name)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# callbacks
|
58
|
+
#
|
59
|
+
|
60
|
+
after_validation :update_version
|
61
|
+
after_save :callback_after_save
|
62
|
+
|
63
|
+
#
|
64
|
+
# db
|
65
|
+
#
|
66
|
+
|
67
|
+
store_in collection: 'bundles'
|
68
|
+
|
69
|
+
#
|
70
|
+
# fields
|
71
|
+
#
|
72
|
+
|
73
|
+
field :build_type, type: String
|
74
|
+
field :name, type: String
|
75
|
+
field :url, type: String
|
76
|
+
|
77
|
+
field :version, type: Integer, default: 0
|
78
|
+
|
79
|
+
#
|
80
|
+
# add indexes
|
81
|
+
#
|
82
|
+
|
83
|
+
#
|
84
|
+
# Properties
|
85
|
+
#
|
86
|
+
|
87
|
+
private
|
88
|
+
def url_uploaders_map
|
89
|
+
{
|
90
|
+
:url => :uploader_bundle
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
def class_info
|
96
|
+
@class_info ||= get_class_by_name(CLASS_MAP[EClassType::ECT_BUNDLE_INFO])
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
def upload_file_path(url_field)
|
101
|
+
"bundles/#{self.build_type}"
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Methods
|
106
|
+
#
|
107
|
+
|
108
|
+
# default constructor
|
109
|
+
public
|
110
|
+
def initialize(options = nil)
|
111
|
+
super
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# validates
|
116
|
+
#
|
117
|
+
|
118
|
+
validates :name, presence: true, allow_blank: false, allow_nil: false
|
119
|
+
validates :url, presence: true, allow_blank: false, allow_nil: false
|
120
|
+
validates :build_type, presence: true, allow_blank: false, allow_nil: false
|
121
|
+
|
122
|
+
validate :check_uniq
|
123
|
+
#
|
124
|
+
# callbacks
|
125
|
+
#
|
126
|
+
|
127
|
+
public
|
128
|
+
def update_version
|
129
|
+
return unless errors.empty?
|
130
|
+
|
131
|
+
return unless self.changed?
|
132
|
+
|
133
|
+
self.version += 1
|
134
|
+
end
|
135
|
+
|
136
|
+
public
|
137
|
+
def callback_after_save
|
138
|
+
return unless errors.empty?
|
139
|
+
|
140
|
+
return unless self.changed?
|
141
|
+
|
142
|
+
return unless Rails.env.development?
|
143
|
+
|
144
|
+
manager_bundles = AppInfo.instance.managers_bundles_map[self.build_type]
|
145
|
+
|
146
|
+
manager_bundles.invalidate_cache
|
147
|
+
manager_bundles.generate_client_json
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
def check_uniq
|
152
|
+
if BundleBase.where(build_type: self.build_type, name: self.name, :id.ne => self.id).exists?
|
153
|
+
self.errors.add(:base, 'bundle with same build type and name already exist')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# uploaders
|
159
|
+
#
|
160
|
+
|
161
|
+
public
|
162
|
+
mount_uploader :uploader_bundle, FileUploader
|
163
|
+
|
164
|
+
#
|
165
|
+
# scopes
|
166
|
+
#
|
167
|
+
|
168
|
+
public
|
169
|
+
def self.init_scopes
|
170
|
+
bundles = self.only(:build_type, :name).to_a
|
171
|
+
|
172
|
+
names_list = []
|
173
|
+
|
174
|
+
bundles.each do |bundle|
|
175
|
+
name = bundle.name.underscore.split('_').first
|
176
|
+
|
177
|
+
names_list << name
|
178
|
+
end
|
179
|
+
|
180
|
+
names_list.uniq!
|
181
|
+
|
182
|
+
EBuildType.values_list.each do |build_type|
|
183
|
+
names_list.each do |name|
|
184
|
+
scope_name = "#{build_type}_#{name}"
|
185
|
+
|
186
|
+
criteria =
|
187
|
+
{
|
188
|
+
build_type: build_type,
|
189
|
+
name: Regexp.new("^#{name}_")
|
190
|
+
}
|
191
|
+
|
192
|
+
add_scope(scope_name, criteria)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class BundleInfoBase < InfoBase
|
2
|
+
|
3
|
+
#
|
4
|
+
# Properties
|
5
|
+
#
|
6
|
+
|
7
|
+
attr_accessor :version
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :url
|
10
|
+
|
11
|
+
#
|
12
|
+
# Methods
|
13
|
+
#
|
14
|
+
|
15
|
+
# default constructor
|
16
|
+
public
|
17
|
+
def initialize
|
18
|
+
end
|
19
|
+
|
20
|
+
public
|
21
|
+
def serialize
|
22
|
+
{
|
23
|
+
version: version,
|
24
|
+
name: name,
|
25
|
+
url: url
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|