sunstone 2.0.1 → 2.0.4
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/ext/active_record/associations/builder/has_and_belongs_to_many.rb +48 -52
- data/ext/active_record/calculations.rb +28 -28
- data/ext/active_record/relation/predicate_builder.rb +23 -29
- data/ext/active_support/core_ext/object/to_query.rb +7 -0
- data/lib/active_record/connection_adapters/sunstone/type/ewkb.rb +31 -0
- data/lib/active_record/connection_adapters/sunstone_adapter.rb +3 -1
- data/lib/sunstone.rb +2 -0
- data/lib/sunstone/connection.rb +6 -0
- data/lib/sunstone/version.rb +1 -1
- data/test/query_test.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d7b7cb926a0045ee4a771a87ce5f3f3096fb035
|
4
|
+
data.tar.gz: 0edf0869c5ac58e901579d47b8979ed4ecf98c39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bf1d1921cf1cad5967be3398b0a49de76cac94b65bc268952c549b994b1e48487913b062a29e33f4968c84fecb90aec0691f24cce06261c61f0a7cf2bce5ddb
|
7
|
+
data.tar.gz: 8bce1e614955c036c7d46df1c109b2650dec40ad5d0b3168d9c33963005c94f91a80a6737d1b00b045ffafea006efc43faaef28f66053f811975e0efa33e2f46
|
@@ -1,52 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# end
|
52
|
-
# end
|
1
|
+
module ActiveRecord::Associations::Builder
|
2
|
+
class HasAndBelongsToMany # :nodoc:
|
3
|
+
|
4
|
+
def through_model
|
5
|
+
habtm = JoinTableResolver.build lhs_model, association_name, options
|
6
|
+
|
7
|
+
join_model = Class.new(lhs_model.base_class.superclass) {
|
8
|
+
class << self;
|
9
|
+
attr_accessor :class_resolver
|
10
|
+
attr_accessor :name
|
11
|
+
attr_accessor :table_name_resolver
|
12
|
+
attr_accessor :left_reflection
|
13
|
+
attr_accessor :right_reflection
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.table_name
|
17
|
+
table_name_resolver.join_table
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.compute_type(class_name)
|
21
|
+
class_resolver.compute_type class_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.add_left_association(name, options)
|
25
|
+
belongs_to name, options
|
26
|
+
self.left_reflection = _reflect_on_association(name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.add_right_association(name, options)
|
30
|
+
rhs_name = name.to_s.singularize.to_sym
|
31
|
+
belongs_to rhs_name, options
|
32
|
+
self.right_reflection = _reflect_on_association(rhs_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
join_model.name = "HABTM_#{association_name.to_s.camelize}"
|
38
|
+
join_model.table_name_resolver = habtm
|
39
|
+
join_model.class_resolver = lhs_model
|
40
|
+
join_model.primary_key = nil
|
41
|
+
|
42
|
+
join_model.add_left_association :left_side, anonymous_class: lhs_model
|
43
|
+
join_model.add_right_association association_name, belongs_to_options(options)
|
44
|
+
join_model
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
module ActiveRecord
|
2
|
+
module Calculations
|
3
|
+
def pluck(*column_names)
|
4
|
+
|
5
|
+
# column_names.map! do |column_name|
|
6
|
+
# if column_name.is_a?(Symbol) && attribute_alias?(column_name)
|
7
|
+
# attribute_alias(column_name)
|
8
|
+
# else
|
9
|
+
# column_name.to_s
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
if has_include?(column_names.first)
|
14
|
+
construct_relation_for_association_calculations.pluck(*column_names)
|
15
|
+
else
|
16
|
+
relation = spawn
|
17
|
+
relation.select_values = column_names.map { |cn|
|
18
|
+
columns_hash.key?(cn) ? arel_table[cn] : cn
|
19
|
+
}
|
20
|
+
|
21
|
+
result = klass.connection.exec_query(relation.arel, nil, relation.arel.bind_values + bind_values)
|
22
|
+
result.cast_values(klass.column_types)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -1,29 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# queries << build(table[column], value)
|
25
|
-
# queries
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# end
|
29
|
-
# end
|
1
|
+
module ActiveRecord
|
2
|
+
class PredicateBuilder # :nodoc:
|
3
|
+
|
4
|
+
def self.expand(klass, table, column, value)
|
5
|
+
queries = []
|
6
|
+
|
7
|
+
# In standard Rails where takes :table => { columns }, but in sunstone we
|
8
|
+
# can can do nested tables eg: where(:properties => { :regions => {:id => 1}})
|
9
|
+
if klass && reflection = klass._reflect_on_association(column)
|
10
|
+
if reflection.polymorphic? && base_class = polymorphic_base_class_from_value(value)
|
11
|
+
queries << build(table[reflection.foreign_type], base_class)
|
12
|
+
end
|
13
|
+
|
14
|
+
# column = reflection.foreign_key
|
15
|
+
column # Don't need Rails to assume we are referencing a table
|
16
|
+
end
|
17
|
+
|
18
|
+
queries << build(table[column], value)
|
19
|
+
queries
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rgeo'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module Sunstone
|
6
|
+
module Type
|
7
|
+
class EWKB < ActiveRecord::Type::Value
|
8
|
+
|
9
|
+
def type
|
10
|
+
:ewkb
|
11
|
+
end
|
12
|
+
|
13
|
+
def type_cast_for_database(value)
|
14
|
+
if value
|
15
|
+
::RGeo::WKRep::WKBGenerator.new(hex_format: true, type_format: :ewkb, emit_ewkb_srid: true).generate(value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def cast_value(string)
|
22
|
+
return string unless string.is_a?(::String)
|
23
|
+
|
24
|
+
::RGeo::WKRep::WKBParser.new(RGeo::Geos.factory_generator, support_ewkb: true).parse(string)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -8,11 +8,12 @@ require 'active_record/connection_adapters/sunstone/column'
|
|
8
8
|
|
9
9
|
require 'active_record/connection_adapters/sunstone/type/date_time'
|
10
10
|
require 'active_record/connection_adapters/sunstone/type/array'
|
11
|
+
require 'active_record/connection_adapters/sunstone/type/ewkb'
|
11
12
|
|
12
13
|
module ActiveRecord
|
13
14
|
module ConnectionHandling # :nodoc:
|
14
15
|
|
15
|
-
VALID_SUNSTONE_CONN_PARAMS = [:site, :host, :port, :api_key, :use_ssl, :user_agent]
|
16
|
+
VALID_SUNSTONE_CONN_PARAMS = [:site, :host, :port, :api_key, :use_ssl, :user_agent, :ca_cert]
|
16
17
|
|
17
18
|
# Establishes a connection to the database that's used by all Active Record
|
18
19
|
# objects
|
@@ -158,6 +159,7 @@ module ActiveRecord
|
|
158
159
|
m.register_type 'decimal', Type::Decimal.new
|
159
160
|
m.register_type 'datetime', Sunstone::Type::DateTime.new
|
160
161
|
m.register_type 'hash', Type::Value.new
|
162
|
+
m.register_type 'ewkb', Sunstone::Type::EWKB.new
|
161
163
|
end
|
162
164
|
|
163
165
|
def exec(arel, name='SAR', binds=[])
|
data/lib/sunstone.rb
CHANGED
@@ -18,6 +18,8 @@ require File.expand_path(File.join(__FILE__, '../../ext/active_record/relation')
|
|
18
18
|
require File.expand_path(File.join(__FILE__, '../../ext/active_record/query_methods'))
|
19
19
|
# require File.expand_path(File.join(__FILE__, '../../ext/active_record/associations/builder/has_and_belongs_to_many'))
|
20
20
|
|
21
|
+
require File.expand_path(File.join(__FILE__, '../../ext/active_support/core_ext/object/to_query'))
|
22
|
+
|
21
23
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/select_manager'))
|
22
24
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/eager_load'))
|
23
25
|
require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/select_statement'))
|
data/lib/sunstone/connection.rb
CHANGED
@@ -36,6 +36,12 @@ module Sunstone
|
|
36
36
|
|
37
37
|
@connection = Net::HTTP.new(host, port)
|
38
38
|
@connection.use_ssl = use_ssl
|
39
|
+
if use_ssl && config[:ca_cert]
|
40
|
+
@connection.cert_store = OpenSSL::X509::Store.new
|
41
|
+
@connection.cert_store.add_cert(OpenSSL::X509::Certificate.new(File.read(config[:ca_cert])))
|
42
|
+
end
|
43
|
+
|
44
|
+
true
|
39
45
|
end
|
40
46
|
|
41
47
|
# Ping the Sunstone. If everything is configured and operating correctly
|
data/lib/sunstone/version.rb
CHANGED
data/test/query_test.rb
CHANGED
@@ -58,6 +58,12 @@ class QueryTest < Minitest::Test
|
|
58
58
|
assert_equal [], Ship.where(:id => 10).to_a
|
59
59
|
end
|
60
60
|
|
61
|
+
test '::where column is nil' do
|
62
|
+
stub_request(:get, URI::escape('malomalo.io/ships?where[leased_at]')).to_return(body: [].to_json)
|
63
|
+
|
64
|
+
assert_equal [], Ship.where(:leased_at => nil).to_a
|
65
|
+
end
|
66
|
+
|
61
67
|
test '::where on belongs_to relation' do
|
62
68
|
stub_request(:get, URI::escape('malomalo.io/ships?where[fleet][id]=1')).to_return(body: [].to_json)
|
63
69
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunstone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -269,6 +269,7 @@ files:
|
|
269
269
|
- ext/active_record/relation.rb
|
270
270
|
- ext/active_record/relation/predicate_builder.rb
|
271
271
|
- ext/active_record/statement_cache.rb
|
272
|
+
- ext/active_support/core_ext/object/to_query.rb
|
272
273
|
- ext/arel/nodes/eager_load.rb
|
273
274
|
- ext/arel/nodes/select_statement.rb
|
274
275
|
- ext/arel/select_manager.rb
|
@@ -277,6 +278,7 @@ files:
|
|
277
278
|
- lib/active_record/connection_adapters/sunstone/schema_statements.rb
|
278
279
|
- lib/active_record/connection_adapters/sunstone/type/array.rb
|
279
280
|
- lib/active_record/connection_adapters/sunstone/type/date_time.rb
|
281
|
+
- lib/active_record/connection_adapters/sunstone/type/ewkb.rb
|
280
282
|
- lib/active_record/connection_adapters/sunstone_adapter.rb
|
281
283
|
- lib/arel/collectors/sunstone.rb
|
282
284
|
- lib/arel/visitors/sunstone.rb
|