torque-postgresql 0.2.14 → 0.2.15
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 +4 -4
- data/lib/torque/postgresql/adapter/database_statements.rb +25 -19
- data/lib/torque/postgresql/attributes/builder/enum.rb +13 -6
- data/lib/torque/postgresql/inheritance.rb +2 -0
- data/lib/torque/postgresql/schema_dumper.rb +2 -5
- data/lib/torque/postgresql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b1a0c063511d941ef67b0aa104ef7163aa9134
|
4
|
+
data.tar.gz: 93421afa177dde965f10e0458d258757956d0983
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2224a3d965215d7ac5a7b7bb43d552728747ead30aa5095288e8b861ca6f370f86868d4ff1da33ef7f82626ad214b075f80efc45d99cbfe3845b9d97f96a6201
|
7
|
+
data.tar.gz: c0eb5be0217a014cc8dcfc6a8c02fd4b4c4ed47cb62c0f03b8cf4c35cada960851b5984cfb8860adcdd76c40a716750f697772b133177196a834ced0d1d41717
|
@@ -90,26 +90,32 @@ module Torque
|
|
90
90
|
|
91
91
|
# Gets a list of user defined types.
|
92
92
|
# You can even choose the +category+ filter
|
93
|
-
def user_defined_types(
|
94
|
-
category_condition =
|
93
|
+
def user_defined_types(*categories)
|
94
|
+
category_condition = categories.present? \
|
95
|
+
? "AND t.typtype IN ('#{categories.join("', '")}')" \
|
96
|
+
: "AND t.typtype NOT IN ('b', 'd')"
|
97
|
+
|
95
98
|
select_all(<<-SQL, 'SCHEMA').rows.to_h
|
96
|
-
SELECT
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
FROM
|
101
|
-
|
102
|
-
WHERE
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
99
|
+
SELECT t.typname AS name,
|
100
|
+
CASE t.typtype
|
101
|
+
WHEN 'e' THEN 'enum'
|
102
|
+
END AS type
|
103
|
+
FROM pg_type t
|
104
|
+
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
105
|
+
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
106
|
+
#{category_condition}
|
107
|
+
AND NOT EXISTS(
|
108
|
+
SELECT 1
|
109
|
+
FROM pg_catalog.pg_type el
|
110
|
+
WHERE el.oid = t.typelem
|
111
|
+
AND el.typarray = t.oid
|
112
|
+
)
|
113
|
+
AND (t.typrelid = 0 OR (
|
114
|
+
SELECT c.relkind = 'c'
|
115
|
+
FROM pg_catalog.pg_class c
|
116
|
+
WHERE c.oid = t.typrelid
|
117
|
+
))
|
118
|
+
ORDER BY t.typtype DESC
|
113
119
|
SQL
|
114
120
|
end
|
115
121
|
|
@@ -4,7 +4,7 @@ module Torque
|
|
4
4
|
module Builder
|
5
5
|
class Enum
|
6
6
|
|
7
|
-
attr_accessor :klass, :attribute, :subtype, :options, :values
|
7
|
+
attr_accessor :klass, :attribute, :subtype, :options, :values, :enum_module
|
8
8
|
|
9
9
|
# Start a new builder of methods for composite values on
|
10
10
|
# ActiveRecord::Base
|
@@ -74,9 +74,14 @@ module Torque
|
|
74
74
|
|
75
75
|
# Create all methods needed
|
76
76
|
def build
|
77
|
+
@enum_module = Module.new
|
78
|
+
|
77
79
|
plural
|
78
80
|
text
|
79
81
|
all_values
|
82
|
+
|
83
|
+
klass.include enum_module
|
84
|
+
klass.extend enum_module::ClassMethods
|
80
85
|
end
|
81
86
|
|
82
87
|
private
|
@@ -98,7 +103,8 @@ module Torque
|
|
98
103
|
def plural
|
99
104
|
attr = attribute
|
100
105
|
enum_klass = subtype.klass
|
101
|
-
|
106
|
+
enum_module.const_set('ClassMethods', Module.new)
|
107
|
+
enum_module::ClassMethods.module_eval do
|
102
108
|
# def self.statuses() statuses end
|
103
109
|
define_method(attr.pluralize) do
|
104
110
|
enum_klass.values
|
@@ -113,7 +119,7 @@ module Torque
|
|
113
119
|
|
114
120
|
# def self.statuses_options() statuses_texts.zip(statuses) end
|
115
121
|
define_method(attr.pluralize + '_options') do
|
116
|
-
enum_klass.values
|
122
|
+
public_send(attr.pluralize + '_texts').zip(enum_klass.values)
|
117
123
|
end
|
118
124
|
end
|
119
125
|
end
|
@@ -122,7 +128,7 @@ module Torque
|
|
122
128
|
# the model scope
|
123
129
|
def text
|
124
130
|
attr = attribute
|
125
|
-
|
131
|
+
enum_module.module_eval do
|
126
132
|
# def status_text() status.text('status', self) end
|
127
133
|
define_method("#{attr}_text") { send(attr).text(attr, self) }
|
128
134
|
end
|
@@ -133,10 +139,11 @@ module Torque
|
|
133
139
|
def all_values
|
134
140
|
attr = attribute
|
135
141
|
vals = values_methods
|
136
|
-
klass
|
142
|
+
model_klass = klass
|
143
|
+
enum_module.module_eval do
|
137
144
|
vals.each do |val, list|
|
138
145
|
# scope :disabled, -> { where(status: 'disabled') }
|
139
|
-
scope list[0], -> { where(attr => val) }
|
146
|
+
model_klass.scope list[0], -> { where(attr => val) }
|
140
147
|
|
141
148
|
# def disabled? status.disabled? end
|
142
149
|
define_method(list[1]) { send(attr).public_send("#{val}?") }
|
@@ -39,6 +39,8 @@ module Torque
|
|
39
39
|
|
40
40
|
# Check if the model's table depends on any inheritance
|
41
41
|
def physically_inherited?
|
42
|
+
return false unless connected?
|
43
|
+
|
42
44
|
@physically_inherited ||= connection.schema_cache.dependencies(
|
43
45
|
defined?(@table_name) ? @table_name : decorated_table_name,
|
44
46
|
).present?
|
@@ -59,14 +59,11 @@ module Torque
|
|
59
59
|
|
60
60
|
# Dump user defined types like enum
|
61
61
|
def user_defined_types(stream)
|
62
|
-
types = @connection.user_defined_types
|
62
|
+
types = @connection.user_defined_types('e')
|
63
63
|
return unless types.any?
|
64
64
|
|
65
65
|
stream.puts " # These are user-defined types used on this database"
|
66
|
-
types.each
|
67
|
-
raise StandardError, "User-defined type '#{name}' cannot be dumped!" if type.blank?
|
68
|
-
send(type.to_sym, name, stream)
|
69
|
-
end
|
66
|
+
types.each { |name, type| send(type.to_sym, name, stream) }
|
70
67
|
stream.puts
|
71
68
|
rescue => e
|
72
69
|
stream.puts "# Could not dump user-defined types because of following #{e.class}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torque-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|