sunstone 6.1.0.2 → 7.0.0
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/collection_association.rb +1 -1
- data/ext/active_record/attribute_methods.rb +7 -1
- data/ext/active_record/finder_methods.rb +14 -13
- data/ext/active_record/persistence.rb +6 -3
- data/ext/active_record/relation/calculations.rb +11 -4
- data/ext/active_record/relation/query_methods.rb +1 -1
- data/ext/active_record/statement_cache.rb +0 -1
- data/ext/arel/nodes/select_statement.rb +3 -3
- data/lib/active_record/connection_adapters/sunstone/column.rb +1 -1
- data/lib/active_record/connection_adapters/sunstone/database_statements.rb +8 -9
- data/lib/active_record/connection_adapters/sunstone/schema_statements.rb +31 -14
- data/lib/active_record/connection_adapters/sunstone_adapter.rb +17 -7
- data/lib/arel/collectors/sunstone.rb +25 -4
- data/lib/arel/visitors/sunstone.rb +21 -26
- data/lib/sunstone/connection.rb +40 -13
- data/lib/sunstone/version.rb +1 -1
- metadata +21 -61
- data/.github/workflows/main.yml +0 -141
- data/.gitignore +0 -31
- data/.tm_properties +0 -1
- data/Gemfile +0 -4
- data/README.md +0 -46
- data/Rakefile +0 -37
- data/TODO.md +0 -89
- data/sunstone.gemspec +0 -40
- data/test/active_record/associations/belongs_to_test.rb +0 -162
- data/test/active_record/associations/has_and_belongs_to_many_test.rb +0 -125
- data/test/active_record/associations/has_many_test.rb +0 -244
- data/test/active_record/eager_loading_test.rb +0 -62
- data/test/active_record/persistance_test.rb +0 -184
- data/test/active_record/preload_test.rb +0 -51
- data/test/active_record/query/all_test.rb +0 -33
- data/test/active_record/query/count_test.rb +0 -51
- data/test/active_record/query/distinct_test.rb +0 -30
- data/test/active_record/query/find_test.rb +0 -37
- data/test/active_record/query/limit_test.rb +0 -19
- data/test/active_record/query/order_test.rb +0 -27
- data/test/active_record/query/where_test.rb +0 -79
- data/test/active_record/query_test.rb +0 -131
- data/test/active_record/rpc_test.rb +0 -30
- data/test/schema_mock.rb +0 -121
- data/test/sunstone/connection/column_definition_test.rb +0 -30
- data/test/sunstone/connection/configuration_test.rb +0 -44
- data/test/sunstone/connection/cookie_store_test.rb +0 -37
- data/test/sunstone/connection/request_helper_test.rb +0 -105
- data/test/sunstone/connection/send_request_test.rb +0 -164
- data/test/sunstone/connection_test.rb +0 -23
- data/test/test_helper.rb +0 -153
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:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
187
|
+
version: 7.0.0
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 7.0.0
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: msgpack
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -222,6 +222,20 @@ dependencies:
|
|
222
222
|
version: '0'
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: activerecord
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 7.0.0
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 7.0.0
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: arel-extensions
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
226
240
|
requirements:
|
227
241
|
- - ">="
|
@@ -235,7 +249,7 @@ dependencies:
|
|
235
249
|
- !ruby/object:Gem::Version
|
236
250
|
version: 6.1.0
|
237
251
|
- !ruby/object:Gem::Dependency
|
238
|
-
name:
|
252
|
+
name: activerecord-filter
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
240
254
|
requirements:
|
241
255
|
- - ">="
|
@@ -255,14 +269,7 @@ executables: []
|
|
255
269
|
extensions: []
|
256
270
|
extra_rdoc_files: []
|
257
271
|
files:
|
258
|
-
- ".github/workflows/main.yml"
|
259
|
-
- ".gitignore"
|
260
|
-
- ".tm_properties"
|
261
|
-
- Gemfile
|
262
272
|
- LICENSE
|
263
|
-
- README.md
|
264
|
-
- Rakefile
|
265
|
-
- TODO.md
|
266
273
|
- ext/active_record/associations.rb
|
267
274
|
- ext/active_record/associations/collection_association.rb
|
268
275
|
- ext/active_record/attribute_methods.rb
|
@@ -298,30 +305,6 @@ files:
|
|
298
305
|
- lib/sunstone/exception.rb
|
299
306
|
- lib/sunstone/gis.rb
|
300
307
|
- lib/sunstone/version.rb
|
301
|
-
- sunstone.gemspec
|
302
|
-
- test/active_record/associations/belongs_to_test.rb
|
303
|
-
- test/active_record/associations/has_and_belongs_to_many_test.rb
|
304
|
-
- test/active_record/associations/has_many_test.rb
|
305
|
-
- test/active_record/eager_loading_test.rb
|
306
|
-
- test/active_record/persistance_test.rb
|
307
|
-
- test/active_record/preload_test.rb
|
308
|
-
- test/active_record/query/all_test.rb
|
309
|
-
- test/active_record/query/count_test.rb
|
310
|
-
- test/active_record/query/distinct_test.rb
|
311
|
-
- test/active_record/query/find_test.rb
|
312
|
-
- test/active_record/query/limit_test.rb
|
313
|
-
- test/active_record/query/order_test.rb
|
314
|
-
- test/active_record/query/where_test.rb
|
315
|
-
- test/active_record/query_test.rb
|
316
|
-
- test/active_record/rpc_test.rb
|
317
|
-
- test/schema_mock.rb
|
318
|
-
- test/sunstone/connection/column_definition_test.rb
|
319
|
-
- test/sunstone/connection/configuration_test.rb
|
320
|
-
- test/sunstone/connection/cookie_store_test.rb
|
321
|
-
- test/sunstone/connection/request_helper_test.rb
|
322
|
-
- test/sunstone/connection/send_request_test.rb
|
323
|
-
- test/sunstone/connection_test.rb
|
324
|
-
- test/test_helper.rb
|
325
308
|
homepage: http://sunstonerb.com
|
326
309
|
licenses: []
|
327
310
|
metadata: {}
|
@@ -340,31 +323,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
340
323
|
- !ruby/object:Gem::Version
|
341
324
|
version: '0'
|
342
325
|
requirements: []
|
343
|
-
rubygems_version: 3.2.
|
326
|
+
rubygems_version: 3.2.22
|
344
327
|
signing_key:
|
345
328
|
specification_version: 4
|
346
329
|
summary: A library for interacting with REST APIs
|
347
|
-
test_files:
|
348
|
-
- test/active_record/associations/belongs_to_test.rb
|
349
|
-
- test/active_record/associations/has_and_belongs_to_many_test.rb
|
350
|
-
- test/active_record/associations/has_many_test.rb
|
351
|
-
- test/active_record/eager_loading_test.rb
|
352
|
-
- test/active_record/persistance_test.rb
|
353
|
-
- test/active_record/preload_test.rb
|
354
|
-
- test/active_record/query/all_test.rb
|
355
|
-
- test/active_record/query/count_test.rb
|
356
|
-
- test/active_record/query/distinct_test.rb
|
357
|
-
- test/active_record/query/find_test.rb
|
358
|
-
- test/active_record/query/limit_test.rb
|
359
|
-
- test/active_record/query/order_test.rb
|
360
|
-
- test/active_record/query/where_test.rb
|
361
|
-
- test/active_record/query_test.rb
|
362
|
-
- test/active_record/rpc_test.rb
|
363
|
-
- test/schema_mock.rb
|
364
|
-
- test/sunstone/connection/column_definition_test.rb
|
365
|
-
- test/sunstone/connection/configuration_test.rb
|
366
|
-
- test/sunstone/connection/cookie_store_test.rb
|
367
|
-
- test/sunstone/connection/request_helper_test.rb
|
368
|
-
- test/sunstone/connection/send_request_test.rb
|
369
|
-
- test/sunstone/connection_test.rb
|
370
|
-
- test/test_helper.rb
|
330
|
+
test_files: []
|
data/.github/workflows/main.yml
DELETED
@@ -1,141 +0,0 @@
|
|
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/.gitignore
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
/.config
|
4
|
-
/coverage/
|
5
|
-
/InstalledFiles
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/test/tmp/
|
9
|
-
/test/version_tmp/
|
10
|
-
/tmp/
|
11
|
-
.DS_Store
|
12
|
-
|
13
|
-
## Documentation cache and generated files:
|
14
|
-
/.yardoc/
|
15
|
-
/_yardoc/
|
16
|
-
/doc/
|
17
|
-
/rdoc/
|
18
|
-
|
19
|
-
## Environment normalisation:
|
20
|
-
/.bundle/
|
21
|
-
/lib/bundler/man/
|
22
|
-
|
23
|
-
# for a library or gem, you might want to ignore these files since the code is
|
24
|
-
# intended to run in multiple environments; otherwise, check them in:
|
25
|
-
Gemfile.lock
|
26
|
-
.ruby-version
|
27
|
-
.ruby-gemset
|
28
|
-
|
29
|
-
# Text Editor scraps
|
30
|
-
*~
|
31
|
-
.byebug_history
|
data/.tm_properties
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
exclude = '{$exclude,log,bin,tmp,.tm_properties,coverage}'
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# Sunstone
|
2
|
-
|
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
|
-
|
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...
|
42
|
-
|
43
|
-
TODO:
|
44
|
-
=====
|
45
|
-
Make `cookie_store` and optional
|
46
|
-
stream building model instances with wankel
|
data/Rakefile
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
Bundler.require(:development)
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rdoc/task'
|
6
|
-
|
7
|
-
task :console do
|
8
|
-
exec 'irb -I lib -r sunstone.rb'
|
9
|
-
end
|
10
|
-
task :c => :console
|
11
|
-
|
12
|
-
Rake::TestTask.new do |t|
|
13
|
-
t.libs << 'test'
|
14
|
-
t.test_files = FileList['test/**/*_test.rb']
|
15
|
-
t.warning = true
|
16
|
-
#t.verbose = true
|
17
|
-
end
|
18
|
-
|
19
|
-
Rake::RDocTask.new do |rd|
|
20
|
-
rd.main = 'README.md'
|
21
|
-
rd.title = 'Sunstone Documentation'
|
22
|
-
rd.rdoc_dir = 'doc'
|
23
|
-
|
24
|
-
rd.options << '-f' << 'sdoc'
|
25
|
-
rd.options << '-T' << '42floors'
|
26
|
-
rd.options << '-g' # Generate github links
|
27
|
-
|
28
|
-
rd.rdoc_files.include('README.rdoc')
|
29
|
-
rd.rdoc_files.include('lib/**/*.rb')
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "Run tests"
|
33
|
-
task :default => :test
|
34
|
-
|
35
|
-
namespace :pages do
|
36
|
-
#TODO: https://github.com/defunkt/sdoc-helpers/blob/master/lib/sdoc_helpers/pages.rb
|
37
|
-
end
|
data/TODO.md
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
- Check if `Sunstone#to_key` needs to be added
|
2
|
-
|
3
|
-
- Add `Sunstone::Model::Persistance` with the following methods:
|
4
|
-
|
5
|
-
- `#new_record?`
|
6
|
-
- `#persisted?`
|
7
|
-
- `#save`
|
8
|
-
- `#save!`
|
9
|
-
- `#update`
|
10
|
-
- `#update!`
|
11
|
-
- `#create`
|
12
|
-
- `#to_param` ?
|
13
|
-
- `::all`
|
14
|
-
- `::where` (probably goes in an Arel like engine)
|
15
|
-
- `::build`
|
16
|
-
- `::create!`
|
17
|
-
- `#==`
|
18
|
-
- `::create`
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
# Creates an object and saves it to the MLS. The resulting object is returned
|
22
|
-
# whether or no the object was saved successfully to the MLS or not.
|
23
|
-
#
|
24
|
-
# ==== Examples
|
25
|
-
# #!ruby
|
26
|
-
# # Create a single new object
|
27
|
-
# User.create(:first_name => 'Jamie')
|
28
|
-
#
|
29
|
-
# # Create a single object and pass it into a block to set other attributes.
|
30
|
-
# User.create(:first_name => 'Jamie') do |u|
|
31
|
-
# u.is_admin = false
|
32
|
-
# end
|
33
|
-
def self.create(attributes={}, &block) # TODO: testme
|
34
|
-
model = self.new(attributes)
|
35
|
-
yield(model) if block_given?
|
36
|
-
model.save
|
37
|
-
model
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
- Look at https://gist.github.com/malomalo/91f360fe52db3dbe1c99 files for inspiration, came from
|
42
|
-
Rails code I think
|
43
|
-
|
44
|
-
- Simplify `Sunstone::Type::Value` to `Sunstone::Type`
|
45
|
-
|
46
|
-
- Add a `find_class(type)` in `Sunstone::Schema`
|
47
|
-
|
48
|
-
- Possibly use Classes to hold information about each attribute in addition to the type
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
class MLS::Attribute
|
52
|
-
|
53
|
-
DEFAULT_OPTIONS = { :serialize => true }
|
54
|
-
|
55
|
-
attr_reader :model, :name, :instance_variable_name, :options, :default
|
56
|
-
attr_reader :reader_visibility, :writer_visibility
|
57
|
-
|
58
|
-
def initialize(name, options={})
|
59
|
-
@name = name
|
60
|
-
@instance_variable_name = "@#{@name}".freeze
|
61
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
62
|
-
|
63
|
-
@default = @options[:default]
|
64
|
-
@reader_visibility = @options[:reader] || :public
|
65
|
-
@writer_visibility = @options[:writer] || :public
|
66
|
-
end
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
|
-
- Use Association classes to model the association:
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
class MLS::Association
|
74
|
-
class BelongsTo
|
75
|
-
attr_reader :klass, :foreign_key, :foreign_type, :primary_key, :polymorphic
|
76
|
-
|
77
|
-
def initialize(name, options={})
|
78
|
-
@name = name
|
79
|
-
@klass = options[:class_name] ? options[:class_name].constantize : name.camelize.constantize
|
80
|
-
|
81
|
-
@polymorphic = options[:polymorphic] || false
|
82
|
-
@foreign_key = options[:foreign_key] || "#{name}_id".to_sym
|
83
|
-
@foreign_type = options[:foreign_type] || "#{name}_type".to_sym
|
84
|
-
@primary_key = options[:primary_key] || :id
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
```
|
data/sunstone.gemspec
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path("../lib/sunstone/version", __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "sunstone"
|
5
|
-
s.version = Sunstone::VERSION
|
6
|
-
s.authors = ["Jon Bracy"]
|
7
|
-
s.email = ["jonbracy@gmail.com"]
|
8
|
-
s.homepage = "http://sunstonerb.com"
|
9
|
-
s.summary = %q{A library for interacting with REST APIs}
|
10
|
-
s.description = %q{A library for interacting with REST APIs. Similar to ActiveResource}
|
11
|
-
|
12
|
-
s.files = `git ls-files`.split("\n")
|
13
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
-
s.require_paths = ["lib"]
|
16
|
-
s.required_ruby_version = '>= 2.6'
|
17
|
-
|
18
|
-
# Developoment
|
19
|
-
s.add_development_dependency 'rake'
|
20
|
-
s.add_development_dependency 'rdoc'
|
21
|
-
# s.add_development_dependency 'sdoc'
|
22
|
-
s.add_development_dependency 'bundler'
|
23
|
-
s.add_development_dependency 'minitest'
|
24
|
-
s.add_development_dependency 'minitest-reporters'
|
25
|
-
s.add_development_dependency 'mocha'
|
26
|
-
s.add_development_dependency 'faker'
|
27
|
-
s.add_development_dependency 'factory_bot'
|
28
|
-
s.add_development_dependency 'webmock'
|
29
|
-
#s.add_development_dependency 'sdoc-templates-42floors'
|
30
|
-
s.add_development_dependency 'rgeo'
|
31
|
-
s.add_development_dependency 'simplecov'
|
32
|
-
s.add_development_dependency 'byebug'
|
33
|
-
s.add_development_dependency 'activesupport', '>= 6.1.0'
|
34
|
-
|
35
|
-
# Runtime
|
36
|
-
s.add_runtime_dependency 'msgpack'
|
37
|
-
s.add_runtime_dependency 'cookie_store'
|
38
|
-
s.add_runtime_dependency 'activerecord', '>= 6.1.0'
|
39
|
-
s.add_runtime_dependency 'arel-extensions', '>= 6.1.0'
|
40
|
-
end
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ActiveRecord::Associations::BelongsToTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
schema do
|
6
|
-
create_table "ships" do |t|
|
7
|
-
t.string "name", limit: 255
|
8
|
-
t.integer "fleet_id"
|
9
|
-
end
|
10
|
-
|
11
|
-
create_table "fleets" do |t|
|
12
|
-
t.string "name", limit: 255
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Fleet < ActiveRecord::Base
|
17
|
-
has_many :ships
|
18
|
-
end
|
19
|
-
|
20
|
-
class Ship < ActiveRecord::Base
|
21
|
-
belongs_to :fleet
|
22
|
-
end
|
23
|
-
|
24
|
-
# Save includes =============================================================
|
25
|
-
|
26
|
-
test '#save new record includes new belongs_to associations' do
|
27
|
-
ship = Ship.new(name: 'Definant', fleet: Fleet.new(name: 'Armada Duo'))
|
28
|
-
|
29
|
-
req_stub = webmock(:post, '/ships', {include: :fleet}).with(
|
30
|
-
body: {
|
31
|
-
ship: { name: 'Definant', fleet_attributes: { name: 'Armada Duo' } }
|
32
|
-
}.to_json
|
33
|
-
).to_return(
|
34
|
-
body: {
|
35
|
-
id: 2,
|
36
|
-
fleet_id: 3,
|
37
|
-
name: 'Definant 001',
|
38
|
-
fleet: { id: 3, name: 'Armada 2' }
|
39
|
-
}.to_json
|
40
|
-
)
|
41
|
-
|
42
|
-
assert ship.save
|
43
|
-
assert_equal 2, ship.id
|
44
|
-
assert_equal 3, ship.fleet_id
|
45
|
-
assert_equal 3, ship.fleet.id
|
46
|
-
assert_equal 'Definant 001', ship.name
|
47
|
-
assert_equal 'Armada 2', ship.fleet.name
|
48
|
-
|
49
|
-
assert_requested req_stub
|
50
|
-
end
|
51
|
-
|
52
|
-
test '#save new record doesnt include persisted/unmodified belongs_to associations' do
|
53
|
-
webmock(:get, "/fleets", where: {id: 1}, limit: 1).to_return(
|
54
|
-
body: [{id: 1, name: 'Armada Original'}].to_json
|
55
|
-
)
|
56
|
-
|
57
|
-
fleet = Fleet.find(1)
|
58
|
-
ship = Ship.new(name: 'Definant', fleet: fleet)
|
59
|
-
|
60
|
-
req_stub = webmock(:post, '/ships').with(
|
61
|
-
body: {
|
62
|
-
ship: { name: 'Definant', fleet_id: 1 }
|
63
|
-
}.to_json
|
64
|
-
).to_return(
|
65
|
-
body: {
|
66
|
-
id: 2,
|
67
|
-
fleet_id: 1,
|
68
|
-
name: 'Definant 001'
|
69
|
-
}.to_json
|
70
|
-
)
|
71
|
-
|
72
|
-
assert ship.save
|
73
|
-
assert_equal 2, ship.id
|
74
|
-
assert_equal 1, ship.fleet_id
|
75
|
-
|
76
|
-
assert_requested req_stub
|
77
|
-
end
|
78
|
-
|
79
|
-
test '#save persisted record includes new belongs_to associations' do
|
80
|
-
webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
|
81
|
-
body: [{id: 1, fleet_id: nil, name: 'Ship Uno'}].to_json
|
82
|
-
)
|
83
|
-
|
84
|
-
req_stub = webmock(:patch, '/ships/1', {include: :fleet}).with(
|
85
|
-
body: {
|
86
|
-
ship: { fleet_attributes: { name: 'Armada Duo' } }
|
87
|
-
}.to_json
|
88
|
-
).to_return(
|
89
|
-
body: {
|
90
|
-
id: 1, fleet_id: 2, name: 'Ship Uno',
|
91
|
-
fleet: { id: 2, name: 'Armada Duo' }
|
92
|
-
}.to_json
|
93
|
-
)
|
94
|
-
|
95
|
-
ship = Ship.find(1)
|
96
|
-
ship.fleet = Fleet.new(name: 'Armada Duo')
|
97
|
-
|
98
|
-
ship.save
|
99
|
-
|
100
|
-
assert_requested req_stub
|
101
|
-
end
|
102
|
-
|
103
|
-
test '#save persisted record doesnt include persisted/unmodified belongs_to associations but updates belongs_to key' do
|
104
|
-
webmock(:get, "/ships", where: {id: 1}, limit: 1).to_return(
|
105
|
-
body: [{id: 1, fleet_id: nil, name: 'Ship Uno'}].to_json
|
106
|
-
)
|
107
|
-
webmock(:get, "/fleets", where: {id: 1}, limit: 1).to_return(
|
108
|
-
body: [{id: 1, name: 'Armada Original'}].to_json
|
109
|
-
)
|
110
|
-
|
111
|
-
fleet = Fleet.find(1)
|
112
|
-
ship = Ship.find(1)
|
113
|
-
|
114
|
-
req_stub = webmock(:patch, '/ships/1').with(
|
115
|
-
body: {
|
116
|
-
ship: { fleet_id: 1 }
|
117
|
-
}.to_json
|
118
|
-
).to_return(
|
119
|
-
body: {
|
120
|
-
id: 1,
|
121
|
-
fleet_id: 1,
|
122
|
-
name: 'My Ship'
|
123
|
-
}.to_json
|
124
|
-
)
|
125
|
-
|
126
|
-
ship.fleet = fleet
|
127
|
-
assert ship.save
|
128
|
-
assert_equal 1, ship.id
|
129
|
-
assert_equal 1, ship.fleet_id
|
130
|
-
assert_equal 'My Ship', ship.name
|
131
|
-
|
132
|
-
assert_requested req_stub
|
133
|
-
end
|
134
|
-
|
135
|
-
test '#save persisted record doesnt include loaded belongs_to association' do
|
136
|
-
webmock(:get, "/ships", where: {id: 1}, limit: 1, include: [:fleet]).to_return(
|
137
|
-
body: [{id: 1, fleet_id: 1, name: 'Ship Uno', fleet: {id: 1, name: 'Armada Original'}}].to_json
|
138
|
-
)
|
139
|
-
|
140
|
-
ship = Ship.eager_load(:fleet).find(1)
|
141
|
-
|
142
|
-
req_stub = webmock(:patch, '/ships/1').with(
|
143
|
-
body: {
|
144
|
-
ship: { name: 'New NAME!!' }
|
145
|
-
}.to_json
|
146
|
-
).to_return(
|
147
|
-
body: {
|
148
|
-
id: 1,
|
149
|
-
fleet_id: 1,
|
150
|
-
name: 'New NAME!!'
|
151
|
-
}.to_json
|
152
|
-
)
|
153
|
-
|
154
|
-
|
155
|
-
assert ship.association(:fleet).loaded?
|
156
|
-
ship.name = 'New NAME!!'
|
157
|
-
assert ship.save
|
158
|
-
|
159
|
-
assert_requested req_stub
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|