activerecord-redundancy 0.3.0 → 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
  SHA1:
3
- metadata.gz: dbed46abce552a4b6c0bb975fbdeb45acd10c638
4
- data.tar.gz: ec046b565f92b938eb81e5b62c710a2878be44fe
3
+ metadata.gz: 805d47d5c17f296d16e84accecdc626f065bdc4d
4
+ data.tar.gz: 3b11790d8ee38706152a5dd597b8e54f47ad3d77
5
5
  SHA512:
6
- metadata.gz: 6c5dee5844b4784e2608e2fc1cbb07c1e87a0e3024db1f04a48e4d88d55ac0117809768824068930a74ca0dce57ef7d3abe042e276dda735c3a332dca2d49cb9
7
- data.tar.gz: c3983f7a81384676b34a5bc01684f96fc8fb476a272ca06ca611a168496c346564093e16302812237739fcaaea4f48f6f7b9ec56d1616a69b204e55755c77fd5
6
+ metadata.gz: 0c0fade28a7fe62ec5483d046fb7081c3712c7fd2ab1d7711b33f2300308cd40b6261cb8771daf86caf4fe3ff25dd9b5a44fa30d368c0e98bc4e3d9aed4dbbff
7
+ data.tar.gz: 0cc659dba8e5b7027bbc6658829aeb0e9d9bad14eb4a20ddf9780d209cec9397dea2c8012713f02ec1bc170d538fd338ef832934943a3f1faa77996af1bd131e
@@ -15,7 +15,7 @@ module Redundancy
15
15
  def after_save record
16
16
  return unless target
17
17
 
18
- get_value_from_source record
18
+ get_value_from_target record
19
19
  force_update_target record
20
20
  end
21
21
 
@@ -55,26 +55,24 @@ module Redundancy
55
55
  local_klass = klass
56
56
 
57
57
  reflection = get_reflection local_klass, association
58
- raise ArgumentError, "HasOne or HasMany reflection required" unless
59
- [:has_one, :has_many].include? reflection.macro
58
+ raise ArgumentError, "BelongsTo reflection required" unless
59
+ [:belongs_to].include? reflection.macro
60
60
 
61
61
  foreign_key = reflection.foreign_key
62
62
  remote_klass = reflection.klass
63
63
 
64
- inverse_association = get_inverse_association local_klass, remote_klass, options
65
-
66
64
  cache_method = options[:cache_method] || :"raw_#{attribute}"
67
65
 
68
- remote_klass.redundacies << UpdateMethod.new(
66
+ local_klass.redundacies << UpdateMethod.new(
69
67
  source: { attribute: cache_method },
70
- dest: { association: inverse_association, attribute: attribute },
71
- change_if: options[:change_if], klass: remote_klass
68
+ dest: { association: association, attribute: attribute },
69
+ change_if: options[:change_if], klass: local_klass
72
70
  )
73
71
 
74
- remote_klass.redundacies << UpdatePrevMethod.new(
72
+ local_klass.redundacies << UpdatePrevMethod.new(
75
73
  source: { attribute: cache_method },
76
- dest: { klass: local_klass, prev_id: foreign_key, attribute: attribute },
77
- change_if: foreign_key, klass: remote_klass
74
+ dest: { klass: remote_klass, prev_id: foreign_key, attribute: attribute },
75
+ change_if: foreign_key, klass: local_klass
78
76
  )
79
77
 
80
78
  end
@@ -1,3 +1,3 @@
1
1
  module Redundancy
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -3,4 +3,7 @@ class Post < ActiveRecord::Base
3
3
 
4
4
  cache_column :user, :name
5
5
  cache_column :user, :name, cache_column: :username
6
+
7
+ cache_method :user, :posts_count
8
+ cache_method :user, :posts_star
6
9
  end
@@ -4,9 +4,6 @@ class User < ActiveRecord::Base
4
4
 
5
5
  cache_column :account, :email
6
6
 
7
- cache_method :posts, :posts_count
8
- cache_method :posts, :posts_star
9
-
10
7
  def raw_posts_count
11
8
  posts.count
12
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-redundancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo