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 +4 -4
- data/README.md +2 -0
- data/lib/active_module/enum/util.rb +23 -9
- data/lib/active_module/enum.rb +2 -1
- data/lib/active_module/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a773717e3bd491388a8e16d8089b33305c79bb1643c10787e69756f5766c4781
|
|
4
|
+
data.tar.gz: 4e193e05305cf58c1c079134ff25e4f189cf2d1bd16edbf0765bccaaf05f70f9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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(
|
|
39
|
-
return unless
|
|
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 =
|
|
44
|
-
.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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)
|
data/lib/active_module/enum.rb
CHANGED
|
@@ -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(
|
|
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,
|