counterwise 0.1.2 → 0.1.3

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: ac4f723a8cdebb397ea3c1035ee728599ce308ebe36fc5aaa9fb6afeff09474e
4
- data.tar.gz: 5efc1f7fdbde64eab27962e0b37355ae16f8293c8173d101e85da97b81679dc7
3
+ metadata.gz: f1cdc6acd0972160c280ad8df73b8a97716f7cac8a5f2a8b45149c73426ece5f
4
+ data.tar.gz: e64e450d2e6e430db5acdd0042ec796183f7640cddffa6a1d86f8020846b284d
5
5
  SHA512:
6
- metadata.gz: 48b91a565a82de0da5dbdf3e6637721ae05ad4b5bea9e0b8c31366932e6b30f6460e526911a458ceda815910d1031046b2413eb0668207cd001c18afdb030002
7
- data.tar.gz: 5d6fd86b0ab23cd378ed374c6bf91aab877626038f7c35acecd2b123777fb646340a4070e61e02cbbf98ce9ab521155c25d2e0b320de0879a927def69cf41b30
6
+ metadata.gz: 65ab2e425276794f29b05286566fdf6009833f500d57e521774dcccd99adca0e2068edf894dd9de667aebad8d0a246b819874554855fc678f1ba1e8aa00e522f
7
+ data.tar.gz: 40efd582468d6d310bb1487081202fd0912f3d77765656222d5a0f6b14bc5d237e846cbda25d80ebfc0060bbc7a1e1fedad65d91ffca152de437736e0a65117e
@@ -4,13 +4,24 @@ module Counter::Definable
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
+ def definition= definition
8
+ @definition = definition
9
+ end
10
+
7
11
  # Fetch the definition for this counter
8
12
  def definition
9
- if parent.nil?
10
- # We don't have a parent, so we're a global counter
11
- Counter::Definition.find_definition name
12
- else
13
- parent.class.counter_configs.find { |c| c.record_name == name }
13
+ @definition ||= begin
14
+ if parent.nil?
15
+ # We don't have a parent, so we're a global counter
16
+ Counter::Definition.find_definition name
17
+ else
18
+ parent.class.ancestors.find do |ancestor|
19
+ return nil if ancestor == ApplicationRecord
20
+ next unless ancestor.respond_to?(:counter_configs)
21
+ config = ancestor.counter_configs.find { |c| c.record_name == name }
22
+ return config if config
23
+ end
24
+ end
14
25
  end
15
26
  end
16
27
  end
@@ -47,5 +47,10 @@ module Counter::Countable
47
47
  @counted_by ||= []
48
48
  @counted_by << config
49
49
  end
50
+
51
+ def inherited subclass
52
+ super
53
+ @counted_by.each { |c| subclass.add_counted_by c }
54
+ end
50
55
  end
51
56
  end
@@ -1,3 +1,3 @@
1
1
  module Counter
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counterwise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Lawrence
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-16 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails