activerecord-pg_enum 1.0.3 → 1.0.4

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
  SHA256:
3
- metadata.gz: 552cd4fa6b85fd2002965150aca5e1f92f9752bfce9ab6628241dce0ef40406f
4
- data.tar.gz: b7915cd86940a3f2c5b2e9053712369f639073e22123b7a3a173f5403539aca1
3
+ metadata.gz: 3bfa16f0e78242be4cacc81ef2205192c4983374507b9f58c0a18703999b2585
4
+ data.tar.gz: 65f30e4358092187ef836e268abeb68399c8883db28a77ea052b99ca0bab6406
5
5
  SHA512:
6
- metadata.gz: 5b48750e4060fb131d1099ddf2198362e750901873e590ca488cb376e99ef30ab09c11857d9aa91ae9e0caea2903367a97bb34073f31f1ee1a9c4377cf9a27a5
7
- data.tar.gz: 66fc8ee9467a8dc96445e5e5f8fdab62b77ad4740086b17fa1d3a673415c657f3fdccf5cc09898f8153534951ccfa88b644359b7ebb2ccb81fd187e5465b4655
6
+ metadata.gz: 0a85929872c43348615853cf3464f8b4c62f16a4c21adf1d482b60dac1ffc6e8b28326f472d979b0b0bcf0e1beb547d517ed6ba30e6716e3ad9a83e3813b8bc2
7
+ data.tar.gz: 9d6ab586a0dc827ddd4e6c38b3a3e98f6d25047917ffbe79035a81f1d42af0f67257ed249f598ffd5e01328dc34b7026345c0a75ff40b4f8504febe711802ca7
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.4] - 2019-11-16
10
+ ### Fixed
11
+ - Dump enums declared in non-public schemas
12
+ - Fix missing `enum` method with using `change_table`
13
+
9
14
  ## [1.0.3] - 2019-10-13
10
15
  ### Fixed
11
16
  - Allow enum labels to contain spaces (@AndrewSpeed)
data/README.md CHANGED
@@ -133,6 +133,20 @@ class ContactInfo < ActiveRecord::Base
133
133
  end
134
134
  ```
135
135
 
136
+ Additionally, `enum` options are fully supported, for example
137
+ ```ruby
138
+ class User < ActiveRecord::Base
139
+ include PGEnum(status: %w[active inactive deleted], _prefix: 'user', _suffix: true)
140
+ end
141
+ ```
142
+
143
+ is equivalent to
144
+ ```ruby
145
+ class User < ActiveRecord::Base
146
+ enum status: { active: 'active', inactive: 'inactive', deleted: 'deleted' }, _prefix: 'user', _suffix: true
147
+ end
148
+ ```
149
+
136
150
  There's no technical reason why you couldn't detect enum columns at startup time and automatically do this wireup, but I feel that the benefit of self-documenting outweighs the convenience.
137
151
 
138
152
  ## Development
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.0.4)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.0.4)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.0.4)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.0.4)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.0.4)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activerecord-pg_enum (1.0.3)
4
+ activerecord-pg_enum (1.0.4)
5
5
  activerecord (>= 4.1.0)
6
6
  activesupport
7
7
  pg
@@ -66,7 +66,7 @@ GIT
66
66
  PATH
67
67
  remote: ..
68
68
  specs:
69
- activerecord-pg_enum (1.0.3)
69
+ activerecord-pg_enum (1.0.4)
70
70
  activerecord (>= 4.1.0)
71
71
  activesupport
72
72
  pg
@@ -3,6 +3,7 @@ module ActiveRecord
3
3
  register :table_definition do
4
4
  require "active_record/connection_adapters/postgresql_adapter"
5
5
  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition.include TableDefinition
6
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Table.include TableDefinition
6
7
  end
7
8
 
8
9
  module TableDefinition
@@ -5,6 +5,7 @@ module ActiveRecord
5
5
  register :table_definition do
6
6
  require "active_record/connection_adapters/postgresql_adapter"
7
7
  ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.include TableDefinition
8
+ ActiveRecord::ConnectionAdapters::PostgreSQL::Table.include TableDefinition
8
9
  end
9
10
  end
10
11
  end
@@ -14,12 +14,11 @@ module ActiveRecord
14
14
  # { "foo_type" => ["foo", "bar", "baz"] }
15
15
  def enum_types
16
16
  res = exec_query(<<-SQL.strip_heredoc, "SCHEMA")
17
- SELECT t.typname AS enum_name, array_agg(e.enumlabel ORDER BY e.enumsortorder) AS enum_value
17
+ SELECT n.nspname AS schema, t.typname AS enum_name, array_agg(e.enumlabel ORDER BY e.enumsortorder) AS enum_value
18
18
  FROM pg_type t
19
19
  JOIN pg_enum e ON t.oid = e.enumtypid
20
20
  JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
21
- WHERE n.nspname = 'public'
22
- GROUP BY enum_name
21
+ GROUP BY schema, enum_name
23
22
  SQL
24
23
 
25
24
  coltype = res.column_types["enum_value"]
@@ -31,10 +30,14 @@ module ActiveRecord
31
30
  proc { |values| coltype.type_cast(values) }
32
31
  end
33
32
 
34
- res.rows.inject({}) do |memo, (name, values)|
35
- memo[name] = deserialize.call(values)
36
- memo
37
- end
33
+ public_enums, custom = res.rows.partition { |schema, _, _| schema == "public" }
34
+ custom.map! { |schema, name, values| ["#{schema}.#{name}", values] }
35
+
36
+ public_enums
37
+ .map { |_, name, values| [name, values] }
38
+ .concat(custom)
39
+ .sort { |a, b| a.first <=> b.first }
40
+ .each_with_object({}) { |(name, values), memo| memo[name] = deserialize.call(values) }
38
41
  end
39
42
  end
40
43
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module PGEnum
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-pg_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Lassek
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-13 00:00:00.000000000 Z
11
+ date: 2019-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg