action-store 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1b80762a43d47ccf77400612e0ec4840e1ab5f1
4
- data.tar.gz: 3cb456ca8cfc16739c8fbb3cb1a1feb81691e5cc
3
+ metadata.gz: 26301184cdf3a950440f0d0c565943abdc8db2ef
4
+ data.tar.gz: df943444fc2af10a16eb54a76ea0174035f05258
5
5
  SHA512:
6
- metadata.gz: 7de4c8111d3b7b92a14be4e041f079edce3dd011a81bcf2305f2c6fda7bf6ed8eeb8ad1173d25776a400458fbc9fdf1898ea7ed46b6bd8330cc0dcf673f78692
7
- data.tar.gz: 34686b4ceea1480b6aba7708be7e0ebd6a0dd26680edf79d7b4c85883c990826584d8b2a28eb44255f83b093d8d89e747e3eec6cad81ee8129dcd2c11810c960
6
+ metadata.gz: 3cde2d271a90c35adbf0bb7ec046536e2e2c86349ef71e3d647e46b4c0a16d644eb37e168fb16e1ce488e1e7e78053da05ca5f01e1896b4a0fb1ebabe1b56d25
7
+ data.tar.gz: ec5998dff944bac6dbd5ebba2717e902eff60dd760013e34ab062f23840d5f3cd8c342880e52b9e445abd9fda0fd55980084fae63c9bc2351cbb8ba48c2490fc
@@ -1,3 +1,26 @@
1
+ 0.3.0
2
+ -----
3
+
4
+ - Fix for action_store in Model that not named `User`.
5
+ - Fix has_many name when `User` model in a namespace.
6
+
7
+ For example:
8
+
9
+ ```rb
10
+ class Person
11
+ action_store :like, :post
12
+ end
13
+
14
+ module Blog
15
+ class User
16
+ action_store :like, :post
17
+ end
18
+ end
19
+
20
+ @post.like_by_people, @post.like_by_person_actions
21
+ @blog_user.like_post(@post), @post.like_by_blog_users, @post.like_by_blog_user_actions
22
+ ```
23
+
1
24
  0.2.2
2
25
  -----
3
26
 
@@ -33,8 +33,9 @@ module ActionStore
33
33
 
34
34
  def action_store(action_type, name, opts = {})
35
35
  opts ||= {}
36
- klass_name = opts[:class_name] || name
37
- target_klass = klass_name.to_s.classify.constantize
36
+ target_type = name
37
+ klass_name = opts[:class_name] || name.to_s.classify
38
+ target_klass = klass_name.constantize
38
39
  action_type = action_type.to_s
39
40
  if opts[:counter_cache] == true
40
41
  # @post.stars_count
@@ -50,7 +51,7 @@ module ActionStore
50
51
  action_name: name.to_s,
51
52
  action_type: action_type,
52
53
  target_klass: target_klass,
53
- target_type: klass_name,
54
+ target_type: target_klass.name,
54
55
  counter_cache: opts[:counter_cache],
55
56
  user_counter_cache: opts[:user_counter_cache]
56
57
  }
@@ -126,7 +127,7 @@ module ActionStore
126
127
  user_klass = self
127
128
 
128
129
  # user, person
129
- user_name = user_klass.name.underscore.singularize
130
+ user_name = user_klass.table_name.underscore.singularize
130
131
 
131
132
  # like_topic, follow_user
132
133
  full_action_name = [action_type, action_name].join('_')
@@ -150,7 +151,9 @@ module ActionStore
150
151
  }
151
152
 
152
153
  # User has_many :like_topic_actions
153
- user_klass.send :has_many, has_many_name, has_many_scope, class_name: 'Action'
154
+ user_klass.send :has_many, has_many_name, has_many_scope,
155
+ class_name: 'Action',
156
+ foreign_key: 'user_id'
154
157
  # User has_many :like_topics
155
158
  user_klass.send :has_many, has_many_through_name,
156
159
  through: has_many_name,
@@ -1,3 +1,3 @@
1
1
  module ActionStore
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee