rom-yesql 0.5.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.devtools/templates/changelog.erb +40 -0
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
- data/.github/ISSUE_TEMPLATE/---bug-report.md +30 -0
- data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
- data/.github/workflows/ci.yml +82 -0
- data/.github/workflows/docsite.yml +62 -0
- data/.github/workflows/sync_configs.yml +53 -0
- data/.rspec +2 -0
- data/.rubocop.yml +117 -39
- data/CHANGELOG.md +32 -12
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +11 -7
- data/Gemfile.devtools +17 -0
- data/Guardfile +7 -5
- data/LICENSE +20 -0
- data/README.md +14 -25
- data/Rakefile +5 -3
- data/changelog.yml +33 -0
- data/lib/rom-yesql.rb +4 -2
- data/lib/rom/yesql.rb +4 -2
- data/lib/rom/yesql/dataset.rb +2 -0
- data/lib/rom/yesql/gateway.rb +8 -6
- data/lib/rom/yesql/relation.rb +5 -4
- data/lib/rom/yesql/relation/class_interface.rb +4 -3
- data/lib/rom/yesql/version.rb +3 -1
- data/project.yml +2 -0
- data/rakelib/rubocop.rake +4 -3
- data/rom-yesql.gemspec +3 -3
- data/spec/integration/adapter_spec.rb +26 -24
- data/spec/shared/database_setup.rb +5 -3
- data/spec/shared/repository_setup.rb +8 -6
- data/spec/shared/users_and_tasks.rb +9 -7
- data/spec/spec_helper.rb +14 -19
- data/spec/support/coverage.rb +15 -0
- data/spec/support/warnings.rb +10 -0
- data/spec/unit/rom/yesql/repository_spec.rb +12 -10
- metadata +29 -22
- data/.rubocop_todo.yml +0 -21
- data/.travis.yml +0 -30
- data/LICENSE.txt +0 -22
data/rom-yesql.gemspec
CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_runtime_dependency "rom", "~>
|
21
|
-
spec.add_runtime_dependency "dry-core", "~>
|
22
|
-
spec.add_runtime_dependency "sequel", "~>
|
20
|
+
spec.add_runtime_dependency "rom", "~>5"
|
21
|
+
spec.add_runtime_dependency "dry-core", "~>0.4"
|
22
|
+
spec.add_runtime_dependency "sequel", "~>5"
|
23
23
|
spec.add_development_dependency "bundler"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
end
|
@@ -1,59 +1,61 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
RSpec.describe "ROM / Yesql" do
|
6
|
+
include_context "users and tasks"
|
5
7
|
|
6
8
|
let(:container) { ROM.container(configuration) }
|
7
9
|
|
8
10
|
let!(:configuration) do
|
9
|
-
ROM::Configuration.new(:yesql, [uri, path: path, queries: {
|
11
|
+
ROM::Configuration.new(:yesql, [uri, path: path, queries: {reports: report_queries}])
|
10
12
|
end
|
11
13
|
|
12
|
-
let(:report_queries) { {
|
14
|
+
let(:report_queries) { {all_users: "SELECT * FROM users ORDER BY %{order}"} }
|
13
15
|
|
14
|
-
let(:users) { container.
|
15
|
-
let(:tasks) { container.
|
16
|
-
let(:reports) { container.
|
16
|
+
let(:users) { container.relations[:users] }
|
17
|
+
let(:tasks) { container.relations[:tasks] }
|
18
|
+
let(:reports) { container.relations[:reports] }
|
17
19
|
|
18
20
|
before do
|
19
21
|
configuration.relation(:users)
|
20
22
|
configuration.relation(:tasks) do
|
21
|
-
query_proc(proc { |_name, query, opts| query.gsub(
|
23
|
+
query_proc(proc { |_name, query, opts| query.gsub(":id:", opts[:id].to_s) })
|
22
24
|
end
|
23
25
|
|
24
26
|
module Test
|
25
27
|
class Reports < ROM::Relation[:yesql]
|
26
|
-
|
28
|
+
schema :reports, infer: true
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
32
|
configuration.register_relation(Test::Reports)
|
31
33
|
end
|
32
34
|
|
33
|
-
describe
|
34
|
-
it
|
35
|
-
expect(users.by_name(name:
|
36
|
-
{
|
35
|
+
describe "query method" do
|
36
|
+
it "uses hash-based interpolation by default" do
|
37
|
+
expect(users.by_name(name: "Jane")).to match_array([
|
38
|
+
{id: 1, name: "Jane"}
|
37
39
|
])
|
38
40
|
end
|
39
41
|
|
40
|
-
it
|
42
|
+
it "uses provided proc to preprocess a query" do
|
41
43
|
expect(tasks.by_id(id: 1)).to match_array([
|
42
|
-
{
|
44
|
+
{id: 1, title: "Task One"}
|
43
45
|
])
|
44
46
|
end
|
45
47
|
|
46
|
-
it
|
47
|
-
expect(reports.all_users(order:
|
48
|
-
{
|
49
|
-
{
|
50
|
-
{
|
48
|
+
it "uses queries provided explicitly during setup" do
|
49
|
+
expect(reports.all_users(order: "name").to_a).to eql([
|
50
|
+
{id: 3, name: "Jade"},
|
51
|
+
{id: 1, name: "Jane"},
|
52
|
+
{id: 2, name: "Joe"}
|
51
53
|
])
|
52
54
|
end
|
53
55
|
|
54
|
-
it
|
55
|
-
relation = users.by_name(name:
|
56
|
-
expect(relation).to match_array([
|
56
|
+
it "returns rom relation" do
|
57
|
+
relation = users.by_name(name: "Jane") >> proc { |r| r.map { |t| t[:name] } }
|
58
|
+
expect(relation).to match_array(["Jane"])
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_context "database setup" do
|
4
|
+
include_context "gateway setup"
|
3
5
|
|
4
6
|
let!(:conn) { Sequel.connect(uri) }
|
5
7
|
|
6
8
|
def drop_tables
|
7
|
-
[
|
9
|
+
%i[users tasks].each { |name| conn.drop_table?(name) }
|
8
10
|
end
|
9
11
|
|
10
12
|
before do
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
let(:root) { Pathname(__FILE__).dirname.join('../..') }
|
3
|
-
let(:path) { root.join('spec/fixtures') }
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
RSpec.shared_context "gateway setup" do
|
4
|
+
let(:root) { Pathname(__FILE__).dirname.join("../..") }
|
5
|
+
let(:path) { root.join("spec/fixtures") }
|
6
|
+
|
7
|
+
if RUBY_ENGINE == "jruby"
|
8
|
+
let(:uri) { "jdbc:sqlite://#{root.join("db/test.sqlite")}" }
|
7
9
|
else
|
8
|
-
let(:uri) { "sqlite://#{root.join(
|
10
|
+
let(:uri) { "sqlite://#{root.join("db/test.sqlite")}" }
|
9
11
|
end
|
10
12
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_context "users and tasks" do
|
4
|
+
include_context "database setup"
|
3
5
|
|
4
6
|
before do
|
5
|
-
conn[:users].insert id: 1, name:
|
6
|
-
conn[:users].insert id: 2, name:
|
7
|
-
conn[:users].insert id: 3, name:
|
7
|
+
conn[:users].insert id: 1, name: "Jane"
|
8
|
+
conn[:users].insert id: 2, name: "Joe"
|
9
|
+
conn[:users].insert id: 3, name: "Jade"
|
8
10
|
|
9
|
-
conn[:tasks].insert id: 1, title:
|
10
|
-
conn[:tasks].insert id: 2, title:
|
11
|
+
conn[:tasks].insert id: 1, title: "Task One"
|
12
|
+
conn[:tasks].insert id: 2, title: "Task Two"
|
11
13
|
end
|
12
14
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,29 +1,24 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler"
|
2
4
|
Bundler.setup
|
3
5
|
|
4
|
-
|
5
|
-
require 'yaml'
|
6
|
-
rubies = YAML.load(File.read(File.join(__dir__, '..', '.travis.yml')))['rvm']
|
7
|
-
latest_mri = rubies.select { |v| v =~ /\A\d+\.\d+.\d+\z/ }.max
|
6
|
+
require_relative "support/coverage" if ENV["COVERAGE"] == "true"
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
add_filter '/spec/'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
8
|
+
require_relative "support/warnings"
|
9
|
+
|
10
|
+
Warning.process { |w| raise w } if ENV["FAIL_ON_WARNINGS"].eql?("true")
|
16
11
|
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
12
|
+
require "rom-yesql"
|
13
|
+
require "inflecto"
|
14
|
+
require "logger"
|
20
15
|
|
21
16
|
begin
|
22
|
-
require
|
23
|
-
rescue LoadError
|
17
|
+
require "byebug"
|
18
|
+
rescue LoadError
|
24
19
|
end
|
25
20
|
|
26
|
-
LOGGER = Logger.new(File.open(
|
21
|
+
LOGGER = Logger.new(File.open("./log/test.log", "a"))
|
27
22
|
|
28
23
|
root = Pathname(__FILE__).dirname
|
29
24
|
|
@@ -41,4 +36,4 @@ RSpec.configure do |config|
|
|
41
36
|
config.warnings = true
|
42
37
|
end
|
43
38
|
|
44
|
-
Dir[root.join(
|
39
|
+
Dir[root.join("shared/*.rb").to_s].sort.each { |f| require f }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# this file is managed by rom-rb/devtools
|
4
|
+
|
5
|
+
if ENV["COVERAGE"] == "true"
|
6
|
+
require "simplecov"
|
7
|
+
require "simplecov-cobertura"
|
8
|
+
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
|
10
|
+
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter "/spec/"
|
13
|
+
enable_coverage :branch
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# this file is managed by rom-rb/devtools project
|
4
|
+
|
5
|
+
require "warning"
|
6
|
+
|
7
|
+
Warning.ignore(%r{rspec/core})
|
8
|
+
Warning.ignore(%r{rspec/mocks})
|
9
|
+
Warning.ignore(/codacy/)
|
10
|
+
Warning[:experimental] = false if Warning.respond_to?(:[])
|
@@ -1,36 +1,38 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
2
4
|
|
3
5
|
RSpec.describe ROM::Yesql::Gateway do
|
4
|
-
include_context
|
6
|
+
include_context "gateway setup"
|
5
7
|
|
6
|
-
it
|
8
|
+
it "loads queries from file system when :path is provided" do
|
7
9
|
gateway = ROM::Yesql::Gateway.new(uri, path: path)
|
8
10
|
|
9
11
|
expect(gateway.queries.keys).to match_array([:users, :tasks])
|
10
12
|
end
|
11
13
|
|
12
|
-
it
|
13
|
-
queries = {
|
14
|
+
it "combines queries from :queries option and loaded from provided :path" do
|
15
|
+
queries = {reports: {true: "SELECT 1"}}
|
14
16
|
gateway = ROM::Yesql::Gateway.new(uri, path: path, queries: queries)
|
15
17
|
|
16
18
|
expect(gateway.queries.keys).to match_array([:users, :tasks, :reports])
|
17
19
|
end
|
18
20
|
|
19
|
-
it
|
20
|
-
queries = {
|
21
|
+
it "loads queries from :queries option" do
|
22
|
+
queries = {reports: {true: "SELECT 1"}}
|
21
23
|
gateway = ROM::Yesql::Gateway.new(uri, queries: queries)
|
22
24
|
|
23
25
|
expect(gateway.queries).to eql(queries)
|
24
26
|
end
|
25
27
|
|
26
|
-
it
|
28
|
+
it "loads empty queries hash when no options were provided" do
|
27
29
|
gateway = ROM::Yesql::Gateway.new(uri)
|
28
30
|
|
29
31
|
expect(gateway.queries).to eql({})
|
30
32
|
end
|
31
33
|
|
32
|
-
it
|
33
|
-
queries = {
|
34
|
+
it "freezes queries" do
|
35
|
+
queries = {reports: {true: "SELECT 1"}}
|
34
36
|
gateway = ROM::Yesql::Gateway.new(uri, queries: queries)
|
35
37
|
|
36
38
|
expect(gateway.queries).to be_frozen
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-yesql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|
@@ -16,48 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dry-core
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.2.4
|
33
|
+
version: '0.4'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '0.
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.2.4
|
40
|
+
version: '0.4'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: sequel
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
50
44
|
requirements:
|
51
45
|
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
47
|
+
version: '5'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
54
|
+
version: '5'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: bundler
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,17 +87,26 @@ executables: []
|
|
93
87
|
extensions: []
|
94
88
|
extra_rdoc_files: []
|
95
89
|
files:
|
90
|
+
- ".devtools/templates/changelog.erb"
|
91
|
+
- ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
|
92
|
+
- ".github/ISSUE_TEMPLATE/---bug-report.md"
|
93
|
+
- ".github/ISSUE_TEMPLATE/---feature-request.md"
|
94
|
+
- ".github/workflows/ci.yml"
|
95
|
+
- ".github/workflows/docsite.yml"
|
96
|
+
- ".github/workflows/sync_configs.yml"
|
96
97
|
- ".gitignore"
|
97
98
|
- ".rspec"
|
98
99
|
- ".rubocop.yml"
|
99
|
-
- ".rubocop_todo.yml"
|
100
|
-
- ".travis.yml"
|
101
100
|
- CHANGELOG.md
|
101
|
+
- CODE_OF_CONDUCT.md
|
102
|
+
- CONTRIBUTING.md
|
102
103
|
- Gemfile
|
104
|
+
- Gemfile.devtools
|
103
105
|
- Guardfile
|
104
|
-
- LICENSE
|
106
|
+
- LICENSE
|
105
107
|
- README.md
|
106
108
|
- Rakefile
|
109
|
+
- changelog.yml
|
107
110
|
- db/.gitkeep
|
108
111
|
- lib/rom-yesql.rb
|
109
112
|
- lib/rom/yesql.rb
|
@@ -113,6 +116,7 @@ files:
|
|
113
116
|
- lib/rom/yesql/relation/class_interface.rb
|
114
117
|
- lib/rom/yesql/version.rb
|
115
118
|
- log/.gitkeep
|
119
|
+
- project.yml
|
116
120
|
- rakelib/rubocop.rake
|
117
121
|
- rom-yesql.gemspec
|
118
122
|
- spec/fixtures/tasks/by_id.sql
|
@@ -122,12 +126,14 @@ files:
|
|
122
126
|
- spec/shared/repository_setup.rb
|
123
127
|
- spec/shared/users_and_tasks.rb
|
124
128
|
- spec/spec_helper.rb
|
129
|
+
- spec/support/coverage.rb
|
130
|
+
- spec/support/warnings.rb
|
125
131
|
- spec/unit/rom/yesql/repository_spec.rb
|
126
132
|
homepage: http://rom-rb.org
|
127
133
|
licenses:
|
128
134
|
- MIT
|
129
135
|
metadata: {}
|
130
|
-
post_install_message:
|
136
|
+
post_install_message:
|
131
137
|
rdoc_options: []
|
132
138
|
require_paths:
|
133
139
|
- lib
|
@@ -142,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
148
|
- !ruby/object:Gem::Version
|
143
149
|
version: '0'
|
144
150
|
requirements: []
|
145
|
-
|
146
|
-
|
147
|
-
signing_key:
|
151
|
+
rubygems_version: 3.1.4
|
152
|
+
signing_key:
|
148
153
|
specification_version: 4
|
149
154
|
summary: Yesql adapter for ROM
|
150
155
|
test_files:
|
@@ -155,4 +160,6 @@ test_files:
|
|
155
160
|
- spec/shared/repository_setup.rb
|
156
161
|
- spec/shared/users_and_tasks.rb
|
157
162
|
- spec/spec_helper.rb
|
163
|
+
- spec/support/coverage.rb
|
164
|
+
- spec/support/warnings.rb
|
158
165
|
- spec/unit/rom/yesql/repository_spec.rb
|
data/.rubocop_todo.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
# `rubocop --auto-gen-config`
|
3
|
-
# on 2015-09-26 18:14:52 +0200 using RuboCop version 0.34.2.
|
4
|
-
# The point is for the user to remove these configuration records
|
5
|
-
# one by one as the offenses are removed from the code base.
|
6
|
-
# Note that changes in the inspected code, or installation of new
|
7
|
-
# versions of RuboCop, may require this file to be generated again.
|
8
|
-
|
9
|
-
# Offense count: 1
|
10
|
-
Metrics/AbcSize:
|
11
|
-
Max: 19
|
12
|
-
|
13
|
-
# Offense count: 4
|
14
|
-
# Configuration parameters: AllowURI, URISchemes.
|
15
|
-
Metrics/LineLength:
|
16
|
-
Max: 83
|
17
|
-
|
18
|
-
# Offense count: 1
|
19
|
-
# Configuration parameters: CountComments.
|
20
|
-
Metrics/MethodLength:
|
21
|
-
Max: 11
|