hancock_cms_cache 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/README.md +35 -0
  7. data/Rakefile +2 -0
  8. data/app/assets/javascripts/hancock/rails_admin/plugins/cache.coffee +4 -0
  9. data/app/assets/javascripts/hancock/rails_admin/plugins/cache/custom/ui.coffee +0 -0
  10. data/app/assets/stylesheets/hancock/rails_admin/plugins/cache.sass +3 -0
  11. data/app/assets/stylesheets/hancock/rails_admin/plugins/cache/custom/theming.sass +0 -0
  12. data/app/controllers/concerns/hancock/cache/action.rb +58 -0
  13. data/app/controllers/concerns/hancock/cache/ajax_csrf.rb +25 -0
  14. data/app/controllers/concerns/hancock/cache/fragments.rb +34 -0
  15. data/app/controllers/concerns/hancock/cache/no_cache.rb +12 -0
  16. data/app/helpers/hancock/cache/cache_helper.rb +167 -0
  17. data/app/models/concerns/hancock/cache/cacheable.rb +164 -0
  18. data/app/models/concerns/hancock/cache/cleared_stack.rb +43 -0
  19. data/app/models/concerns/hancock/cache/decorators/fragment.rb +41 -0
  20. data/app/models/concerns/hancock/cache/loadable.rb +44 -0
  21. data/app/models/concerns/hancock/cache/snapshotable.rb +49 -0
  22. data/app/models/hancock/cache/fragment.rb +11 -0
  23. data/app/views/hancock/_assets.html.slim +24 -0
  24. data/app/views/layouts/application.html.slim +33 -0
  25. data/app/views/rails_admin/main/hancock_cache_global_clear.html.slim +25 -0
  26. data/bin/console +14 -0
  27. data/bin/setup +8 -0
  28. data/config/initializers/cache_detector.rb +53 -0
  29. data/config/initializers/hancock_cache.rb +7 -0
  30. data/config/locales/hancock.cache.ru.yml +59 -0
  31. data/hancock_cms_cache.gemspec +34 -0
  32. data/lib/generators/hancock/cache/config/config_generator.rb +13 -0
  33. data/lib/generators/hancock/cache/config/templates/hancock_cache.erb +14 -0
  34. data/lib/generators/hancock/cache/models/decorators_generator.rb +24 -0
  35. data/lib/generators/hancock/cache/models/fragment_generator.rb +39 -0
  36. data/lib/generators/hancock/cache/models/templates/fragment.erb +38 -0
  37. data/lib/hancock/cache/admin.rb +37 -0
  38. data/lib/hancock/cache/admin/fragment.rb +140 -0
  39. data/lib/hancock/cache/configuration.rb +38 -0
  40. data/lib/hancock/cache/engine.rb +20 -0
  41. data/lib/hancock/cache/models/fragment.rb +310 -0
  42. data/lib/hancock/cache/models/mongoid/fragment.rb +259 -0
  43. data/lib/hancock/cache/rails_admin_ext/hancock_cache_clear.rb +95 -0
  44. data/lib/hancock/cache/rails_admin_ext/hancock_cache_dump_snapshot.rb +92 -0
  45. data/lib/hancock/cache/rails_admin_ext/hancock_cache_global_clear.rb +74 -0
  46. data/lib/hancock/cache/rails_admin_ext/hancock_cache_restore_snapshot.rb +92 -0
  47. data/lib/hancock/cache/rails_admin_ext/hancock_touch.rb +95 -0
  48. data/lib/hancock/cache/rails_admin_settings_patch.rb +185 -0
  49. data/lib/hancock/cache/version.rb +5 -0
  50. data/lib/hancock_cms_cache.rb +34 -0
  51. data/release.sh +6 -0
  52. metadata +141 -0
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Cache
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc 'Hancock::Cache Config generator'
8
+ def config
9
+ template 'hancock_cache.erb', "config/initializers/hancock_cache.rb"
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ Hancock::Cache.configure do |config|
2
+ ##### defaults #####
3
+ #
4
+ # config.localize = Hancock.config.localize
5
+ #
6
+ # config.runtime_cache_detector = false
7
+ #
8
+ # config.preloaded_fragments = []
9
+ # config.preloaded_fragments += [
10
+ # {name: 'keyname', desc: 'desc', overwrite: true},
11
+ # {name: 'no overwrited key', desc: 'desc', overwrite: false}
12
+ # ]
13
+ # config.preloaded_fragments << {name: 'somekey', parents: ['keyname']}
14
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Cache::Models
4
+ class DecoratorsGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../../../../app/models/concerns/hancock/cache/decorators', __FILE__)
6
+ argument :models, type: :array, default: []
7
+
8
+ desc 'Hancock::Cache Models decorators generator'
9
+ def decorators
10
+ copied = false
11
+ (models == ['all'] ? permitted_models : models & permitted_models).each do |c|
12
+ copied = true
13
+ copy_file "#{c}.rb", "app/models/concerns/hancock/cache/decorators/#{c}.rb"
14
+ end
15
+ puts "U need to set models`s name. One of this: #{permitted_models.join(", ")}." unless copied
16
+ end
17
+
18
+ private
19
+ def permitted_models
20
+ ['fragment']
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Goto::Models
4
+ class TransferGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ argument :class_name_arg, type: :string, default: ""
7
+
8
+ desc 'Hancock::Goto Transfer Model generator'
9
+ def transfer
10
+ template 'transfer.erb', "app/models/#{file_name}.rb"
11
+ end
12
+
13
+ private
14
+ def class_name
15
+ class_name_arg.blank? ? "SetClassForTransfer" : class_name_arg
16
+ end
17
+
18
+ def capitalized_class_name
19
+ class_name.capitalize
20
+ end
21
+
22
+ def camelcased_class_name
23
+ class_name.camelcase
24
+ end
25
+
26
+ def file_name
27
+ underscored_class_name
28
+ end
29
+
30
+ def underscored_class_name
31
+ camelcased_class_name.underscore
32
+ end
33
+
34
+ def underscored_pluralized_class_name
35
+ underscored_class_name.pluralize
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ class <%= camelcased_class_name %> < Hancock::Cache::Fragment
2
+
3
+ ############ rails_admin ##############
4
+ def self.rails_admin_name_synonyms
5
+ "Кеш Кэш".freeze
6
+ end
7
+ def self.rails_admin_navigation_icon
8
+ ''.freeze
9
+ end
10
+
11
+ def self.rails_admin_add_fields
12
+ [] #super
13
+ end
14
+
15
+ def self.rails_admin_add_config(config)
16
+ #super(config)
17
+ end
18
+
19
+ def self.admin_can_user_defined_actions
20
+ [].freeze
21
+ end
22
+ def self.admin_cannot_user_defined_actions
23
+ [].freeze
24
+ end
25
+ def self.manager_can_user_defined_actions
26
+ [].freeze
27
+ end
28
+ def self.manager_cannot_user_defined_actions
29
+ [].freeze
30
+ end
31
+ def self.rails_admin_user_defined_visible_actions
32
+ [].freeze
33
+ end
34
+
35
+ rails_admin(&Hancock::Cache::Admin::Fragment.config(rails_admin_add_fields) { |config|
36
+ rails_admin_add_config(config)
37
+ })
38
+ end
@@ -0,0 +1,37 @@
1
+ module Hancock::Cache
2
+ module Admin
3
+
4
+ def self.caching_block(is_active = false, options = {})
5
+ if is_active.is_a?(Hash)
6
+ is_active, options = (is_active[:active] || false), is_active
7
+ end
8
+
9
+ Proc.new {
10
+ active is_active
11
+ label options[:label] || I18n.t('hancock.cache')
12
+ field :perform_caching, :toggle
13
+ field :cache_keys_str, :text do
14
+ searchable true
15
+ end
16
+ field :cache_fragments do
17
+ read_only true
18
+ formatted_value do
19
+ bindings and bindings[:object] and bindings[:object].cache_fragments.all.to_a.map do |_frag|
20
+ bindings[:view].link_to(
21
+ _frag.name,
22
+ bindings[:view].show_path(model_name: _frag.rails_admin_model, id: _frag.id),
23
+ )
24
+ end.join(", ").html_safe
25
+ end
26
+ end
27
+
28
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
29
+
30
+ if block_given?
31
+ yield self
32
+ end
33
+ }
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,140 @@
1
+ module Hancock::Cache
2
+ module Admin
3
+ module Fragment
4
+ def self.config(fields = {})
5
+ Proc.new {
6
+ navigation_label I18n.t('hancock.cache')
7
+
8
+ list do
9
+ field :enabled, :toggle
10
+ field :is_action_cache do
11
+ read_only true
12
+ end
13
+
14
+ field :name_n_desc_n_parents
15
+ # field :name_n_desc
16
+ field :name do
17
+ visible false
18
+ searchable true
19
+ end
20
+ field :desc do
21
+ visible false
22
+ searchable true
23
+ end
24
+
25
+ field :data do
26
+ pretty_value do
27
+ bindings[:object].data(false)
28
+ end
29
+ end
30
+
31
+ field :last_clear_data
32
+ field :last_clear_time do
33
+ visible false
34
+ searchable false
35
+ end
36
+ field :last_clear_user do
37
+ visible false
38
+ searchable false
39
+ end
40
+
41
+ field :on_ram, :toggle
42
+ field :is_html, :toggle
43
+ field :virtual_path do
44
+ searchable true
45
+ end
46
+
47
+ field :snapshot_data
48
+ field :snapshot do
49
+ visible false
50
+ searchable true
51
+ pretty_value do
52
+ bindings[:object].get_snapshot(false)
53
+ end
54
+ queryable true
55
+ end
56
+ field :last_dump_snapshot_time do
57
+ visible false
58
+ end
59
+ field :last_restore_snapshot_time do
60
+ visible false
61
+ end
62
+
63
+ scopes [nil, :is_action_cache, :on_ram]
64
+ end
65
+
66
+ edit do
67
+ field :enabled, :toggle
68
+ field :is_action_cache do
69
+ read_only true
70
+ end
71
+ field :on_ram, :toggle
72
+ field :name
73
+ field :virtual_path
74
+ field :is_html, :toggle
75
+ field :desc
76
+ field :parents, :hancock_multiselect
77
+
78
+ field :last_clear_time do
79
+ read_only true
80
+ end
81
+ field :last_clear_user do
82
+ read_only true
83
+ end
84
+ field :data do
85
+ read_only true
86
+ end
87
+
88
+ field :snapshot do
89
+ pretty_value do
90
+ bindings[:object].get_snapshot
91
+ end
92
+ read_only do
93
+ render_object = (bindings[:controller] || bindings[:view])
94
+ !(render_object and render_object.current_user.admin?)
95
+ end
96
+ end
97
+ field :last_dump_snapshot_time do
98
+ read_only true
99
+ end
100
+ field :last_restore_snapshot_time do
101
+ read_only true
102
+ end
103
+ end
104
+
105
+ show do
106
+ field :enabled, :toggle
107
+ field :is_action_cache do
108
+ read_only true
109
+ end
110
+ field :on_ram, :toggle
111
+ field :name
112
+ field :virtual_path
113
+ field :is_html
114
+ field :desc
115
+ field :parents
116
+ field :parent_names do
117
+ visible do
118
+ render_object = (bindings[:controller] || bindings[:view])
119
+ (render_object and render_object.current_user.admin?)
120
+ end
121
+ end
122
+ field :last_clear_time
123
+ field :last_clear_user
124
+ field :data
125
+
126
+ field :snapshot do
127
+ pretty_value do
128
+ bindings[:object].get_snapshot
129
+ end
130
+ end
131
+ field :last_dump_snapshot_time
132
+ field :last_restore_snapshot_time
133
+ end
134
+ }
135
+
136
+ end #def self.config(fields = {})
137
+
138
+ end #module Fragment
139
+ end #module Admin
140
+ end #module Hancock::Cache
@@ -0,0 +1,38 @@
1
+ module Hancock::Cache
2
+ include Hancock::PluginConfiguration
3
+
4
+ def self.config_class
5
+ Configuration
6
+ end
7
+
8
+ def self.configure
9
+ yield configuration
10
+ end
11
+
12
+ class Configuration
13
+
14
+ attr_accessor :localize
15
+
16
+ attr_accessor :runtime_cache_detector
17
+
18
+ attr_accessor :model_settings_support
19
+ attr_accessor :user_abilities_support
20
+ attr_accessor :ra_comments_support
21
+
22
+ attr_accessor :preloaded_fragments
23
+
24
+ def initialize
25
+
26
+ @localize = Hancock.config.localize
27
+
28
+ @runtime_cache_detector = false
29
+
30
+ @model_settings_support = !!defined?(RailsAdminModelSettings)
31
+ @user_abilities_support = !!defined?(RailsAdminUserAbilities)
32
+ @ra_comments_support = !!defined?(RailsAdminComments)
33
+
34
+ @preloaded_fragments = []
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ module Hancock
2
+ module Cache
3
+ class Engine < ::Rails::Engine
4
+ # isolate_namespace Hancock::Cache
5
+
6
+ initializer "RailsAdminSettingsPatch (cache)" do
7
+ if defined?(RailsAdminSettings)
8
+ ::RailsAdminSettings::Setting.send(:include, Hancock::Cache::RailsAdminSettingsPatch)
9
+ end
10
+ end
11
+
12
+ initializer "LookupContext Patch" do
13
+ ActionView::LookupContext.register_detail(:hancock_cache_keys) do
14
+ []
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,310 @@
1
+ module Hancock::Cache
2
+ module Models
3
+ module Fragment
4
+ extend ActiveSupport::Concern
5
+ include Hancock::Model
6
+ include Hancock::Enableable
7
+
8
+ include Hancock::Cache::Loadable
9
+
10
+ include Hancock::Cache.orm_specific('Fragment')
11
+
12
+ included do
13
+
14
+ include Hancock::Cache::ClearedStack
15
+
16
+ def self.rails_admin_name
17
+ self.name.gsub("::", "~").underscore
18
+ end
19
+
20
+ if Hancock::Cache.config.model_settings_support
21
+ include RailsAdminModelSettings::ModelSettingable
22
+ end
23
+
24
+ # def set_last_clear_user(forced_user = nil)
25
+ # self.last_clear_user = forced_user if forced_user
26
+ # end
27
+ def set_last_clear_user!(forced_user = nil)
28
+ self.set_last_clear_user(f_nameorced_user) and self.save
29
+ end
30
+
31
+ def clear_dry(forced_user = nil)
32
+ if self.set_last_clear_user(forced_user)
33
+ self.last_clear_time = Time.new
34
+ self
35
+ end
36
+ end
37
+ def clear_dry!(forced_user = nil)
38
+ self.clear_dry(forced_user) and self.save
39
+ end
40
+
41
+ def clear(forced_user = nil)
42
+ return nil if self.is_in_cleared_stack?
43
+ if self.set_last_clear_user(forced_user)
44
+ Rails.cache.delete(self.name)
45
+ self.on_ram_data = nil
46
+ self.last_clear_time = Time.new
47
+ self.add_to_cleared_stack
48
+ self.parents.each { |p| p.clear(forced_user) }
49
+ self.drop_cleared_stack_if_can
50
+ self
51
+ end
52
+ end
53
+ def clear!(forced_user = nil)
54
+ return nil if self.is_in_cleared_stack?
55
+ if self.set_last_clear_user(forced_user)
56
+ Rails.cache.delete(self.name)
57
+ self.on_ram_data = nil
58
+ self.last_clear_time = Time.new
59
+ self.add_to_cleared_stack
60
+ self.parents.each { |p| p.clear(forced_user) }
61
+ self.drop_cleared_stack_if_can
62
+ self.save
63
+ end
64
+ end
65
+
66
+ def name_from_view=(_name)
67
+ self.name = name_from_view(_name)
68
+ end
69
+ def self.name_from_view(_name)
70
+ if _name.is_a?(Array)
71
+ ret = _name.map { |n| name_from_view(n) }
72
+ else
73
+ ret = "views/#{_name}"
74
+ ret = "#{ret}index" if ret[-1] == "/"
75
+ end
76
+ ret
77
+ end
78
+
79
+ def self.create_unless_exists(_name, _desc = nil, _virtual_path = "", overwrite = :append)
80
+ if _name.is_a?(Hash)
81
+ _name, _desc, _virtual_path, overwrite, parents, on_ram, is_action_cache =
82
+ _name[:name], _name[:desc], (_name[:_virtual_path] || ""), _name[:overwrite], _name[:parents], _name[:on_ram], _name[:is_action_cache]
83
+ end
84
+ on_ram ||= false
85
+ is_action_cache ||= false
86
+
87
+ if _name.is_a?(Array)
88
+ return _name.map do |n|
89
+ create_unless_exists(n, _desc, _virtual_path, overwrite) unless n.blank?
90
+ end
91
+ end
92
+
93
+ unless _name.blank?
94
+ if Hancock::Cache::Fragment.where(name: _name).count == 0
95
+ if parents
96
+ if parents.first.is_a?(String)
97
+ parents = Hancock::Cache::Fragment.by_name(parents).distinct(:_id)
98
+ else
99
+ parents = parents.map(&:_id).uniq.compact
100
+ end
101
+ end
102
+ frag = Hancock::Cache::Fragment.create(name: _name, desc: _desc, virtual_path: _virtual_path, parent_ids: parents, on_ram: on_ram, is_action_cache: is_action_cache)
103
+ else
104
+ frag = Hancock::Cache::Fragment.where(name: _name).first
105
+ if overwrite.is_a?(Symbol) or overwrite.is_a?(String)
106
+ case overwrite.to_sym
107
+ when :append
108
+ frag.desc = "\n#{_desc}" unless frag.desc == _desc
109
+ frag.virtual_path += "\n#{_virtual_path}" unless frag.virtual_path.strip == _virtual_path.strip
110
+ if parents
111
+ if parents.first.is_a?(String)
112
+ frag.parent_ids += Hancock::Cache::Fragment.by_name(parents).distinct(:_id)
113
+ else
114
+ frag.parent_ids += parents.map(&:_id).uniq.compact
115
+ end
116
+ end
117
+ frag.on_ram = on_ram
118
+ frag.is_action_cache = is_action_cache
119
+ frag = frag.save and frag
120
+
121
+ when :overwrite
122
+ frag.desc = _desc
123
+ frag.virtual_path = _desc
124
+ if parents
125
+ if parents.first.is_a?(String)
126
+ frag.parent_ids = Hancock::Cache::Fragment.by_name(parents).distinct(:_id)
127
+ else
128
+ frag.parent_ids = parents.map(&:_id)
129
+ end
130
+ frag.parent_ids.uniq!
131
+ frag.parent_ids.compact!
132
+ end
133
+ frag.on_ram = on_ram
134
+ frag.is_action_cache = is_action_cache
135
+ frag = frag.save and frag
136
+ end #case overwrite.to_sym
137
+ else
138
+ if overwrite
139
+ frag.desc = _desc
140
+ frag.virtual_path = _desc
141
+ if parents
142
+ if parents.first.is_a?(String)
143
+ frag.parent_ids = Hancock::Cache::Fragment.by_name(parents).distinct(:_id)
144
+ else
145
+ frag.parent_ids = parents.map(&:_id).uniq.compact
146
+ end
147
+ end
148
+ frag.on_ram = on_ram
149
+ frag.is_action_cache = is_action_cache
150
+ frag = frag.save and frag
151
+ end
152
+ end #if overwrite.is_a?(Symbol) or overwrite.is_a?(String)
153
+ end #if Hancock::Cache::Fragment.where(name: _name).count == 0
154
+
155
+ frag
156
+ end #unless _name.blank?
157
+ end
158
+
159
+ def self.load_from_preloaded
160
+ Hancock::Cache.config.preloaded_fragments.map do |f_data|
161
+ Hancock::Cache::Fragment.create_unless_exists(f_data)
162
+ end
163
+ end
164
+
165
+ def self.clear_all(forced_user = nil)
166
+ self.all.to_a.map { |c| c.clear!(forced_user) }
167
+ end
168
+
169
+
170
+ def get_as_hash(overwrite = nil)
171
+ {
172
+ name: self.name,
173
+ desc: self.desc,
174
+ virtual_path: self.virtual_path,
175
+ parents: self.parents.map(&:name),
176
+ on_ram: self.on_ram,
177
+ is_action_cache: self.is_action_cache,
178
+ overwrite: overwrite
179
+ }.compact
180
+ end
181
+ def get_as_json(overwrite = nil)
182
+ get_as_hash(overwrite).to_json
183
+ end
184
+ def self.get_as_hash(overwrite = nil)
185
+ Hancock::Cache::Fragment.cutted.all.to_a.map { |f| f.get_as_hash(overwrite) }
186
+ end
187
+ def self.get_as_json(overwrite = nil)
188
+ Hancock::Cache::Fragment.cutted.all.to_a.map { |f| f.get_as_json(overwrite) }
189
+ end
190
+
191
+ # worse but working
192
+ def self.copy_preloaded_to_config_file(fname = "config/initializers/hancock_cache.rb")
193
+ File.truncate(fname, File.size(fname) - 4)
194
+ File.open(fname, 'a') do |file|
195
+ file.write " config.preloaded_fragments = [\n #{Hancock::Cache::Fragment.get_as_json.join(",\n ")}\n ]\n # Hancock::Cache::Fragment.load_from_preloaded\n # Hancock::MODELS.map { |m| m.respond_to?(:set_default_cache_keys!) and m.set_default_cache_keys! }\nend"
196
+ end
197
+ end
198
+ def self.copy_new_preloaded_to_config_file(fname = "config/initializers/hancock_cache.rb")
199
+ File.truncate(fname, File.size(fname) - 4)
200
+ _text = Hancock::Cache::Fragment.where(:name.nin => Hancock::Cache.config.preloaded_fragments.map { |f|
201
+ f[:name]
202
+ }).all.to_a.map { |f|
203
+ f.get_as_json(false)
204
+ }.join(",\n ")
205
+ File.open(fname, 'a') do |file|
206
+ file.write " config.preloaded_fragments += [\n #{_text}\n ]\n # Hancock::Cache::Fragment.load_from_preloaded\n # Hancock::MODELS.map { |m| m.respond_to?(:set_default_cache_keys!) and m.set_default_cache_keys! }\nend"
207
+ end
208
+ end
209
+
210
+
211
+ def set_for_object(obj)
212
+ return set_for_objects(obj) if obj.is_a?(::Array)
213
+ return set_for_model(obj.klass, true) if obj.is_a?(::Mongoid::Criteria)
214
+ obj and
215
+ obj.fields.keys.include?(:cache_keys_str) and obj.respond_to?(:cache_keys) and
216
+ !obj.cache_keys.include?(self.name) and
217
+ obj.class.where(id: obj.id).update(cache_keys_str: "#{obj.cache_keys_str}\n#{self.name}".strip)
218
+ end
219
+ def set_for_objects(objs)
220
+ if objs
221
+ objs.map do |obj|
222
+ set_for_object(obj)
223
+ end
224
+ end
225
+ end
226
+ def set_for_model(model, as_forced = false)
227
+ return set_for_models(model, as_forced) if model.is_a?(::Array)
228
+ if model
229
+ if as_forced and model.respond_to :add_forced_cache_key
230
+ model.send(:add_forced_cache_key, self.name) unless model.forced_cache_key.include?(self.name)
231
+ else
232
+ set_for_objects(model.not(cache_keys_str: /(^|\n)#{Regexp.escape self.name}(\n|$)/).all.to_a)
233
+ end
234
+ end
235
+ # model and set_for_objects(model.all.to_a)
236
+ end
237
+ def set_for_models(models, as_forced = false)
238
+ if models
239
+ models.map do |model|
240
+ set_for_model(model)
241
+ end
242
+ end
243
+ end
244
+ def set_for_setting(setting_obj)
245
+ if defined?(RailsAdminModelSettings)
246
+ if setting_obj.is_a?(Hash)
247
+ unless setting_obj[:keys].present?
248
+ if setting_obj[:key].nil?
249
+ return set_for_setting({ns: setting_obj[:ns], key: nil})
250
+ else
251
+ # setting_obj = RailsAdminSettings::Setting.where(ns: setting_obj[:ns], key: setting_obj[:key]).not(cache_keys_str: /(^|\n)#{Regexp.escape self.name}(\n|$)/).first
252
+ setting_obj = Settings.ns(setting_obj[:ns]).getnc(setting_obj[:key])
253
+ end
254
+
255
+ else
256
+ # setting_obj = RailsAdminSettings::Setting.where(ns: setting_obj[:ns], :key.in => setting_obj[:keys]).not(cache_keys_str: /(^|\n)#{Regexp.escape self.name}(\n|$)/).all.to_a
257
+ return setting_obj[:keys].map do |k|
258
+ # set_for_setting({ns: setting_obj[:ns], key: k}) unless k.blank?
259
+ set_for_setting(Settings.ns(setting_obj[:ns]).getnc(k)) unless k.blank?
260
+ end
261
+ end
262
+
263
+ elsif setting_obj.is_a?(Array)
264
+ return setting_obj.map do |obj|
265
+ set_for_setting(obj) unless obj.blank?
266
+ end
267
+ end
268
+
269
+ setting_obj and set_for_object(setting_obj) and setting_obj.reload
270
+ end
271
+ end
272
+
273
+ def self.rails_admin_name_synonyms
274
+ "Кеш Кэш".freeze
275
+ end
276
+ def self.rails_admin_navigation_icon
277
+ ''.freeze
278
+ end
279
+
280
+
281
+ def self.manager_can_add_actions
282
+ ret = [:hancock_cache_clear, :hancock_cache_global_clear, :hancock_cache_dump_snapshot, :hancock_cache_restore_snapshot]
283
+ ret << :model_settings if Hancock::Cache.config.model_settings_support
284
+ # ret << :model_accesses if Hancock::Cache.config.user_abilities_support
285
+ # ret += [:comments, :model_comments] if Hancock::Cache.config.ra_comments_support
286
+ ret.freeze
287
+ end
288
+ def self.rails_admin_add_visible_actions
289
+ ret = [:hancock_cache_clear, :hancock_cache_global_clear, :hancock_cache_dump_snapshot, :hancock_cache_restore_snapshot]
290
+ ret << :model_settings if Hancock::Cache.config.model_settings_support
291
+ ret << :model_accesses if Hancock::Cache.config.user_abilities_support
292
+ # ret += [:comments, :model_comments] if Hancock::Cache.config.ra_comments_support
293
+ ret.freeze
294
+ end
295
+
296
+ after_touch :reload_fragments
297
+ after_save :reload_fragments
298
+ after_destroy :reload_fragments
299
+ protected
300
+ def reload_fragments
301
+ if ::ApplicationController.respond_to?(:reload_fragments)
302
+ ::ApplicationController.reload_fragments
303
+ end
304
+ end
305
+
306
+ end
307
+
308
+ end
309
+ end
310
+ end