sunstone 6.1.0.1 → 6.1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +141 -0
- data/README.md +39 -3
- data/ext/active_record/relation/calculations.rb +6 -14
- data/lib/arel/visitors/sunstone.rb +1 -0
- data/lib/sunstone.rb +1 -0
- data/lib/sunstone/version.rb +1 -1
- data/test/active_record/query_test.rb +8 -0
- data/test/test_helper.rb +1 -0
- metadata +3 -3
- data/.travis.yml +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52f0e0a557ddc1ec6d7dcc9728d3cfbf602d8c467d1647571cb887b56755e3cc
|
4
|
+
data.tar.gz: 8db1bd8849700b80328ac2cf1248ff5260659d0afc49648e694fae33790c79cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a656ce5545ac0ad4a3f660f61857e8068a9c1f59060d4e9f9f06b1d80d2f6daca73e3317e02b35669a100ea1f8c578695f8ca0cc3a9eb2f00fc908708c1d18ff
|
7
|
+
data.tar.gz: 3395da82c6d52adc2029570a459f98cb7311c428a3f92c9f598d61ae8f0b7c5c7a354bb4d88933a6096e2cd5271997f929535f9ad2a35cda2c066d59472dae72
|
@@ -0,0 +1,141 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
sunstone:
|
11
|
+
name: Sunstone Test
|
12
|
+
runs-on: ubuntu-20.04
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 3.0
|
18
|
+
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
|
21
|
+
- run: bundle
|
22
|
+
|
23
|
+
- run: bundle exec rake test
|
24
|
+
|
25
|
+
ar-postgresql:
|
26
|
+
name: ActiveRecord PostgresQL Test
|
27
|
+
strategy:
|
28
|
+
matrix:
|
29
|
+
rails: [v6.1.3]
|
30
|
+
|
31
|
+
runs-on: ubuntu-20.04
|
32
|
+
|
33
|
+
steps:
|
34
|
+
- name: Install Postgresql
|
35
|
+
run: |
|
36
|
+
sudo apt-get install curl ca-certificates gnupg
|
37
|
+
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
38
|
+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
39
|
+
sudo apt-get update
|
40
|
+
sudo apt-get install postgresql-13
|
41
|
+
sudo systemctl start postgresql@13-main.service
|
42
|
+
sudo -u postgres createuser runner --superuser
|
43
|
+
|
44
|
+
- uses: ruby/setup-ruby@v1
|
45
|
+
with:
|
46
|
+
ruby-version: 3.0
|
47
|
+
|
48
|
+
- uses: actions/checkout@v2
|
49
|
+
|
50
|
+
- name: Download Rails
|
51
|
+
run: |
|
52
|
+
git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
|
53
|
+
pushd ~/rails
|
54
|
+
cat /home/runner/work/_temp/*.sh
|
55
|
+
sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/rails/activerecord/Rakefile
|
56
|
+
sed -i "s/t.warning = true/t.warning = false/g" ~/rails/activerecord/Rakefile
|
57
|
+
sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'sunstone'" ~/rails/activerecord/test/cases/helper.rb
|
58
|
+
rm ~/rails/Gemfile.lock
|
59
|
+
sed -i "/# Active Record./a gem 'sunstone', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
|
60
|
+
cat ~/rails/Gemfile
|
61
|
+
bundle update --jobs=3 --retry=3
|
62
|
+
|
63
|
+
- run: |
|
64
|
+
pushd ~/rails/activerecord
|
65
|
+
bundle exec rake db:postgresql:rebuild postgresql:test
|
66
|
+
bundle exec rake db:postgresql:rebuild postgresql:isolated_test
|
67
|
+
|
68
|
+
ar-sqlite:
|
69
|
+
name: ActiveRecord SQLite Test
|
70
|
+
strategy:
|
71
|
+
matrix:
|
72
|
+
rails: [v6.1.3]
|
73
|
+
|
74
|
+
runs-on: ubuntu-20.04
|
75
|
+
|
76
|
+
steps:
|
77
|
+
- uses: ruby/setup-ruby@v1
|
78
|
+
with:
|
79
|
+
ruby-version: 3.0
|
80
|
+
|
81
|
+
- uses: actions/checkout@v2
|
82
|
+
|
83
|
+
- name: Download Rails
|
84
|
+
run: |
|
85
|
+
git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
|
86
|
+
pushd ~/rails
|
87
|
+
cat /home/runner/work/_temp/*.sh
|
88
|
+
sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/rails/activerecord/Rakefile
|
89
|
+
sed -i "s/t.warning = true/t.warning = false/g" ~/rails/activerecord/Rakefile
|
90
|
+
sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'sunstone'" ~/rails/activerecord/test/cases/helper.rb
|
91
|
+
rm ~/rails/Gemfile.lock
|
92
|
+
sed -i "/# Active Record./a gem 'sunstone', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
|
93
|
+
cat ~/rails/Gemfile
|
94
|
+
bundle update --jobs=3 --retry=3
|
95
|
+
|
96
|
+
- run: |
|
97
|
+
pushd ~/rails/activerecord
|
98
|
+
bundle exec rake sqlite3:test
|
99
|
+
rm test/db/*.sqlite3 test/fixtures/*.sqlite3
|
100
|
+
bundle exec rake sqlite3:isolated_test
|
101
|
+
rm test/db/*.sqlite3 test/fixtures/*.sqlite3
|
102
|
+
bundle exec rake sqlite3_mem:test
|
103
|
+
|
104
|
+
ar-mysql:
|
105
|
+
name: ActiveRecord MySQL Test
|
106
|
+
strategy:
|
107
|
+
matrix:
|
108
|
+
rails: [v6.1.3]
|
109
|
+
|
110
|
+
runs-on: ubuntu-20.04
|
111
|
+
|
112
|
+
steps:
|
113
|
+
- name: Install MySQL
|
114
|
+
run: |
|
115
|
+
sudo /etc/init.d/mysql start
|
116
|
+
mysql -uroot -proot -e "CREATE USER 'rails'@'%';"
|
117
|
+
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'rails'@'%' WITH GRANT OPTION;"
|
118
|
+
|
119
|
+
- uses: ruby/setup-ruby@v1
|
120
|
+
with:
|
121
|
+
ruby-version: 3.0
|
122
|
+
|
123
|
+
- uses: actions/checkout@v2
|
124
|
+
|
125
|
+
- name: Download Rails
|
126
|
+
run: |
|
127
|
+
git clone --branch ${{ matrix.rails }} https://github.com/rails/rails.git ~/rails
|
128
|
+
pushd ~/rails
|
129
|
+
cat /home/runner/work/_temp/*.sh
|
130
|
+
sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/rails/activerecord/Rakefile
|
131
|
+
sed -i "s/t.warning = true/t.warning = false/g" ~/rails/activerecord/Rakefile
|
132
|
+
sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\(ENV['GITHUB_WORKSPACE']\)\)\nrequire 'sunstone'" ~/rails/activerecord/test/cases/helper.rb
|
133
|
+
rm ~/rails/Gemfile.lock
|
134
|
+
sed -i "/# Active Record./a gem 'sunstone', path: File.expand_path\(ENV['GITHUB_WORKSPACE']\)" ~/rails/Gemfile
|
135
|
+
cat ~/rails/Gemfile
|
136
|
+
bundle update --jobs=3 --retry=3
|
137
|
+
|
138
|
+
- run: |
|
139
|
+
pushd ~/rails/activerecord
|
140
|
+
bundle exec rake db:mysql:rebuild mysql2:test
|
141
|
+
bundle exec rake db:mysql:rebuild mysql2:isolated_test
|
data/README.md
CHANGED
@@ -1,8 +1,44 @@
|
|
1
|
-
# Sunstone
|
1
|
+
# Sunstone
|
2
2
|
|
3
|
-
|
4
|
-
APIs
|
3
|
+
Sunstone is an [ActiveRecord](https://rubygems.org/gems/activerecord) adapter for quering
|
4
|
+
APIs conforming to [Standard API](https://github.com/waratuman/standardapi).
|
5
5
|
|
6
|
+
Configuration
|
7
|
+
-------------
|
8
|
+
|
9
|
+
### Rails
|
10
|
+
|
11
|
+
Add `sunstone` to your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'sunstone'
|
15
|
+
```
|
16
|
+
|
17
|
+
Update `config/database.yml`"
|
18
|
+
|
19
|
+
```yaml
|
20
|
+
development:
|
21
|
+
adapter: sunstone
|
22
|
+
url: https://mystanda.rd/api
|
23
|
+
api_key: ..optional..
|
24
|
+
user_agent: ..optional..
|
25
|
+
```
|
26
|
+
|
27
|
+
### Standalone ActiveRecord
|
28
|
+
|
29
|
+
Initialize the connection on `ActiveRecord::Base` or your abstract model (`ApplicationRecord` for example)
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
ActiveRecord::Base.establish_connection(
|
33
|
+
adapter: 'sunstone',
|
34
|
+
url: 'https://mystanda.rd/api'
|
35
|
+
)
|
36
|
+
```
|
37
|
+
|
38
|
+
Usage
|
39
|
+
-----
|
40
|
+
|
41
|
+
Mention fitler / etc...
|
6
42
|
|
7
43
|
TODO:
|
8
44
|
=====
|
@@ -2,30 +2,22 @@ module ActiveRecord
|
|
2
2
|
module Calculations
|
3
3
|
|
4
4
|
def pluck(*column_names)
|
5
|
-
if loaded? &&
|
5
|
+
if loaded? && (column_names.map(&:to_s) - @klass.attribute_names - @klass.attribute_aliases.keys).empty?
|
6
6
|
return records.pluck(*column_names)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
if has_include?(column_names.first)
|
10
10
|
relation = apply_join_dependency
|
11
11
|
relation.pluck(*column_names)
|
12
12
|
elsif klass.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
|
13
13
|
load
|
14
|
-
return records.pluck(*column_names.map{|n| n.sub(/^#{klass.table_name}\./, "")})
|
14
|
+
return records.pluck(*column_names.map{|n| n.to_s.sub(/^#{klass.table_name}\./, "")})
|
15
15
|
else
|
16
16
|
klass.disallow_raw_sql!(column_names)
|
17
|
-
columns = arel_columns(column_names)
|
18
17
|
relation = spawn
|
19
|
-
relation.select_values =
|
20
|
-
|
21
|
-
result
|
22
|
-
if where_clause.contradiction?
|
23
|
-
ActiveRecord::Result.new([], [])
|
24
|
-
else
|
25
|
-
klass.connection.select_all(relation.arel, nil)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
type_cast_pluck_values(result, columns)
|
18
|
+
relation.select_values = column_names
|
19
|
+
result = skip_query_cache_if_necessary { klass.connection.select_all(relation.arel, nil) }
|
20
|
+
result.cast_values(klass.attribute_types)
|
29
21
|
end
|
30
22
|
end
|
31
23
|
|
data/lib/sunstone.rb
CHANGED
@@ -41,6 +41,7 @@ require File.expand_path(File.join(__FILE__, '../../ext/active_record/finder_met
|
|
41
41
|
|
42
42
|
if ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR == 1
|
43
43
|
# Patch to allow Rails 6.1 pass url to adapter, all other versions work
|
44
|
+
require 'active_record/database_configurations'
|
44
45
|
class ActiveRecord::DatabaseConfigurations::UrlConfig
|
45
46
|
private
|
46
47
|
def build_url_hash
|
data/lib/sunstone/version.rb
CHANGED
@@ -119,5 +119,13 @@ class ActiveRecord::QueryTest < ActiveSupport::TestCase
|
|
119
119
|
query = MessagePack.unpack(CGI.unescape(uri.query))
|
120
120
|
assert_equal({"where"=>{"ownerships"=>{"id"=>{"eq"=>1}}}}, query)
|
121
121
|
end
|
122
|
+
|
123
|
+
test 'Arel::Nodes::HomogeneousIn' do
|
124
|
+
webmock(:get, "/ships", { where: {id: {in: [10,12]} }, limit: 100, offset: 0 }).to_return({
|
125
|
+
body: [].to_json
|
126
|
+
})
|
127
|
+
|
128
|
+
Ship.where(id: [10,12]).to_a
|
129
|
+
end
|
122
130
|
|
123
131
|
end
|
data/test/test_helper.rb
CHANGED
@@ -69,6 +69,7 @@ class ActiveSupport::TestCase
|
|
69
69
|
|
70
70
|
stub_request(method, /^#{ActiveRecord::Base.connection.instance_variable_get(:@connection).url}/).with do |req|
|
71
71
|
if query
|
72
|
+
puts unpack(req&.uri&.query&.sub(/=true$/, '')) if req&.uri&.query
|
72
73
|
req&.uri&.path == path && req.uri.query && unpack(req.uri.query.sub(/=true$/, '')) == query
|
73
74
|
else
|
74
75
|
req&.uri&.path == path && req.uri.query.nil?
|
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: 6.1.0.
|
4
|
+
version: 6.1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -255,9 +255,9 @@ executables: []
|
|
255
255
|
extensions: []
|
256
256
|
extra_rdoc_files: []
|
257
257
|
files:
|
258
|
+
- ".github/workflows/main.yml"
|
258
259
|
- ".gitignore"
|
259
260
|
- ".tm_properties"
|
260
|
-
- ".travis.yml"
|
261
261
|
- Gemfile
|
262
262
|
- LICENSE
|
263
263
|
- README.md
|
data/.travis.yml
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
dist: bionic
|
2
|
-
language: ruby
|
3
|
-
sudo: false
|
4
|
-
|
5
|
-
cache:
|
6
|
-
bundler: true
|
7
|
-
directories:
|
8
|
-
- /home/travis/.rvm/gems
|
9
|
-
|
10
|
-
rvm:
|
11
|
-
- 2.7
|
12
|
-
- 3.0
|
13
|
-
|
14
|
-
env:
|
15
|
-
matrix:
|
16
|
-
- RAILS_VERSION=v6.1.0 TASK='db:mysql:rebuild mysql2:test'
|
17
|
-
- RAILS_VERSION=v6.1.0 TASK='db:mysql:rebuild mysql2:isolated_test'
|
18
|
-
- RAILS_VERSION=v6.1.0 TASK='db:postgresql:rebuild postgresql:test'
|
19
|
-
- RAILS_VERSION=v6.1.0 TASK='db:postgresql:rebuild postgresql:isolated_test'
|
20
|
-
- RAILS_VERSION=v6.1.0 TASK='sqlite3:test'
|
21
|
-
- RAILS_VERSION=v6.1.0 TASK='sqlite3:isolated_test'
|
22
|
-
- RAILS_VERSION=v6.1.0 TASK='sqlite3_mem:test'
|
23
|
-
|
24
|
-
services:
|
25
|
-
- mysql
|
26
|
-
addons:
|
27
|
-
postgresql: "13"
|
28
|
-
apt:
|
29
|
-
packages:
|
30
|
-
- postgresql-13
|
31
|
-
- postgresql-client-13
|
32
|
-
|
33
|
-
before_install:
|
34
|
-
- sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/13/main/postgresql.conf
|
35
|
-
- sudo cp /etc/postgresql/{9.3,13}/main/pg_hba.conf
|
36
|
-
- sudo pg_ctlcluster 13 main restart
|
37
|
-
- unset BUNDLE_GEMFILE
|
38
|
-
- gem update --system
|
39
|
-
- gem update bundler
|
40
|
-
- gem install bundler --version 1.17.3
|
41
|
-
- mysql -e "create user rails@localhost;"
|
42
|
-
- mysql -e "grant all privileges on activerecord_unittest.* to rails@localhost;"
|
43
|
-
- mysql -e "grant all privileges on activerecord_unittest2.* to rails@localhost;"
|
44
|
-
- mysql -e "grant all privileges on inexistent_activerecord_unittest.* to rails@localhost;"
|
45
|
-
- mysql -e "create database activerecord_unittest default character set utf8mb4;"
|
46
|
-
- mysql -e "create database activerecord_unittest2 default character set utf8mb4;"
|
47
|
-
|
48
|
-
install:
|
49
|
-
- git clone --branch $RAILS_VERSION https://github.com/rails/rails.git ~/build/rails
|
50
|
-
|
51
|
-
before_script:
|
52
|
-
- sed -i "s/t.warning = true/t.warning = false/g" Rakefile
|
53
|
-
- pushd ~/build/rails
|
54
|
-
- git status
|
55
|
-
- sed -i "s/Gem.ruby, '-w'/Gem.ruby, '-w0'/" ~/build/rails/activerecord/Rakefile
|
56
|
-
- sed -i "s/t.warning = true/t.warning = false/g" ~/build/rails/activerecord/Rakefile
|
57
|
-
- sed -i "/require 'support\/connection'/a \$LOAD_PATH.unshift\(File.expand_path\('~\/build\/malomalo\/sunstone\/lib'\)\)\nrequire 'sunstone'" ~/build/rails/activerecord/test/cases/helper.rb
|
58
|
-
- cat ~/build/rails/Gemfile
|
59
|
-
- rm ~/build/rails/Gemfile.lock
|
60
|
-
- "sed -i \"/# Active Record./a gem 'sunstone', path: File.expand_path\\('~\\/build\\/malomalo\\/sunstone'\\)\" ~/build/rails/Gemfile"
|
61
|
-
- cat ~/build/rails/Gemfile
|
62
|
-
- bundle update --jobs=3 --retry=3
|
63
|
-
- popd
|
64
|
-
- bundle install --jobs=3 --retry=3
|
65
|
-
|
66
|
-
script:
|
67
|
-
- bundle exec rake test
|
68
|
-
- cd ~/build/rails/activerecord && bundle exec rake $TASK
|