Skip to content

Commit 490d95c

Browse files
author
Carlos Silva
committed
New version docs and final adjustments
1 parent 6ff1fbd commit 490d95c

File tree

8 files changed

+55
-12
lines changed

8 files changed

+55
-12
lines changed

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
To install torque-postgresql you need to add the following to your Gemfile:
2121
```ruby
22-
gem 'torque-postgresql', '~> 0.2'
22+
gem 'torque-postgresql', '~> 1.0'
2323
```
2424

2525
Also, run:
@@ -39,13 +39,26 @@ These are the currently available features:
3939

4040
* [Configuring](https://github.com/crashtech/torque-postgresql/wiki/Configuring)
4141

42+
## Core Extensions
43+
44+
* [Range](https://github.com/crashtech/torque-postgresql/wiki/Range)
45+
4246
## Data types
4347

4448
* [Enum](https://github.com/crashtech/torque-postgresql/wiki/Enum)
49+
* [EnumSet](https://github.com/crashtech/torque-postgresql/wiki/EnumSet)
4550
* [Interval](https://github.com/crashtech/torque-postgresql/wiki/Interval)
51+
* [Date/Time Range](https://github.com/crashtech/torque-postgresql/wiki/Date-Time-Range)
52+
* [Box](https://github.com/crashtech/torque-postgresql/wiki/Box)
53+
* [Circle](https://github.com/crashtech/torque-postgresql/wiki/Circle)
54+
* [Line](https://github.com/crashtech/torque-postgresql/wiki/Line)
55+
* [Segment](https://github.com/crashtech/torque-postgresql/wiki/Segment)
4656

4757
## Querying
4858

59+
* [Arel](https://github.com/crashtech/torque-postgresql/wiki/Arel)
60+
* [Has Many](https://github.com/crashtech/torque-postgresql/wiki/Has-Many)
61+
* [Belongs to Many](https://github.com/crashtech/torque-postgresql/wiki/Belongs-to-Many)
4962
* [Dynamic Attributes](https://github.com/crashtech/torque-postgresql/wiki/Dynamic-Attributes)
5063
* [Distinct On](https://github.com/crashtech/torque-postgresql/wiki/Distinct-On)
5164
* [Auxiliary Statements](https://github.com/crashtech/torque-postgresql/wiki/Auxiliary-Statements)

lib/torque/postgresql/arel/nodes.rb

+4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ module Arel
44
module Nodes
55

66
class Cast < ::Arel::Nodes::Binary
7+
include ::Arel::Expressions
78
include ::Arel::Predications
9+
include ::Arel::AliasPredication
10+
include ::Arel::OrderPredications
11+
include ::Arel::Math
812

913
def initialize(left, right, array = false)
1014
right = right.to_s

lib/torque/postgresql/attributes/builder/period.rb

+15
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,13 @@ def build_singleton_methods
209209

210210
klass.scope method_names[:containing], ->(value) do
211211
value = arel_table[value] if value.is_a?(Symbol)
212+
value = ::Arel.sql(connection.quote(value)) unless value.respond_to?(:cast)
212213
where(builder.arel_attribute.contains(value))
213214
end
214215

215216
klass.scope method_names[:not_containing], ->(value) do
216217
value = arel_table[value] if value.is_a?(Symbol)
218+
value = ::Arel.sql(connection.quote(value)) unless value.respond_to?(:cast)
217219
where.not(builder.arel_attribute.contains(value))
218220
end
219221

@@ -224,6 +226,8 @@ def build_singleton_methods
224226
value = ::Arel.sql(connection.quote(value))
225227
right = ::Arel.sql(connection.quote(right))
226228
value = builder.arel_convert_to_type(value, right)
229+
elsif !value.respond_to?(:cast)
230+
value = ::Arel.sql(connection.quote(value))
227231
end
228232

229233
where(builder.arel_attribute.overlaps(value))
@@ -236,6 +240,8 @@ def build_singleton_methods
236240
value = ::Arel.sql(connection.quote(value))
237241
right = ::Arel.sql(connection.quote(right))
238242
value = builder.arel_convert_to_type(value, right)
243+
elsif !value.respond_to?(:cast)
244+
value = ::Arel.sql(connection.quote(value))
239245
end
240246

241247
where.not(builder.arel_attribute.overlaps(value))
@@ -276,6 +282,7 @@ def build_singleton_methods
276282
if threshold.present?
277283
klass.scope method_names[:real_containing], ->(value) do
278284
value = arel_table[value] if value.is_a?(Symbol)
285+
value = ::Arel.sql(connection.quote(value)) unless value.respond_to?(:cast)
279286
where(builder.real_arel_attribute.contains(value))
280287
end
281288

@@ -286,6 +293,8 @@ def build_singleton_methods
286293
value = ::Arel.sql(connection.quote(value))
287294
right = ::Arel.sql(connection.quote(right))
288295
value = builder.arel_convert_to_type(value, right)
296+
elsif !value.respond_to?(:cast)
297+
value = ::Arel.sql(connection.quote(value))
289298
end
290299

291300
where(builder.real_arel_attribute.overlaps(value))
@@ -327,11 +336,13 @@ def build_singleton_methods
327336
unless type.eql?(:daterange)
328337
klass.scope method_names[:containing_date], ->(value) do
329338
value = arel_table[value] if value.is_a?(Symbol)
339+
value = ::Arel.sql(connection.quote(value)) unless value.respond_to?(:cast)
330340
where(builder.arel_daterange.contains(value))
331341
end
332342

333343
klass.scope method_names[:not_containing_date], ->(value) do
334344
value = arel_table[value] if value.is_a?(Symbol)
345+
value = ::Arel.sql(connection.quote(value)) unless value.respond_to?(:cast)
335346
where.not(builder.arel_daterange.contains(value))
336347
end
337348

@@ -342,6 +353,8 @@ def build_singleton_methods
342353
value = ::Arel.sql(connection.quote(value))
343354
right = ::Arel.sql(connection.quote(right))
344355
value = builder.arel_convert_to_type(value, right, :daterange)
356+
elsif !value.respond_to?(:cast)
357+
value = ::Arel.sql(connection.quote(value))
345358
end
346359

347360
where(builder.arel_daterange.overlaps(value))
@@ -354,6 +367,8 @@ def build_singleton_methods
354367
value = ::Arel.sql(connection.quote(value))
355368
right = ::Arel.sql(connection.quote(right))
356369
value = builder.arel_convert_to_type(value, right, :daterange)
370+
elsif !value.respond_to?(:cast)
371+
value = ::Arel.sql(connection.quote(value))
357372
end
358373

359374
where.not(builder.arel_daterange.overlaps(value))

lib/torque/postgresql/attributes/enum_set.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class EnumSetError < Enum::EnumError; end
99
class << self
1010
include Enumerable
1111

12-
delegate :each, :sample, to: :members
12+
delegate :each, to: :members
1313
delegate :values, :members, :texts, :to_options, :valid?, :size,
1414
:length, :connection_specification_name, to: :enum_source
1515

@@ -41,6 +41,11 @@ def enum_source
4141
const_get('EnumSource')
4242
end
4343

44+
# Use the power to get a sample of the value
45+
def sample
46+
new(rand(0..((2 ** size) - 1)))
47+
end
48+
4449
# Overpass new so blank values return only nil
4550
def new(*values)
4651
return Lazy.new(self, []) if values.compact.blank?

lib/torque/postgresql/config.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def config.irregular_models=(hash)
2929
# Configure associations features
3030
config.nested(:associations) do |assoc|
3131

32-
# Define if belongs to many associations are marked as required by default
32+
# Define if +belongs_to_many+ associations are marked as required by
33+
# default. False means that no validation will be performed
3334
assoc.belongs_to_many_required_by_default = false
3435

3536
end
@@ -41,7 +42,8 @@ def config.irregular_models=(hash)
4142
# arguments to format string or send on a proc
4243
cte.send_arguments_key = :args
4344

44-
# Specify the namespace of each enum type of value
45+
# Estipulate a class name (which may contain namespace) that expose the
46+
# auxiliary statement in order to perform detached CTEs
4547
cte.exposed_class = 'TorqueCTE'
4648

4749
end
@@ -90,14 +92,14 @@ def config.irregular_models=(hash)
9092
# it. Any class provided here must respond to 'x', and 'y'
9193
geometry.point_class = ActiveRecord::Point
9294

93-
# Define the class that will be handling Circle data types after decoding
94-
# it. Any class provided here must respond to 'x', 'y', and 'r'
95-
geometry.circle_class = nil
96-
9795
# Define the class that will be handling Box data types after decoding it.
9896
# Any class provided here must respond to 'x1', 'y1', 'x2', and 'y2'
9997
geometry.box_class = nil
10098

99+
# Define the class that will be handling Circle data types after decoding
100+
# it. Any class provided here must respond to 'x', 'y', and 'r'
101+
geometry.circle_class = nil
102+
101103
# Define the class that will be handling Line data types after decoding
102104
# it. Any class provided here must respond to 'a', 'b', and 'c'
103105
geometry.line_class = nil
@@ -172,6 +174,5 @@ def config.irregular_models=(hash)
172174
}
173175

174176
end
175-
176177
end
177178
end

lib/torque/postgresql/geometry_builder.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def cast(value)
2727
when ::Hash
2828
build_klass(*value.symbolize_keys.slice(*pieces).values)
2929
when ::Array
30-
build_klass(*value)
30+
build_klass(*(value.flatten))
3131
else
3232
value
3333
end
@@ -41,7 +41,7 @@ def serialize(value)
4141
when ::Hash
4242
value.symbolize_keys.slice(*pieces).values
4343
when ::Array
44-
value
44+
value.flatten
4545
end
4646

4747
parts = parts&.compact&.flatten

spec/tests/enum_set_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@
183183
it 'accepts values turn into an array of integer by index' do
184184
expect((subject.B | subject.C).map(&:to_i)).to be_eql([1, 2])
185185
end
186+
187+
it 'can return a sample for resting purposes' do
188+
expect(subject).to receive(:new).with(Numeric)
189+
subject.sample
190+
end
186191
end
187192

188193
context 'on OID' do

torque_postgresql.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
1111
s.email = ['[email protected]']
1212
s.homepage = 'https://github.com/crashtech/torque-postgresql'
1313
s.summary = 'ActiveRecord extension to access PostgreSQL advanced resources'
14-
s.description = 'Add support to complex resources of PostgreSQL, like data types, user-defined types and auxiliary statements (CTE)'
14+
s.description = 'Add support to complex resources of PostgreSQL, like data types, array associations, and auxiliary statements (CTE)'
1515
s.license = 'MIT'
1616

1717
s.require_paths = ['lib']

0 commit comments

Comments
 (0)