active_module 0.9.1 → 0.10.0

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: 8d77a661dc79e590fdf8f2738fb32c2fcfe85bb1f9ff34fd4ff5988d880fc9c0
4
- data.tar.gz: 24c7478f77096285f4cf59202380e6ca0f847bde3055bd3114fe2e3a7eb7f43f
3
+ metadata.gz: a773717e3bd491388a8e16d8089b33305c79bb1643c10787e69756f5766c4781
4
+ data.tar.gz: 4e193e05305cf58c1c079134ff25e4f189cf2d1bd16edbf0765bccaaf05f70f9
5
5
  SHA512:
6
- metadata.gz: feb6feb26ab1b771684e1619b205181885ccf27f31f27fa5a8092a3c863c1dd945f66dc04d0edb3853dc6611fe7e551aff87b6d60b5ab10c1fbf1956831641ab
7
- data.tar.gz: 6a88a6e2aeb4f6b6f93dd7abb9712f7d3535ef35063a97f8a439eef6c29d2b79e9dc75124bb2d84ac343354fab0c697c8ed4c29e7763fe8edf58ee3246e746d3
6
+ metadata.gz: 3221ade593a5db7e9d697c90a55b3a3bbe002986d51f26976022e884e66f623009ed34e392be2154cdfb43bfd99d0f5b3924feb4a4f97a4c92e289d25bf8522b
7
+ data.tar.gz: 8d6e3251df54906e9a6abd6815ffa5c45217b48c390e957b722a16b028157daf2a3e2b5439671f7c3047828b0554590ad06cfe7aa70f6ee93ccf811467e32bb0
data/README.md CHANGED
@@ -695,6 +695,8 @@ active_module_enum :pipeline_stage,
695
695
  - **`on_ambiguous: :silence`** — suppresses warnings when multiple
696
696
  modules share the same demodulized name (e.g. `Tino` and
697
697
  `Banana::Tino` both producing `tino?`)
698
+ - **`on_ambiguous: :warn`** — logs the warning with `Rails.logger.warn` when
699
+ an ambiguous demodulized name is used (default behavior).
698
700
 
699
701
  ##### Ambiguity resolution
700
702
 
@@ -35,18 +35,32 @@ module ActiveModule
35
35
  define_method(name, &block)
36
36
  end
37
37
 
38
- def warn_if_ambiguous(mod, value_name, opts, maps)
39
- return unless maps[:ambiguity][value_name]&.size&.> 1
38
+ def warn_if_ambiguous(value_name, opts, maps)
39
+ return unless should_warn_for_ambiguity?(value_name, opts, maps)
40
+
41
+ Rails.logger.warn(ambiguity_warning_message(value_name, opts, maps))
42
+ end
43
+
44
+ def should_warn_for_ambiguity?(value_name, opts, maps)
45
+ ambiguous_modules = maps[:ambiguity][value_name]
46
+ return unless ambiguous_modules&.size&.> 1
40
47
  return if opts[:on_ambiguous] == :silence
41
48
 
49
+ maps[:warned].add?(value_name)
50
+ end
51
+
52
+ def ambiguity_warning_message(value_name, opts, maps)
53
+ ambiguous_modules = maps[:ambiguity][value_name]
42
54
  name = enum_method_name(value_name, opts)
43
- alts = (maps[:unique][mod] || [])
44
- .map { |a| "`#{a}`" }
45
- warn("WARNING: `#{name}` is ambiguous. " \
46
- "Use #{alts.join(", ")} for " \
47
- "unambiguous access. " \
48
- "Pass on_ambiguous: :silence " \
49
- "to suppress this warning.")
55
+ alts = ambiguous_modules
56
+ .flat_map { |ambiguous_mod| maps[:unique][ambiguous_mod] || [] }
57
+ .uniq
58
+ .map { |alternative| enum_method_name(alternative, opts) }
59
+ "WARNING: `#{name}` is ambiguous. " \
60
+ "Use #{alts.map { |alt| "`#{alt}`" }.join(", ")} for " \
61
+ "unambiguous access. " \
62
+ "Pass on_ambiguous: :silence " \
63
+ "to suppress this warning."
50
64
  end
51
65
 
52
66
  def build_name_maps(modules)
@@ -52,6 +52,7 @@ module ActiveModule
52
52
  sorted = modules
53
53
  .sort_by { |m| m.name.count("::") }
54
54
  maps = build_name_maps(sorted)
55
+ maps[:warned] = Set.new
55
56
  existing = {
56
57
  instance: instance_methods,
57
58
  singleton: singleton_methods
@@ -66,7 +67,7 @@ module ActiveModule
66
67
  def generate_methods(attribute_name, mod, opts,
67
68
  maps, existing)
68
69
  mod.underscored_names.each do |value_name|
69
- warn_if_ambiguous(mod, value_name, opts, maps)
70
+ warn_if_ambiguous(value_name, opts, maps)
70
71
  if opts[:instance_methods]
71
72
  define_instance_methods(
72
73
  attribute_name, mod, value_name,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveModule
4
- VERSION = "0.9.1"
4
+ VERSION = "0.10.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_module
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Rolo