pg_tags_on 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: 01ed743033dfd067912e4ffe4878cf719e87d920220c656318eb4a780c4f9196
4
- data.tar.gz: 03f9ea30352f7ced5e6c5b87d343c410a8d6522d7475ee34685c53870a9952f3
3
+ metadata.gz: 066f0a47a35f600a5f4048b2bc4f53348f546778e4be9979d8ba821036f59b78
4
+ data.tar.gz: bbbc6d9b19187f32c2dcb9be084694e52d9267e4303288dd503ea0046201d709
5
5
  SHA512:
6
- metadata.gz: 118f18d7f3dc1e5e7809b03ec03a107499b8be1e66f225b3b40d819f55e95e98e7deaf469fe4f8ad29cd790962082b2a314081ac266009d1d4bc65cf9fd94d86
7
- data.tar.gz: 7771926231fc5013bce1e01938aeef247e9b602b6308dbfbfdf29d10b6d111bb8743a4fbc0bd97c6d0ad4daf773bb9efc0edcedcaa166e74ea7b8096d32cca12
6
+ metadata.gz: 313542b894433383a4058a669eef4e9e06bf1a3417580efa24765330b9b3e0254842ae7a22de1a05ab1c7d515388c5302d1dda2ca3e65d621598cc22b74de19f
7
+ data.tar.gz: 2990fc830e4a250e52c4dc710d9b711cb1a62b9ba6f4ef38be521e3cfbcd02471937b253dc9b63516bb83709eca820583b704ffe29213a4c750d3f578640f54b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.0 ( 2020-04-15)
2
+
3
+ * apply PR for gem versions
4
+ * fixed Arel deprecation warning
5
+ * changed validation param names
6
+
1
7
  ## 0.2.0 ( 2020-09-02)
2
8
 
3
9
  * Added support for multiple tags creation and deletion
data/README.md CHANGED
@@ -42,7 +42,7 @@ Or install it yourself as:
42
42
  ## Usage
43
43
  ### ActiveRecord model setup
44
44
 
45
- One or multiple columns can be specified:
45
+ One or multiple columns that store tags can be specified:
46
46
 
47
47
  ```ruby
48
48
  class Entity < ActiveRecord::Base
@@ -51,7 +51,7 @@ class Entity < ActiveRecord::Base
51
51
  end
52
52
  ```
53
53
 
54
- For ```jsonb[]``` columns you'll have to specify the key for the tag value. If you store multiple attributes in the objects then you must set also ```has_attributes: true```.
54
+ In ```jsonb[]``` columns, by default each tag is stored as an object with a single key. For example ```{"tag": "rubygems"}```. If you store multiple attributes in the objects, then you must set also ```has_attributes: true```.
55
55
 
56
56
  ```ruby
57
57
  class Entity < ActiveRecord::Base
@@ -65,7 +65,7 @@ Maximum number of tags and maximum tag length can be validated. Errors will be i
65
65
 
66
66
  ```ruby
67
67
  class Entity < ActiveRecord::Base
68
- pg_tags_on :tags, limit: 10, tag_length: 50 # limit to 10 tags and 50 chars. per tag.
68
+ pg_tags_on :tags, limit: 10, length: 50 # limit to 10 tags and 50 chars. per tag.
69
69
  end
70
70
  ```
71
71
 
@@ -12,7 +12,7 @@ module PgTagsOn
12
12
 
13
13
  pg_tags_on_init_model unless @pg_tags_on_init_model
14
14
  pg_tags_on_settings[name] = options.deep_symbolize_keys
15
- validates(name, 'pg_tags_on/tags': true) if %i[limit tag_length].any? { |k| options[k] }
15
+ validates(name, 'pg_tags_on/tags': true) if %i[limit length].any? { |k| options[k] }
16
16
  instance_eval <<-RUBY, __FILE__, __LINE__ + 1
17
17
  scope :#{name}, -> { PgTagsOn::Repository.new(self, "#{name}") }
18
18
  RUBY
@@ -5,7 +5,7 @@ module PgTagsOn
5
5
  # Operatons for 'jsonb[]' column type
6
6
  class ArrayJsonbRepository < ArrayRepository
7
7
  def create(tag_or_tags, returning: nil)
8
- tags = normalize_tags(Array.wrap(tag_or_tags))
8
+ tags = normalize_tags(tag_or_tags)
9
9
 
10
10
  super(tags, returning: returning)
11
11
  end
@@ -24,13 +24,14 @@ module PgTagsOn
24
24
  end
25
25
 
26
26
  def delete(tag_or_tags, returning: nil)
27
- tags = Array.wrap(tag_or_tags)
28
- normalized_tags = normalize_tags(tags)
29
- rel = klass.where(column_name => PgTagsOn.query_class.any(tags))
27
+ tags = normalize_tags(tag_or_tags)
30
28
  sm = build_tags_select_manager
31
- normalized_tags.each do |tag|
29
+
30
+ tags.each do |tag|
32
31
  sm.where(arel_infix_operation('@>', Arel.sql('tag'), bind_for(tag.to_json, nil)).not)
33
32
  end
33
+
34
+ rel = klass.where(column_name => PgTagsOn.query_class.any(tag_or_tags))
34
35
  value = arel_function('array', sm)
35
36
 
36
37
  perform_update(rel, { column_name => value }, returning: returning)
@@ -48,7 +49,9 @@ module PgTagsOn
48
49
  .as('_tags'))
49
50
  end
50
51
 
51
- def normalize_tags(tags)
52
+ def normalize_tags(tag_or_tags)
53
+ tags = Array.wrap(tag_or_tags)
54
+
52
55
  return tags unless key?
53
56
 
54
57
  tags.map do |tag|
@@ -42,8 +42,8 @@ module PgTagsOn
42
42
  all.count
43
43
  end
44
44
 
45
- def create(tag, returning: nil)
46
- value = arel_array_cat(arel_column, bind_for(Array.wrap(tag)))
45
+ def create(tag_or_tags, returning: nil)
46
+ value = arel_array_cat(arel_column, bind_for(Array.wrap(tag_or_tags)))
47
47
 
48
48
  perform_update(klass, { column_name => value }, returning: returning)
49
49
  end
@@ -65,7 +65,7 @@ module PgTagsOn
65
65
 
66
66
  stmt = ::Arel::UpdateManager.new
67
67
  stmt.table(arel_table)
68
- stmt.key = klass.arel_attribute(klass.primary_key)
68
+ stmt.key = arel_table[klass.primary_key]
69
69
  stmt.take(rel.arel.limit)
70
70
  stmt.offset(rel.arel.offset)
71
71
  stmt.order(*rel.arel.orders)
@@ -4,7 +4,7 @@ module PgTagsOn
4
4
  # Validator for max. number of tags and max. tag length.
5
5
  #
6
6
  # class Entity
7
- # pg_tags_on :tags, limit: 20, tag_length: 64
7
+ # pg_tags_on :tags, limit: 20, length: 64
8
8
  # end
9
9
  #
10
10
  class TagsValidator < ActiveModel::EachValidator
@@ -15,7 +15,7 @@ module PgTagsOn
15
15
 
16
16
  def validate_each(record, attribute, value)
17
17
  validate_limit(record, attribute, value)
18
- validate_tag_length(record, attribute, value)
18
+ validate_length(record, attribute, value)
19
19
 
20
20
  record.errors.present?
21
21
  end
@@ -31,8 +31,8 @@ module PgTagsOn
31
31
  record.errors.add(attr, "size exceeded #{limit} tags") if value.size > limit.to_i
32
32
  end
33
33
 
34
- def validate_tag_length(record, attr, value)
35
- limit, key = klass.pg_tags_on_options_for(attr).values_at(:tag_length, :key)
34
+ def validate_length(record, attr, value)
35
+ limit, key = klass.pg_tags_on_options_for(attr).values_at(:length, :key)
36
36
  return true unless limit && value
37
37
 
38
38
  value.map! { |tag| tag.with_indifferent_access.dig(*key) } if key
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgTagsOn
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_tags_on
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
  - Catalin Marinescu
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-02 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -122,7 +122,7 @@ metadata:
122
122
  changelog_uri: https://github.com/cata-m/pg_tags_on/blob/master/CHANGELOG.md
123
123
  homepage_uri: http://github.com/cata-m/pg_tags_on
124
124
  source_code_uri: https://github.com/cata-m/pg_tags_on
125
- post_install_message:
125
+ post_install_message:
126
126
  rdoc_options: []
127
127
  require_paths:
128
128
  - lib
@@ -137,8 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.0.6
141
- signing_key:
140
+ rubygems_version: 3.0.9
141
+ signing_key:
142
142
  specification_version: 4
143
143
  summary: Query and manage tags stored in a Postgresql column.
144
144
  test_files: []