activerecord-collation 0.0.1 → 0.0.3

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: b08951bb81767158f2bb2182f468a658c763879c00f03a3173f7ed7fdb82dac4
4
- data.tar.gz: 63d6d457800220ab6962bf1d201febdcdfa1f4d71128fb4ed7db2a3c28109a48
3
+ metadata.gz: 4030382ddc37e42c183e0c718597e127a923626e33d4d20d1454ee79523b8980
4
+ data.tar.gz: eb336c834feab12f38a41283acf6c35ed379fcdb3a8ba55ed3b4b9887094debd
5
5
  SHA512:
6
- metadata.gz: f0c2107d45f7d6f5878494e91716e96f4853c6403c8c423eec5b0c61f1156567609417179ec4b2a39b6ef577a18466c0f9d6414b06b893eb4086e2159493e776
7
- data.tar.gz: 85bdcf26363009c077c105eac437ee6cd0d5f8710a5f927f66c3b9e247c919278017c40dd02dd31e0d7ff246e701593ead7b93f3bcff90031c9c415447917a73
6
+ metadata.gz: 566a00cac7e367909daa3b196f7b9dc7308151f176ed73d880746cb96066914126543ac693e4c5f2c6903a321d318967a5b4c9ca11138ac175a64a2b8629fc77
7
+ data.tar.gz: 54b78aadfe34f5a3da6df6494f62ddf38e1f46d4c81d7318614038ef1067a066a69dc34b55b04c6d4ed0fd92adb5d4bf470362ae48fdba0f4a0a0f571c38317b
data/README.md CHANGED
@@ -18,17 +18,17 @@ See [Postgres collation documentation](https://www.postgresql.org/docs/current/c
18
18
 
19
19
  ## Setup
20
20
 
21
- Add `activerecord-collations` to your dependencies. If you also want the `collate` class method on your model you also include the collation module:
21
+ Add `activerecord-collations` to your dependencies. Include the collation concern into your models to get access to the `collate` class method.
22
22
 
23
23
  ```ruby
24
24
  class ApplicationRecord < ActiveRecord::Base
25
- self.abstract_class = true
25
+ primary_abstract_class
26
26
 
27
27
  include ActiveRecord::Collation
28
28
  end
29
29
  ```
30
30
 
31
- The collate method creates an ARel expression for the column with a certain collation.
31
+ The `collate` method creates an ARel expression for the column with a certain collation.
32
32
 
33
33
  ```ruby
34
34
  scope :ordered, -> { order(collate(:title, "natural_#{I18n.locale}") }
@@ -45,11 +45,13 @@ Arel::Nodes::InfixOperation.new(
45
45
  )
46
46
  ```
47
47
 
48
- ## Testing
48
+ ## Development
49
49
 
50
- The Dummy application uses the gem so you can load the schema and run migrations there:
50
+ Run tests in this repository with `rake`. Migrations are exercised by running them in the dummy application.
51
51
 
52
52
  ```
53
53
  cd test/dummy
54
- RAILS_ENV=test rake db:migrate
54
+ rm -f db/schema.rb && RAILS_ENV=test bundle exec rake db:drop db:create db:migrate
55
+ cd ../../
56
+ bundle exec rake
55
57
  ```
@@ -10,15 +10,15 @@ module ActiveRecord
10
10
  collations = @connection.collations
11
11
  return unless collations.any?
12
12
 
13
- stream.puts
14
13
  collations.each do |row|
15
14
  stream.puts(
16
15
  " create_collation(#{row['collname'].inspect}, #{row['colllocale'].inspect})"
17
16
  )
18
17
  end
18
+ stream.puts
19
19
  end
20
20
 
21
- def trailer(stream)
21
+ def tables(stream)
22
22
  collations(stream)
23
23
  super
24
24
  end
@@ -18,14 +18,31 @@ module ActiveRecord
18
18
  end
19
19
 
20
20
  def collations
21
- internal_exec_query(<<~SQL, 'SCHEMA')
22
- SELECT
23
- pg_collation.collname,
24
- pg_collation.colllocale
25
- FROM pg_collation
26
- JOIN pg_namespace
27
- ON pg_collation.collnamespace = pg_namespace.oid AND pg_namespace.nspname = 'public'
28
- SQL
21
+ internal_exec_query(collations_sql, 'SCHEMA')
22
+ end
23
+
24
+ private
25
+
26
+ def collations_sql # rubocop:disable Metrics/MethodLength
27
+ if database_version >= 170_000
28
+ <<~SQL
29
+ SELECT
30
+ pg_collation.collname,
31
+ pg_collation.colllocale
32
+ FROM pg_collation
33
+ JOIN pg_namespace
34
+ ON pg_collation.collnamespace = pg_namespace.oid AND pg_namespace.nspname = 'public'
35
+ SQL
36
+ else
37
+ <<~SQL
38
+ SELECT
39
+ pg_collation.collname,
40
+ pg_collation.colliculocale AS colllocale
41
+ FROM pg_collation
42
+ JOIN pg_namespace
43
+ ON pg_collation.collnamespace = pg_namespace.oid AND pg_namespace.nspname = 'public'
44
+ SQL
45
+ end
29
46
  end
30
47
  end
31
48
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module Collation
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-collation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
@@ -24,7 +24,7 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
26
  description: " Adds methods like create_collation to manage collations in your Ruby
27
- on Rials project.\n"
27
+ on Rails project.\n"
28
28
  email:
29
29
  - manfred@fngtps.com
30
30
  executables: []
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.7.0
61
+ rubygems_version: 4.0.10
62
62
  specification_version: 4
63
63
  summary: Collation support for Active Record.
64
64
  test_files: []