activerecord-multirange 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +203 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +12 -0
- data/lib/activerecord-multirange/adapter.rb +25 -0
- data/lib/activerecord-multirange/oid/multi_range.rb +138 -0
- data/lib/activerecord-multirange/quoting.rb +25 -0
- data/lib/activerecord-multirange/schema_statements.rb +18 -0
- data/lib/activerecord-multirange/table_definition.rb +43 -0
- data/lib/activerecord-multirange/type_map.rb +17 -0
- data/lib/activerecord-multirange/version.rb +7 -0
- data/lib/activerecord-multirange.rb +25 -0
- data/sig/activerecord-multirange.rbs +6 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e8d7ad768c556f1c8d5ce716eb67367c6b6ace7de0ad656b9f7adf217e5ffa6c
|
4
|
+
data.tar.gz: fa4427fb5cded6f543bb918bc8f672245c71c0e7ab006cfd929c3a5765f6582d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8bda0778850f79cbaf2dfba6afd671f1f2b28379b735e4374c45008206afd6e30389da13ed570d53410c1a6322bf26d0f93ea1fc826274bdd813a029120d2a2
|
7
|
+
data.tar.gz: fa87bef90a08f6c88ceba3fa08d945ace2e3b5734bc498b955030bcc99136161e9b7cfedfab7d17ccf86dddb0cf408a4ed90b1c23f6be84c9a8e1ecb981dba1e
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
activerecord-multirange (0.1.0)
|
5
|
+
pg (>= 1)
|
6
|
+
rails (>= 6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (7.0.7)
|
12
|
+
actionpack (= 7.0.7)
|
13
|
+
activesupport (= 7.0.7)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (7.0.7)
|
17
|
+
actionpack (= 7.0.7)
|
18
|
+
activejob (= 7.0.7)
|
19
|
+
activerecord (= 7.0.7)
|
20
|
+
activestorage (= 7.0.7)
|
21
|
+
activesupport (= 7.0.7)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
net-imap
|
24
|
+
net-pop
|
25
|
+
net-smtp
|
26
|
+
actionmailer (7.0.7)
|
27
|
+
actionpack (= 7.0.7)
|
28
|
+
actionview (= 7.0.7)
|
29
|
+
activejob (= 7.0.7)
|
30
|
+
activesupport (= 7.0.7)
|
31
|
+
mail (~> 2.5, >= 2.5.4)
|
32
|
+
net-imap
|
33
|
+
net-pop
|
34
|
+
net-smtp
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
actionpack (7.0.7)
|
37
|
+
actionview (= 7.0.7)
|
38
|
+
activesupport (= 7.0.7)
|
39
|
+
rack (~> 2.0, >= 2.2.4)
|
40
|
+
rack-test (>= 0.6.3)
|
41
|
+
rails-dom-testing (~> 2.0)
|
42
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
43
|
+
actiontext (7.0.7)
|
44
|
+
actionpack (= 7.0.7)
|
45
|
+
activerecord (= 7.0.7)
|
46
|
+
activestorage (= 7.0.7)
|
47
|
+
activesupport (= 7.0.7)
|
48
|
+
globalid (>= 0.6.0)
|
49
|
+
nokogiri (>= 1.8.5)
|
50
|
+
actionview (7.0.7)
|
51
|
+
activesupport (= 7.0.7)
|
52
|
+
builder (~> 3.1)
|
53
|
+
erubi (~> 1.4)
|
54
|
+
rails-dom-testing (~> 2.0)
|
55
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
56
|
+
activejob (7.0.7)
|
57
|
+
activesupport (= 7.0.7)
|
58
|
+
globalid (>= 0.3.6)
|
59
|
+
activemodel (7.0.7)
|
60
|
+
activesupport (= 7.0.7)
|
61
|
+
activerecord (7.0.7)
|
62
|
+
activemodel (= 7.0.7)
|
63
|
+
activesupport (= 7.0.7)
|
64
|
+
activestorage (7.0.7)
|
65
|
+
actionpack (= 7.0.7)
|
66
|
+
activejob (= 7.0.7)
|
67
|
+
activerecord (= 7.0.7)
|
68
|
+
activesupport (= 7.0.7)
|
69
|
+
marcel (~> 1.0)
|
70
|
+
mini_mime (>= 1.1.0)
|
71
|
+
activesupport (7.0.7)
|
72
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
73
|
+
i18n (>= 1.6, < 2)
|
74
|
+
minitest (>= 5.1)
|
75
|
+
tzinfo (~> 2.0)
|
76
|
+
ast (2.4.2)
|
77
|
+
builder (3.2.4)
|
78
|
+
coderay (1.1.3)
|
79
|
+
concurrent-ruby (1.2.2)
|
80
|
+
crass (1.0.6)
|
81
|
+
date (3.3.3)
|
82
|
+
diff-lcs (1.5.0)
|
83
|
+
erubi (1.12.0)
|
84
|
+
globalid (1.1.0)
|
85
|
+
activesupport (>= 5.0)
|
86
|
+
i18n (1.14.1)
|
87
|
+
concurrent-ruby (~> 1.0)
|
88
|
+
json (2.6.3)
|
89
|
+
loofah (2.21.3)
|
90
|
+
crass (~> 1.0.2)
|
91
|
+
nokogiri (>= 1.12.0)
|
92
|
+
mail (2.8.1)
|
93
|
+
mini_mime (>= 0.1.1)
|
94
|
+
net-imap
|
95
|
+
net-pop
|
96
|
+
net-smtp
|
97
|
+
marcel (1.0.2)
|
98
|
+
method_source (1.0.0)
|
99
|
+
mini_mime (1.1.5)
|
100
|
+
minitest (5.19.0)
|
101
|
+
net-imap (0.3.7)
|
102
|
+
date
|
103
|
+
net-protocol
|
104
|
+
net-pop (0.1.2)
|
105
|
+
net-protocol
|
106
|
+
net-protocol (0.2.1)
|
107
|
+
timeout
|
108
|
+
net-smtp (0.3.3)
|
109
|
+
net-protocol
|
110
|
+
nio4r (2.5.9)
|
111
|
+
nokogiri (1.15.4-x86_64-darwin)
|
112
|
+
racc (~> 1.4)
|
113
|
+
parallel (1.23.0)
|
114
|
+
parser (3.2.2.1)
|
115
|
+
ast (~> 2.4.1)
|
116
|
+
pg (1.5.3)
|
117
|
+
pry (0.14.2)
|
118
|
+
coderay (~> 1.1)
|
119
|
+
method_source (~> 1.0)
|
120
|
+
racc (1.7.1)
|
121
|
+
rack (2.2.8)
|
122
|
+
rack-test (2.1.0)
|
123
|
+
rack (>= 1.3)
|
124
|
+
rails (7.0.7)
|
125
|
+
actioncable (= 7.0.7)
|
126
|
+
actionmailbox (= 7.0.7)
|
127
|
+
actionmailer (= 7.0.7)
|
128
|
+
actionpack (= 7.0.7)
|
129
|
+
actiontext (= 7.0.7)
|
130
|
+
actionview (= 7.0.7)
|
131
|
+
activejob (= 7.0.7)
|
132
|
+
activemodel (= 7.0.7)
|
133
|
+
activerecord (= 7.0.7)
|
134
|
+
activestorage (= 7.0.7)
|
135
|
+
activesupport (= 7.0.7)
|
136
|
+
bundler (>= 1.15.0)
|
137
|
+
railties (= 7.0.7)
|
138
|
+
rails-dom-testing (2.2.0)
|
139
|
+
activesupport (>= 5.0.0)
|
140
|
+
minitest
|
141
|
+
nokogiri (>= 1.6)
|
142
|
+
rails-html-sanitizer (1.6.0)
|
143
|
+
loofah (~> 2.21)
|
144
|
+
nokogiri (~> 1.14)
|
145
|
+
railties (7.0.7)
|
146
|
+
actionpack (= 7.0.7)
|
147
|
+
activesupport (= 7.0.7)
|
148
|
+
method_source
|
149
|
+
rake (>= 12.2)
|
150
|
+
thor (~> 1.0)
|
151
|
+
zeitwerk (~> 2.5)
|
152
|
+
rainbow (3.1.1)
|
153
|
+
rake (13.0.6)
|
154
|
+
regexp_parser (2.8.0)
|
155
|
+
rexml (3.2.5)
|
156
|
+
rspec (3.12.0)
|
157
|
+
rspec-core (~> 3.12.0)
|
158
|
+
rspec-expectations (~> 3.12.0)
|
159
|
+
rspec-mocks (~> 3.12.0)
|
160
|
+
rspec-core (3.12.2)
|
161
|
+
rspec-support (~> 3.12.0)
|
162
|
+
rspec-expectations (3.12.3)
|
163
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
164
|
+
rspec-support (~> 3.12.0)
|
165
|
+
rspec-mocks (3.12.5)
|
166
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
167
|
+
rspec-support (~> 3.12.0)
|
168
|
+
rspec-support (3.12.0)
|
169
|
+
rubocop (1.51.0)
|
170
|
+
json (~> 2.3)
|
171
|
+
parallel (~> 1.10)
|
172
|
+
parser (>= 3.2.0.0)
|
173
|
+
rainbow (>= 2.2.2, < 4.0)
|
174
|
+
regexp_parser (>= 1.8, < 3.0)
|
175
|
+
rexml (>= 3.2.5, < 4.0)
|
176
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
177
|
+
ruby-progressbar (~> 1.7)
|
178
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
179
|
+
rubocop-ast (1.28.1)
|
180
|
+
parser (>= 3.2.1.0)
|
181
|
+
ruby-progressbar (1.13.0)
|
182
|
+
thor (1.2.2)
|
183
|
+
timeout (0.4.0)
|
184
|
+
tzinfo (2.0.6)
|
185
|
+
concurrent-ruby (~> 1.0)
|
186
|
+
unicode-display_width (2.4.2)
|
187
|
+
websocket-driver (0.7.6)
|
188
|
+
websocket-extensions (>= 0.1.0)
|
189
|
+
websocket-extensions (0.1.5)
|
190
|
+
zeitwerk (2.6.11)
|
191
|
+
|
192
|
+
PLATFORMS
|
193
|
+
x86_64-darwin-22
|
194
|
+
|
195
|
+
DEPENDENCIES
|
196
|
+
activerecord-multirange!
|
197
|
+
pry
|
198
|
+
rake (~> 13.0)
|
199
|
+
rspec (~> 3.0)
|
200
|
+
rubocop (~> 1.21)
|
201
|
+
|
202
|
+
BUNDLED WITH
|
203
|
+
2.4.13
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Gustavo Warmling Teixeira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Activercord Multirange
|
2
|
+
|
3
|
+
This gem adds full suppport of [Postgress Multiranges](https://www.postgresql.org/docs/14/rangetypes.html#RANGETYPES-BUILTIN) types.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add activerecord-multirange
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install activerecord-multirange
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Initialize it
|
18
|
+
|
19
|
+
```
|
20
|
+
# config/initializers/activerecord_multirange
|
21
|
+
|
22
|
+
Activerecord::Multirange.add_multirange_column_type
|
23
|
+
```
|
24
|
+
|
25
|
+
### Migrations
|
26
|
+
|
27
|
+
All multirange types are available on the migrations
|
28
|
+
|
29
|
+
|
30
|
+
```
|
31
|
+
t.tsmultirange :column
|
32
|
+
t.tstzmultirange :column_tz
|
33
|
+
t.datemultirange :column_date
|
34
|
+
t.nummultirange :column_num
|
35
|
+
t.int8multirange :column_int8
|
36
|
+
t.int4multirange :column_int4
|
37
|
+
```
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gustavowt/activerecord-multirange.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Activerecord
|
4
|
+
module Multirange
|
5
|
+
module Adapter
|
6
|
+
def initialize_type_map(*params)
|
7
|
+
super
|
8
|
+
load_multirange_types
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_multirange_types
|
12
|
+
initializer = ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::TypeMapInitializer.new(type_map)
|
13
|
+
query = <<-QUERY
|
14
|
+
SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
|
15
|
+
FROM pg_type as t
|
16
|
+
JOIN pg_range as r ON oid = "rngmultitypid";
|
17
|
+
QUERY
|
18
|
+
|
19
|
+
execute_and_clear(query, "SCHEMA", []) do |records|
|
20
|
+
initializer.register_multirange_type(records)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Activerecord
|
4
|
+
module Multirange
|
5
|
+
module OID # :nodoc:
|
6
|
+
class MultiRange < ::ActiveModel::Type::Value # :nodoc:
|
7
|
+
Data = Struct.new(:ranges)
|
8
|
+
|
9
|
+
attr_reader :subtype, :type
|
10
|
+
|
11
|
+
def initialize(subtype, type = :multirange)
|
12
|
+
@subtype = subtype
|
13
|
+
@type = type
|
14
|
+
end
|
15
|
+
|
16
|
+
def deserialize(value)
|
17
|
+
case value
|
18
|
+
when ::String
|
19
|
+
cast_value(value)
|
20
|
+
when Data
|
21
|
+
type_cast_ranges(value.ranges, :deserialize)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def serialize(value)
|
26
|
+
if value.is_a?(::Array)
|
27
|
+
Data.new(type_cast_ranges(value, :serialize))
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def cast_value(value)
|
34
|
+
return nil if value.blank?
|
35
|
+
return value unless value.is_a?(::String)
|
36
|
+
|
37
|
+
ranges = scan_ranges(value)
|
38
|
+
|
39
|
+
ranges.map { |r| build_range(r) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(other)
|
43
|
+
other.is_a?(MultiRange) &&
|
44
|
+
other.subtype == subtype &&
|
45
|
+
other.type == type
|
46
|
+
end
|
47
|
+
|
48
|
+
def force_equality?(value)
|
49
|
+
value.is_a?(::Array)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def type_cast_ranges(ranges, method)
|
55
|
+
ranges.map do |range|
|
56
|
+
::Range.new(
|
57
|
+
@subtype.public_send(method, range.begin),
|
58
|
+
@subtype.public_send(method, range.end),
|
59
|
+
range.exclude_end?
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def scan_ranges(value)
|
65
|
+
value.scan(/\{*(\[|\()(.*?)?,(.*?)?(\]|\))/)
|
66
|
+
end
|
67
|
+
|
68
|
+
# When formatting the bound values of range types, PostgreSQL quotes
|
69
|
+
# the bound value using double-quotes in certain conditions. Within
|
70
|
+
# a double-quoted string, literal " and \ characters are themselves
|
71
|
+
# escaped. In input, PostgreSQL accepts multiple escape styles for "
|
72
|
+
# (either \" or "") but in output always uses "".
|
73
|
+
# See:
|
74
|
+
# * https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-IO
|
75
|
+
# * https://www.postgresql.org/docs/current/rowtypes.html#ROWTYPES-IO-SYNTAX
|
76
|
+
def unquote(value)
|
77
|
+
if value.start_with?('"') && value.end_with?('"')
|
78
|
+
unquoted_value = value[1..-2]
|
79
|
+
unquoted_value.gsub!('""', '"')
|
80
|
+
unquoted_value.gsub!("\\\\", "\\")
|
81
|
+
unquoted_value
|
82
|
+
else
|
83
|
+
value
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def parse_lower(value)
|
88
|
+
return infinity_value(value, negative: true) if ["", "-infinity"].include?(value)
|
89
|
+
|
90
|
+
@subtype.deserialize(unquote(value))
|
91
|
+
end
|
92
|
+
|
93
|
+
def parse_upper(value)
|
94
|
+
return infinity_value(value) if ["", "infinity"].include?(value)
|
95
|
+
|
96
|
+
@subtype.deserialize(unquote(value))
|
97
|
+
end
|
98
|
+
|
99
|
+
def extract_range_data(value)
|
100
|
+
from = parse_lower(value[1])
|
101
|
+
to = parse_upper(value[2])
|
102
|
+
|
103
|
+
{
|
104
|
+
exclude_start: value[0] == "(",
|
105
|
+
from: from,
|
106
|
+
to: to,
|
107
|
+
exclude_end: value[3] == ")"
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_range(value)
|
112
|
+
extracted = extract_range_data(value)
|
113
|
+
|
114
|
+
if !infinity?(extracted[:from]) && extracted[:exclude_start]
|
115
|
+
raise ArgumentError,
|
116
|
+
"The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
|
117
|
+
end
|
118
|
+
|
119
|
+
::Range.new(extracted[:from], extracted[:to], extracted[:exclude_end])
|
120
|
+
end
|
121
|
+
|
122
|
+
def infinity_value(_value, negative: false)
|
123
|
+
if @subtype.respond_to?(:infinity)
|
124
|
+
@subtype.infinity(negative: negative)
|
125
|
+
elsif negative
|
126
|
+
-::Float::INFINITY
|
127
|
+
else
|
128
|
+
::Float::INFINITY
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def infinity?(value)
|
133
|
+
value.respond_to?(:infinite?) && value.infinite?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Activerecord
|
4
|
+
module Multirange
|
5
|
+
module Quoting
|
6
|
+
def quote(value)
|
7
|
+
return quote(encode_multirange(value)) if value.is_a?(::Activerecord::Multirange::OID::MultiRange::Data)
|
8
|
+
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def type_cast(value)
|
13
|
+
return encode_multirange(value) if value.is_a?(::Activerecord::Multirange::OID::MultiRange::Data)
|
14
|
+
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def encode_multirange(range_data)
|
19
|
+
collection = range_data.ranges.map { |r| encode_range(r) }.join(",")
|
20
|
+
|
21
|
+
"{#{collection}}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Activerecord
|
4
|
+
module Multirange
|
5
|
+
module SchemaStatements
|
6
|
+
def native_database_types
|
7
|
+
super.merge({
|
8
|
+
tsmultirange: { name: "tsmultirange" },
|
9
|
+
datemultirange: { name: "datemultirange" },
|
10
|
+
tstzmultirange: { name: "tstzmultirange" },
|
11
|
+
nummultirange: { name: "nummultirange" },
|
12
|
+
int8multirange: { name: "int8multirange" },
|
13
|
+
int4multirange: { name: "int4multirange" }
|
14
|
+
})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Activerecord
|
4
|
+
module Multirange
|
5
|
+
module TableDefinition
|
6
|
+
def tsmultirange(*args, **options)
|
7
|
+
args.each do |name|
|
8
|
+
column(name, :tsmultirange, **options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def tstzmultirange(*args, **options)
|
13
|
+
args.each do |name|
|
14
|
+
column(name, :tstzmultirange, **options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def datemultirange(*args, **options)
|
19
|
+
args.each do |name|
|
20
|
+
column(name, :datemultirange, **options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def nummultirange(*args, **options)
|
25
|
+
args.each do |name|
|
26
|
+
column(name, :nummultirange, **options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def int8multirange(*args, **options)
|
31
|
+
args.each do |name|
|
32
|
+
column(name, :int8multirange, **options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def int4multirange(*args, **options)
|
37
|
+
args.each do |name|
|
38
|
+
column(name, :int4multirange, **options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "activerecord-multirange/oid/multi_range"
|
4
|
+
|
5
|
+
module Activerecord
|
6
|
+
module Multirange
|
7
|
+
module TypeMap
|
8
|
+
def register_multirange_type(records)
|
9
|
+
records.each do |row|
|
10
|
+
register_with_subtype(row["oid"], row["rngsubtype"].to_i) do |subtype|
|
11
|
+
Activerecord::Multirange::OID::MultiRange.new(subtype, row["typname"].to_sym)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "activerecord-multirange/version"
|
4
|
+
require "activerecord-multirange/adapter"
|
5
|
+
require "activerecord-multirange/quoting"
|
6
|
+
require "activerecord-multirange/schema_statements"
|
7
|
+
require "activerecord-multirange/table_definition"
|
8
|
+
require "activerecord-multirange/type_map"
|
9
|
+
require "active_record"
|
10
|
+
|
11
|
+
module Activerecord
|
12
|
+
module Multirange
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
def self.add_multirange_column_type
|
16
|
+
ActiveSupport.on_load(:active_record) do
|
17
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(Adapter)
|
18
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TypeMapInitializer.prepend(TypeMap)
|
19
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting.prepend(Quoting)
|
20
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements.prepend(SchemaStatements)
|
21
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.prepend(TableDefinition)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-multirange
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gustavo Warmling Teixeira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pg
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6'
|
41
|
+
description: Add PostgreSQL multiranges support
|
42
|
+
email:
|
43
|
+
- gustavowt@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- CHANGELOG.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/activerecord-multirange.rb
|
57
|
+
- lib/activerecord-multirange/adapter.rb
|
58
|
+
- lib/activerecord-multirange/oid/multi_range.rb
|
59
|
+
- lib/activerecord-multirange/quoting.rb
|
60
|
+
- lib/activerecord-multirange/schema_statements.rb
|
61
|
+
- lib/activerecord-multirange/table_definition.rb
|
62
|
+
- lib/activerecord-multirange/type_map.rb
|
63
|
+
- lib/activerecord-multirange/version.rb
|
64
|
+
- sig/activerecord-multirange.rbs
|
65
|
+
homepage: https://github.com/gustavowt/activerecord-multirange
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
homepage_uri: https://github.com/gustavowt/activerecord-multirange
|
70
|
+
source_code_uri: https://github.com/gustavowt/activerecord-multirange
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 2.6.0
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.4.10
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: PostgreSQL multiranges support
|
90
|
+
test_files: []
|