rom-yesql 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
- require 'rom/relation'
2
- require 'rom/yesql/relation/class_interface'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/core/class_attributes"
4
+
5
+ require "rom/relation"
6
+ require "rom/yesql/relation/class_interface"
3
7
 
4
8
  module ROM
5
9
  module Yesql
@@ -11,7 +15,9 @@ module ROM
11
15
  # It also supports overriding query_proc
12
16
  #
13
17
  # @example
14
- # ROM.setup(:yesql, [uri, path: '/my/sql/queries/are/here'])
18
+ # conf = ROM::Configuration.new(
19
+ # :yesql, ['sqlite::memory', path: '/my/sql/queries/are/here']
20
+ # )
15
21
  #
16
22
  # class Reports < ROM::Relation[:yesql]
17
23
  # query_proc(proc { |name, query, *args|
@@ -19,15 +25,17 @@ module ROM
19
25
  # })
20
26
  # end
21
27
  #
22
- # rom = ROM.finalize.env
28
+ # conf.register_relation(Reports)
23
29
  #
24
- # rom.relation(:reports) # use like a normal rom relation
30
+ # rom = ROM.container(conf)
31
+ #
32
+ # rom.relations[:reports] # use like a normal rom relation
25
33
  #
26
34
  # @api public
27
35
  class Relation < ROM::Relation
28
36
  adapter :yesql
29
37
 
30
- extend ClassMacros
38
+ extend Dry::Core::ClassAttributes
31
39
 
32
40
  defines :query_proc
33
41
 
@@ -43,10 +51,9 @@ module ROM
43
51
  def self.inherited(klass)
44
52
  super
45
53
  klass.extend(ClassInterface)
46
- define_query_methods(klass, queries[klass.dataset] || {})
47
54
  end
48
55
 
49
- # Extend provided klass with query methods
56
+ # Extends provided klass with query methods
50
57
  #
51
58
  # @param [Class] klass A relation class
52
59
  # @param [Hash] queries A hash with name, query pairs for the relation
@@ -66,7 +73,7 @@ module ROM
66
73
  #
67
74
  # @return [Hash]
68
75
  #
69
- # @api privatek
76
+ # @api private
70
77
  def self.queries
71
78
  @queries || {}
72
79
  end
@@ -86,7 +93,7 @@ module ROM
86
93
  @queries
87
94
  end
88
95
 
89
- # Return query proc set on a relation class
96
+ # Returns query proc set on a relation class
90
97
  #
91
98
  # By default this returns whatever was set in the gateway or the default
92
99
  # one which simply uses hash % query to evaluate a query string
@@ -1,21 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Yesql
3
5
  class Relation < ROM::Relation
4
6
  module ClassInterface
5
- # Set dataset name for the relation class
7
+ # Sets dataset name for the relation class
6
8
  #
7
9
  # The class will be extended with queries registered under that name.
8
10
  # By default dataset name is derived from the class name, which doesn't
9
- # have to match they key under which its queries were registered
11
+ # have to match the key under which its queries were registered
12
+ #
13
+ # @param name [String]
10
14
  #
11
15
  # @return [Symbol]
12
16
  #
13
17
  # @api public
14
18
  def dataset(name = Undefined)
15
- return @dataset if name == Undefined
16
- @dataset = name
19
+ name = relation_name.to_sym if name == Undefined
17
20
  define_query_methods(self, Relation.queries[name] || {})
18
- @dataset
21
+ ->(*) { self }
19
22
  end
20
23
  end
21
24
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Yesql
3
- VERSION = '0.2.0'.freeze
5
+ VERSION = "1.0.0"
4
6
  end
5
7
  end
@@ -0,0 +1,2 @@
1
+ name: rom-yesql
2
+ codacy_id: 88fbb464691e4666b94e0455468b68bf
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "rubocop/rake_task"
3
5
 
@@ -8,11 +10,10 @@ begin
8
10
  end
9
11
 
10
12
  namespace :rubocop do
11
- desc 'Generate a configuration file acting as a TODO list.'
13
+ desc "Generate a configuration file acting as a TODO list."
12
14
  task :auto_gen_config do
13
15
  exec "bundle exec rubocop --auto-gen-config"
14
16
  end
15
17
  end
16
-
17
18
  rescue LoadError
18
19
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'rom/yesql/version'
@@ -18,8 +17,9 @@ Gem::Specification.new do |spec|
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
21
- spec.add_runtime_dependency 'rom', '~> 0.9', '>= 0.9.0'
22
- spec.add_runtime_dependency 'sequel', '~> 4.19.0'
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
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'ROM / Yesql' do
4
- include_context 'users and tasks'
3
+ require "spec_helper"
5
4
 
6
- let(:rom) { setup.finalize }
5
+ RSpec.describe "ROM / Yesql" do
6
+ include_context "users and tasks"
7
7
 
8
- let!(:setup) do
9
- ROM.setup(:yesql, [uri, path: path, queries: { reports: report_queries }])
8
+ let(:container) { ROM.container(configuration) }
9
+
10
+ let!(:configuration) do
11
+ ROM::Configuration.new(:yesql, [uri, path: path, queries: {reports: report_queries}])
10
12
  end
11
13
 
12
- let(:report_queries) { { all_users: 'SELECT * FROM users ORDER BY %{order}' } }
14
+ let(:report_queries) { {all_users: "SELECT * FROM users ORDER BY %{order}"} }
13
15
 
14
- let(:users) { rom.relation(:users) }
15
- let(:tasks) { rom.relation(:tasks) }
16
- let(:reports) { rom.relation(:reports) }
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
- class Users < ROM::Relation[:yesql]
20
- end
21
-
22
- class Tasks < ROM::Relation[:yesql]
23
- query_proc(proc { |_name, query, opts| query.gsub(':id:', opts[:id].to_s) })
21
+ configuration.relation(:users)
22
+ configuration.relation(:tasks) do
23
+ query_proc(proc { |_name, query, opts| query.gsub(":id:", opts[:id].to_s) })
24
24
  end
25
25
 
26
26
  module Test
27
27
  class Reports < ROM::Relation[:yesql]
28
- dataset :reports
28
+ schema :reports, infer: true
29
29
  end
30
30
  end
31
+
32
+ configuration.register_relation(Test::Reports)
31
33
  end
32
34
 
33
- describe 'query method' do
34
- it 'uses hash-based interpolation by default' do
35
- expect(users.by_name(name: 'Jane')).to match_array([
36
- { id: 1, name: 'Jane' }
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 'uses provided proc to preprocess a query' do
42
+ it "uses provided proc to preprocess a query" do
41
43
  expect(tasks.by_id(id: 1)).to match_array([
42
- { id: 1, title: 'Task One' }
44
+ {id: 1, title: "Task One"}
43
45
  ])
44
46
  end
45
47
 
46
- it 'uses queries provided explicitly during setup' do
47
- expect(reports.all_users(order: 'name').to_a).to eql([
48
- { id: 3, name: 'Jade' },
49
- { id: 1, name: 'Jane' },
50
- { id: 2, name: 'Joe' }
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 'returns rom relation' do
55
- relation = users.by_name(name: 'Jane') >> proc { |r| r.map { |t| t[:name] } }
56
- expect(relation).to match_array(['Jane'])
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
- shared_context 'database setup' do
2
- include_context 'gateway setup'
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
- [:users, :tasks].each { |name| conn.drop_table?(name) }
9
+ %i[users tasks].each { |name| conn.drop_table?(name) }
8
10
  end
9
11
 
10
12
  before do
@@ -1,10 +1,12 @@
1
- shared_context 'gateway setup' do
2
- let(:root) { Pathname(__FILE__).dirname.join('../..') }
3
- let(:path) { root.join('spec/fixtures') }
1
+ # frozen_string_literal: true
4
2
 
5
- if RUBY_ENGINE == 'jruby'
6
- let(:uri) { "jdbc:sqlite://#{root.join('db/test.sqlite')}" }
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('db/test.sqlite')}" }
10
+ let(:uri) { "sqlite://#{root.join("db/test.sqlite")}" }
9
11
  end
10
12
  end
@@ -1,12 +1,14 @@
1
- shared_context 'users and tasks' do
2
- include_context 'database setup'
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: 'Jane'
6
- conn[:users].insert id: 2, name: 'Joe'
7
- conn[:users].insert id: 3, name: 'Jade'
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: 'Task One'
10
- conn[:tasks].insert id: 2, title: 'Task Two'
11
+ conn[:tasks].insert id: 1, title: "Task One"
12
+ conn[:tasks].insert id: 2, title: "Task Two"
11
13
  end
12
14
  end
@@ -1,39 +1,39 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'bundler'
3
+ require "bundler"
4
4
  Bundler.setup
5
5
 
6
- if RUBY_ENGINE == 'rbx'
7
- require "codeclimate-test-reporter"
8
- CodeClimate::TestReporter.start
9
- end
6
+ require_relative "support/coverage" if ENV["COVERAGE"] == "true"
7
+
8
+ require_relative "support/warnings"
9
+
10
+ Warning.process { |w| raise w } if ENV["FAIL_ON_WARNINGS"].eql?("true")
10
11
 
11
- require 'rom-yesql'
12
- # FIXME: why do we need to require it manually??
13
- require 'sequel/adapters/sqlite' unless RUBY_ENGINE == 'jruby'
14
- require 'inflecto'
15
- require 'logger'
12
+ require "rom-yesql"
13
+ require "inflecto"
14
+ require "logger"
16
15
 
17
16
  begin
18
- require 'byebug'
17
+ require "byebug"
19
18
  rescue LoadError
20
19
  end
21
20
 
22
- LOGGER = Logger.new(File.open('./log/test.log', 'a'))
21
+ LOGGER = Logger.new(File.open("./log/test.log", "a"))
23
22
 
24
23
  root = Pathname(__FILE__).dirname
25
24
 
26
- Dir[root.join('shared/*.rb').to_s].each { |f| require f }
27
-
28
25
  RSpec.configure do |config|
29
26
  config.before do
30
- @constants = Object.constants
27
+ module Test
28
+ end
31
29
  end
32
30
 
33
31
  config.after do
34
- added_constants = Object.constants - @constants
35
- added_constants.each { |name| Object.send(:remove_const, name) }
32
+ Object.send(:remove_const, :Test)
36
33
  end
34
+
35
+ config.disable_monkey_patching!
36
+ config.warnings = true
37
37
  end
38
38
 
39
- ROM.use :auto_registration
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
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe ROM::Yesql::Gateway do
4
- include_context 'gateway setup'
3
+ require "spec_helper"
5
4
 
6
- it 'loads queries from file system when :path is provided' do
5
+ RSpec.describe ROM::Yesql::Gateway do
6
+ include_context "gateway setup"
7
+
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 'combines queries from :queries option and loaded from provided :path' do
13
- queries = { reports: { true: 'SELECT 1' } }
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 'loads queries from :queries option' do
20
- queries = { reports: { true: 'SELECT 1' } }
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 'loads empty queries hash when no options were provided' do
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 'freezes queries' do
33
- queries = { reports: { true: 'SELECT 1' } }
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.2.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: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2020-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rom
@@ -16,34 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.9'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.9.0
19
+ version: '5'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.9'
30
- - - ">="
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
31
39
  - !ruby/object:Gem::Version
32
- version: 0.9.0
40
+ version: '0.4'
33
41
  - !ruby/object:Gem::Dependency
34
42
  name: sequel
35
43
  requirement: !ruby/object:Gem::Requirement
36
44
  requirements:
37
45
  - - "~>"
38
46
  - !ruby/object:Gem::Version
39
- version: 4.19.0
47
+ version: '5'
40
48
  type: :runtime
41
49
  prerelease: false
42
50
  version_requirements: !ruby/object:Gem::Requirement
43
51
  requirements:
44
52
  - - "~>"
45
53
  - !ruby/object:Gem::Version
46
- version: 4.19.0
54
+ version: '5'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: bundler
49
57
  requirement: !ruby/object:Gem::Requirement
@@ -79,17 +87,26 @@ executables: []
79
87
  extensions: []
80
88
  extra_rdoc_files: []
81
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"
82
97
  - ".gitignore"
83
98
  - ".rspec"
84
99
  - ".rubocop.yml"
85
- - ".rubocop_todo.yml"
86
- - ".travis.yml"
87
100
  - CHANGELOG.md
101
+ - CODE_OF_CONDUCT.md
102
+ - CONTRIBUTING.md
88
103
  - Gemfile
104
+ - Gemfile.devtools
89
105
  - Guardfile
90
- - LICENSE.txt
106
+ - LICENSE
91
107
  - README.md
92
108
  - Rakefile
109
+ - changelog.yml
93
110
  - db/.gitkeep
94
111
  - lib/rom-yesql.rb
95
112
  - lib/rom/yesql.rb
@@ -99,6 +116,7 @@ files:
99
116
  - lib/rom/yesql/relation/class_interface.rb
100
117
  - lib/rom/yesql/version.rb
101
118
  - log/.gitkeep
119
+ - project.yml
102
120
  - rakelib/rubocop.rake
103
121
  - rom-yesql.gemspec
104
122
  - spec/fixtures/tasks/by_id.sql
@@ -108,12 +126,14 @@ files:
108
126
  - spec/shared/repository_setup.rb
109
127
  - spec/shared/users_and_tasks.rb
110
128
  - spec/spec_helper.rb
129
+ - spec/support/coverage.rb
130
+ - spec/support/warnings.rb
111
131
  - spec/unit/rom/yesql/repository_spec.rb
112
132
  homepage: http://rom-rb.org
113
133
  licenses:
114
134
  - MIT
115
135
  metadata: {}
116
- post_install_message:
136
+ post_install_message:
117
137
  rdoc_options: []
118
138
  require_paths:
119
139
  - lib
@@ -128,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
148
  - !ruby/object:Gem::Version
129
149
  version: '0'
130
150
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.4.5
133
- signing_key:
151
+ rubygems_version: 3.1.4
152
+ signing_key:
134
153
  specification_version: 4
135
154
  summary: Yesql adapter for ROM
136
155
  test_files:
@@ -141,4 +160,6 @@ test_files:
141
160
  - spec/shared/repository_setup.rb
142
161
  - spec/shared/users_and_tasks.rb
143
162
  - spec/spec_helper.rb
163
+ - spec/support/coverage.rb
164
+ - spec/support/warnings.rb
144
165
  - spec/unit/rom/yesql/repository_spec.rb