active_module 0.9.0 → 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: 9b89a72d9eb3c1f6de06429d825e774eab2f039126c46f1c410b0050d88bdfc6
4
- data.tar.gz: f2955121a326352f383a734357406895a89ff3aca27ea03c39651ac734c187e9
3
+ metadata.gz: a773717e3bd491388a8e16d8089b33305c79bb1643c10787e69756f5766c4781
4
+ data.tar.gz: 4e193e05305cf58c1c079134ff25e4f189cf2d1bd16edbf0765bccaaf05f70f9
5
5
  SHA512:
6
- metadata.gz: 69638a53a743d8b834ccea349b7c4615bda8f785f2af6c5bf707203dde09eb2820ae1ac35c651743c76e402889ee93c42996808f46b5d851797564e392892f70
7
- data.tar.gz: ab04085e13a62140ac4fbafe188e1f14fefec8f081f4352979a7d4e7181af1f3b97aeb580841d307a37a0a32b74592c4c8ad06de98ee9b3f5f456661d98d509f
6
+ metadata.gz: 3221ade593a5db7e9d697c90a55b3a3bbe002986d51f26976022e884e66f623009ed34e392be2154cdfb43bfd99d0f5b3924feb4a4f97a4c92e289d25bf8522b
7
+ data.tar.gz: 8d6e3251df54906e9a6abd6815ffa5c45217b48c390e957b722a16b028157daf2a3e2b5439671f7c3047828b0554590ad06cfe7aa70f6ee93ccf811467e32bb0
data/README.md CHANGED
@@ -76,7 +76,7 @@ end
76
76
  Add to your gemfile - and if you are using rails - that's all you need:
77
77
 
78
78
  ```ruby
79
- gem "active_module", "~> 0.8"
79
+ gem "active_module", "~> 0.9"
80
80
  ```
81
81
 
82
82
  If you are not using rails, just issue this command after loading active record
@@ -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,
@@ -27,12 +27,8 @@ module ActiveModule
27
27
 
28
28
  def colon_delimited_names
29
29
  name_parts = name.split("::")
30
- [qualified_name].tap do |names|
31
- loop do
32
- names << name_parts.join("::").freeze
33
- name_parts = name_parts.drop(1)
34
- break if name_parts.empty?
35
- end
30
+ [qualified_name] + name_parts.each_index.map do |index|
31
+ name_parts.drop(index).join("::").freeze
36
32
  end
37
33
  end
38
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveModule
4
- VERSION = "0.9.0"
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.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Rolo
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 4.0.10
126
+ rubygems_version: 4.0.22
127
127
  specification_version: 4
128
128
  summary: Modules and Classes as first-class active record values
129
129
  test_files: []