acts-as-taggable-array-on 0.2.0 → 0.2.1

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: 080185fe1e3f5faf0542afb12518cc740f669098
4
- data.tar.gz: f7647f52be3c7c26f2697e14e1bd35e53cdb1014
3
+ metadata.gz: d434088f73e146383bb7123506e8d4b7d89e1706
4
+ data.tar.gz: f046f099ce1f5cad0497278767661d8f73cceda7
5
5
  SHA512:
6
- metadata.gz: 1540c2ee1a7b21a74065186193f142b41f7ca080d7e35229b39b2b706e018e8ed4614327b3379f6746933a121c3d2c20382e3f3b1a9f03f943226fc355c427d7
7
- data.tar.gz: 26607de532bacdba54128430953e060c03bb282b5cd9c1284c039e78b385624d5c4cd627add5ae46050442f6653036dbae484b7c74fb157c94d0a80c2221f966
6
+ metadata.gz: a80faa85b005eab8e8bcf87d1ce09f4c319a912c0e1b5e593318aca0f9e72ea8b19544d4213df4855ce11bf4244f45ba77aeb46803acdcee639015cb9ec77537
7
+ data.tar.gz: 63b9d87fc308d757bad3b99178c2d454828ecd54b3e086ebd7de464e3765750acc61aaa4e9ef9919469a7f87bc68be90f2009b9320eaa4c2e76a05bc7fa9ec36
data/README.md CHANGED
@@ -122,6 +122,12 @@ Tag cloud calculation uses subquery internally. To add scopes to the query, use
122
122
  User.tags_cloud { where name: ['ken', 'tom'] }
123
123
  ```
124
124
 
125
+ To handle the result tags named 'tag' and 'count', prepend scopes.
126
+
127
+ ```ruby
128
+ User.where('tag like ?', 'aws%').limit(10).order('count desc').tags_cloud { where name: ['ken', 'tom'] }
129
+ ```
130
+
125
131
  ### All Tags
126
132
 
127
133
  Can get all tags easily.
@@ -138,10 +144,15 @@ As the same to tag cloud calculation, you can use block to add scopes to the que
138
144
  User.all_tags { where name: ['ken', 'tom'] }
139
145
  ```
140
146
 
147
+ To handle the result tags named 'tag', prepend scopes.
148
+
149
+ ```ruby
150
+ User.where('tag like ?', 'aws%').all_tags { where name: ['ken', 'tom'] }
151
+ ```
141
152
 
142
153
  ## Contributing
143
154
 
144
- 1. Fork it ( http://github.com/<my-github-username>/acts-as-taggable-array-on/fork )
155
+ 1. Fork it ( http://github.com/tmiyamon/acts-as-taggable-array-on/fork )
145
156
  2. Create your feature branch (`git checkout -b my-new-feature`)
146
157
  3. Commit your changes (`git commit -am 'Add some feature'`)
147
158
  4. Push to the branch (`git push origin my-new-feature`)
@@ -15,17 +15,17 @@ module ActsAsTaggableArrayOn
15
15
 
16
16
  self.class.class_eval do
17
17
  define_method :"all_#{tag_name}" do |options = {}, &block|
18
- query_scope = all
19
- query_scope = query_scope.merge(instance_eval(&block)) if block
18
+ subquery_scope = unscoped.select("unnest(#{table_name}.#{tag_name}) as tag").uniq
19
+ subquery_scope = subquery_scope.instance_eval(&block) if block
20
20
 
21
- query_scope.uniq.pluck("unnest(#{table_name}.#{tag_name})")
21
+ from(subquery_scope).pluck('tag')
22
22
  end
23
23
 
24
24
  define_method :"#{tag_name}_cloud" do |options = {}, &block|
25
- query_scope = select("unnest(#{table_name}.#{tag_name}) as tag")
26
- query_scope = query_scope.merge(instance_eval(&block)) if block
25
+ subquery_scope = unscoped.select("unnest(#{table_name}.#{tag_name}) as tag")
26
+ subquery_scope = subquery_scope.instance_eval(&block) if block
27
27
 
28
- from(query_scope).group('tag').order('tag').pluck('tag, count(*)')
28
+ from(subquery_scope).group('tag').order('tag').pluck('tag, count(*) as count')
29
29
  end
30
30
  end
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsTagPgarray
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -56,6 +56,14 @@ describe ActsAsTaggableArrayOn::Taggable do
56
56
  it "returns filtered tags for tag_name with block" do
57
57
  expect(User.all_colors{where(name: ["Ken", "Joe"])}).to match_array([@user2,@user3].map(&:colors).flatten.uniq)
58
58
  end
59
+
60
+ it "returns filtered tags for tag_name with prepended scope" do
61
+ expect(User.where('tag like ?', 'bl%').all_colors).to match_array([@user1,@user2,@user3].map(&:colors).flatten.uniq.select{|name| name.start_with? 'bl'})
62
+ end
63
+
64
+ it "returns filtered tags for tag_name with prepended scope and bock" do
65
+ expect(User.where('tag like ?', 'bl%').all_colors{where(name: ["Ken", "Joe"])}).to match_array([@user2,@user3].map(&:colors).flatten.uniq.select{|name| name.start_with? 'bl'})
66
+ end
59
67
  end
60
68
 
61
69
  describe "#colors_cloud" do
@@ -70,6 +78,18 @@ describe ActsAsTaggableArrayOn::Taggable do
70
78
  [@user2,@user3].map(&:colors).flatten.group_by(&:to_s).map{|k,v| [k,v.count]}
71
79
  )
72
80
  end
81
+
82
+ it "returns filtered tag cloud for tag_name with prepended scope" do
83
+ expect(User.where('tag like ?', 'bl%').colors_cloud).to match_array(
84
+ [@user1,@user2,@user3].map(&:colors).flatten.group_by(&:to_s).map{|k,v| [k,v.count]}.select{|name,count| name.start_with? 'bl'}
85
+ )
86
+ end
87
+
88
+ it "returns filtered tag cloud for tag_name with prepended scope and block" do
89
+ expect(User.where('tag like ?', 'bl%').colors_cloud{where(name: ["Ken", "Joe"])}).to match_array(
90
+ [@user2,@user3].map(&:colors).flatten.group_by(&:to_s).map{|k,v| [k,v.count]}.select{|name,count| name.start_with? 'bl'}
91
+ )
92
+ end
73
93
  end
74
94
 
75
95
  describe "with complex scope" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-array-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Miyamoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-03 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord