kono_utils_bootstrap_view4 0.2.1 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fcef8e13a1c9c4bff67ed8e88c00bf04fcbfbc8ffd4b1cbc48bd0916b65fd60
4
- data.tar.gz: 9899170841054403a58adfc4c7e171c8702347dda0806d3b1867ab96dad3baac
3
+ metadata.gz: aa0a2f1125771c5f72660fb327ededb8c2262eb4f036618f3bafdd78a3e54c5c
4
+ data.tar.gz: 56914dcf749aa2959aca53d809c2045b37cc0c0cc432047c351b48c689fdd7de
5
5
  SHA512:
6
- metadata.gz: 9813a36ce88877e93019ff4c87e98efc3cbdeaa8180ba55dd9dcff6fd27124fafc556c8a61b4010cfdfa825b3710f19fde05f90913013ff6a5a03798f0bbb9bf
7
- data.tar.gz: 39503751866ad57624a900937915d71e82fe254449b415519bbca6b27bbcd4c1d320c216f084b94da214577616bbbfd226d400ee02225d112bfcd06e937dea3f
6
+ metadata.gz: f4318dbe3a8f1ef499fdc36748a446a6ef947a220151da1800542975c4894cf093f8178abf04d6b9c8d3e893ea45bb2765f894a0a11c25bfb97ac08f536db0d4
7
+ data.tar.gz: aadf01fb29d8bf9c424dd5296272e5926bb9e078ad966526c00fa33cf929e28019df2dcc0c4a1710b2d0b25a17dca47b1a06ace59a9d6de76a38a183493391b6
@@ -37,6 +37,12 @@ module KonoUtils
37
37
  parent_controller.send(:show_custom_polymorphic_path, *rec)
38
38
  end
39
39
 
40
+ def show(&block)
41
+ ActiveSupport::Notifications.instrument "kono_utils_bootstrap_view4.#{self.class.name.underscore.gsub("/", ".")}", this: :data do
42
+ super
43
+ end
44
+ end
45
+
40
46
  ##
41
47
  # Registra il contenuto con una chiave, e lo renderizza poi dove è più necessario
42
48
  # @param [String] name
@@ -32,7 +32,7 @@ module KonoUtils
32
32
  #
33
33
  def input_value
34
34
  value = form.object.send(attribute_name)
35
- value.is_a?(DateTime) ? "date: moment('#{value&.rfc2822}')," : ''
35
+ value.respond_to?(:rfc2822) ? "date: moment('#{value.rfc2822}')," : ''
36
36
  end
37
37
 
38
38
  def input_picker_format
@@ -4,6 +4,11 @@ module KonoUtils
4
4
  module Index # namespace
5
5
  class RowButtons < Base # class
6
6
 
7
+ ##
8
+ # Restituisce la policy per la riga, non viene instanziata più volte per oggetto
9
+ def cached_policy
10
+ @_cached_policy ||= policy(model)
11
+ end
7
12
  end
8
13
  end
9
14
  end
@@ -2,7 +2,7 @@
2
2
  <thead>
3
3
  <tr>
4
4
  <% columns_to_show.each do |c| %>
5
- <th><%= form.object.class.human_attribute_name(c.name) %></th>
5
+ <th><%= base_class.human_attribute_name(c.name) %></th>
6
6
  <% end %>
7
7
  <th></th>
8
8
  </tr>
@@ -1,3 +1,3 @@
1
- <%= concept("cell/buttons/show", model) if policy(model).show? %>
2
- <%= concept("cell/buttons/edit", model) if policy(model).edit? %>
3
- <%= concept("cell/buttons/delete", model) if policy(model).destroy? %>
1
+ <%= concept("cell/buttons/show", model) if cached_policy.show? %>
2
+ <%= concept("cell/buttons/edit", model) if cached_policy.edit? %>
3
+ <%= concept("cell/buttons/delete", model) if cached_policy.destroy? %>
@@ -14,6 +14,7 @@ module KonoUtilsBootstrapView4
14
14
  autoload :Engine
15
15
  autoload :PaginateProxer
16
16
  autoload :SearchFormBuilder
17
+ autoload :ConceptCacher
17
18
  autoload :VERSION
18
19
 
19
20
  class << self
@@ -14,26 +14,16 @@ module KonoUtilsBootstrapView4
14
14
  end
15
15
 
16
16
  def concept_ns(view)
17
- @_memo_concept ||= {}
18
17
  ns = "#{tableize(self.name)}/#{view}"
19
-
20
- unless @_memo_concept.key?(ns)
18
+ KonoUtilsBootstrapView4.configuration.concept_cacher.get(ns) do |cache|
21
19
  if safe_constantize(ns.camelize)
22
20
  KonoUtilsBootstrapView4.configuration.logger.info { "TROVATA CLASSE PER : #{ns.camelize} --->>>" }
23
- @_memo_concept[ns] = ns
21
+ cache.store(ns, ns)
24
22
  else
25
- @_memo_concept[ns] = false
23
+ KonoUtilsBootstrapView4.configuration.logger.debug { "CLASSE OVERRIDE NON TROVATA PER : #{ns.camelize}" }
24
+ cache.store(ns, "kono_utils/object/#{view}")
26
25
  end
27
26
  end
28
-
29
- if @_memo_concept[ns]
30
- return @_memo_concept[ns]
31
- else
32
- KonoUtilsBootstrapView4.configuration.logger.debug { "CLASSE OVERRIDE NON TROVATA PER : #{ns.camelize}" }
33
-
34
- "kono_utils/object/#{view}"
35
- end
36
-
37
27
  end
38
28
 
39
29
  ##
@@ -0,0 +1,38 @@
1
+ module KonoUtilsBootstrapView4
2
+ ##
3
+ # PORO per l'esecuzione della cache a livello di istanza applicazione dei nomi di classe da utilizzare per i vari
4
+ # componenti dei modelli
5
+ class ConceptCacher
6
+ #@return [Hash]
7
+ attr_reader :_cache
8
+
9
+ def initialize
10
+ @_cache = {}
11
+ end
12
+
13
+ def clear
14
+ Rails.logger.debug {"PULIZIA CACHE"}
15
+ @_cache = {}
16
+ end
17
+
18
+ ##
19
+ # Ritorna il valore cachato, se non è presente, allora verrà dato in pasto allo yield l'istanza di cache, e sarà
20
+ # chi la utilizzerà che si occuperà di salvare o meno il dato richiamato il metodo store passando il relativo valore da
21
+ # salvare
22
+ # @param [String] key
23
+ # @return [Object] Cached result
24
+ # @yieldparam [KonoUtilsBootstrapView4::ConceptCacher]
25
+ def get(key)
26
+ return @_cache[key] if @_cache.key?(key)
27
+ yield(self)
28
+ @_cache[key]
29
+ end
30
+
31
+ ##
32
+ # Store del valore
33
+ def store(key, value)
34
+ @_cache[key] = value
35
+ end
36
+
37
+ end
38
+ end
@@ -4,8 +4,23 @@ class KonoUtilsBootstrapView4::Configuration
4
4
  #@return [ActiveSupport::TaggedLogging] log di kono utils bootstrap, default estende quello di rails
5
5
  attr_reader :logger
6
6
 
7
+ ##
8
+ # Se attivo, abilitiamo le metriche con un un ActiveSupport::Notifications.instrument
9
+ # durante la show della cella
10
+ #@return [Boolean]
11
+ attr_accessor :cell_metrics
12
+
13
+ ##
14
+ # Cache delle classi del concept
15
+ # Nell'inizializzazione di rails aggiungiamo un ascoltatore alla cartella standard dei concepts per
16
+ # controllare se i files sono stati modificati, nel caso puliamo completamente la cartella
17
+ attr_reader :concept_cacher
18
+
7
19
  def initialize
8
20
  @moment_js_locales = I18n.available_locales
21
+ @concept_cacher = KonoUtilsBootstrapView4::ConceptCacher.new
22
+
23
+ @cell_metrics = false
9
24
  # inizializzo logger, come quello che mi verrebbe passato
10
25
  self.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
11
26
  end
@@ -34,6 +34,21 @@ module KonoUtilsBootstrapView4
34
34
  end
35
35
  end
36
36
 
37
+ initializer 'kono_utils_bootstrap_view4.append_instrumentation', :group => :all do |app|
38
+ if KonoUtilsBootstrapView4.configuration.cell_metrics
39
+ app.config.after_initialize do
40
+ ActiveSupport::Notifications.subscribe /kono_utils_bootstrap_view4/ do |event|
41
+ Rails.logger.info "[KUBV4] #{event.name} - #{event.duration} ms - (#{event.allocations} allocations)"
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ initializer 'kono_utils_bootstrap_view4.configure_auto_clear_concept_cache', :group => :all do |app|
48
+ app.reloader.to_prepare do
49
+ KonoUtilsBootstrapView4.configuration.concept_cacher.clear
50
+ end
51
+ end
37
52
  ##
38
53
  # Abbiamo rimosso possibili JS, lasciamo per documentazione
39
54
  initializer 'kono_utils_bootstrap_view4.append_cell_assets', :group => :all do |app|
@@ -51,7 +66,6 @@ module KonoUtilsBootstrapView4
51
66
  end
52
67
  end
53
68
 
54
-
55
69
  Rails.logger.warn { "config.assets.initialize_on_precompile should be true" } unless app.config.assets.initialize_on_precompile == true
56
70
  end
57
71
 
@@ -1,3 +1,3 @@
1
1
  module KonoUtilsBootstrapView4
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kono_utils_bootstrap_view4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marino Bonetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-02 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -350,6 +350,7 @@ files:
350
350
  - lib/kono_utils_bootstrap_view4/application_icon_helper.rb
351
351
  - lib/kono_utils_bootstrap_view4/base_class_concept_ns.rb
352
352
  - lib/kono_utils_bootstrap_view4/base_search.rb
353
+ - lib/kono_utils_bootstrap_view4/concept_cacher.rb
353
354
  - lib/kono_utils_bootstrap_view4/configuration.rb
354
355
  - lib/kono_utils_bootstrap_view4/editable_field.rb
355
356
  - lib/kono_utils_bootstrap_view4/engine.rb