pg_taggable 0.2.0 → 0.3.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: a1558a67c0063eb3c5dacc16ee3e1420bf01d0c8987891c4da2d4f018721e55f
4
- data.tar.gz: 7b306fffd714f679925bb9ac870e8f8bcfa3c04e82c8a6bb4e4bb3a215bc430f
3
+ metadata.gz: d69f3ca42c6a0521d3c78f45b02aabd4ac22a2d2fc24a7292bff7cfffc55f954
4
+ data.tar.gz: 138eb372bdba0b11dd34d284c3c2d86afc81821140fb894c9b5787e5038f948d
5
5
  SHA512:
6
- metadata.gz: da505e59ecd6b6d24ef848b54c77702c97aab8c874dda0c5cd2953b7ad2206ac3a7f310153c8e02d58b1ee98d00e03ad580bed30c603a006e1fcb974007b45e6
7
- data.tar.gz: 97b98cbec2d7b32ccaedc4da5fb0500bf67190bfc97dba43134e0811a076922bc05f19c53896bc425404b3d17273b2090e32923110c8589710f20791a6a5e8b4
6
+ metadata.gz: 3e7f136c064d12711f2bc8432881976df03332e3882e57dd548f107c7ebcecf97adac266569c17aada7c3c4d3fc3118fc68036d95869745ff16d6f7cf5e9d162
7
+ data.tar.gz: a49d82d021946a137e0b3ed82a644c346804f042df6c9b921a41d49dcf7c5040b2f266d28e189654cc41a99433cf48d8316bb1b88ad83e0c361d11be05feb1d7
data/README.md CHANGED
@@ -135,7 +135,7 @@ Post.tags
135
135
  Post.tags.size
136
136
  # => 4
137
137
 
138
- Post.tags.distinct.size
138
+ Post.tags.select(:tag).distinct.size
139
139
  # => 3
140
140
 
141
141
  Post.tags.distinct.pluck(:tag)
@@ -145,6 +145,16 @@ Post.tags.group(:tag).count
145
145
  # => {"food"=>1, "travel"=>2, "technology"=>1}
146
146
  ```
147
147
 
148
+ #### distinct_#{tag_name}
149
+ Return an array of distinct tag records. It can be used for paging, count or other query.
150
+ ```Ruby
151
+ Post.distinct_tags
152
+ # => #<ActiveRecord::Relation [#<Post tag: "food", id: nil>, #<Post tag: "travel", id: nil>, #<Post tag: "technology", id: nil>]>
153
+
154
+ # equal to
155
+ Post.tags.select(:tag).distinct
156
+ ```
157
+
148
158
  #### uniq_#{tag_name}
149
159
  Return an array of unique tag strings.
150
160
  ```Ruby
@@ -34,7 +34,8 @@ module PgTaggable
34
34
  end
35
35
 
36
36
  scope name, -> { unscope(:where).from(select("UNNEST(#{table_name}.#{name}) AS tag"), table_name) }
37
- scope "uniq_#{name}", -> { public_send(name).distinct.pluck(:tag) }
37
+ scope "distinct_#{name}", -> { public_send(name).select(:tag).distinct }
38
+ scope "uniq_#{name}", -> { public_send("distinct_#{name}").pluck(:tag) }
38
39
  scope "count_#{name}", -> { public_send(name).group(:tag).count }
39
40
  taggable_attributes.keys.each do |key|
40
41
  scope key, ->(value, delimiter = ',') { where(key => value.is_a?(Array) ? value : value.split(delimiter)) }
@@ -1,3 +1,3 @@
1
1
  module PgTaggable
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_taggable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yi-Cyuan Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-20 00:00:00.000000000 Z
11
+ date: 2025-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails