rom-yesql 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d2f166f3d42301d471b4979669d1da6895a2cff
4
- data.tar.gz: 3aeb1b4e7a6aa628b37a67fb6c82c1b56b76281e
3
+ metadata.gz: 2aedcc9a8aee73d1d75cf44cf9ffcea7c2750e64
4
+ data.tar.gz: fb51885ac908e9131e4ceca401549ad214097391
5
5
  SHA512:
6
- metadata.gz: d94b71f2804916243042a0b34236303deba1fdc6b8ff8a850572927b7953b2a84743a5d90342ced89c5a82d1731130dc5117faa797c1862ff550c9319798ffd7
7
- data.tar.gz: f9f3336ac5eda3bd80a21125c1e3a332016e8230158effdc3b3473d26eba79b2fad70d4590919d9297f8bcfd185a07e629ef1df6beacf8868d4e29ad6afe8fb2
6
+ metadata.gz: ae27fce18a060dcb5f88b6c0bb8eab3acbf5dd37e8996dd3b38a8012d4a84f4bd1c4d5285076272f9ccb6c1cae187e4fa3351d0ad1594fe5849cf622aaba2343
7
+ data.tar.gz: bec60620f2ae3ae65e806b00ff320c04fb291a8895691ee170fcce48ea65602618bb4c40290d649fedd7e714cac626c91ad4c6e20e6877cfe7f2ec077194c7e5
@@ -29,7 +29,7 @@ Style/AsciiComments:
29
29
  Enabled: false
30
30
 
31
31
  # Allow using braces for value-returning blocks
32
- Style/Blocks:
32
+ Style/BlockDelimiters:
33
33
  Enabled: false
34
34
 
35
35
  # Documentation checked by Inch CI
@@ -53,10 +53,6 @@ Style/OpMethod:
53
53
  Exclude:
54
54
  - lib/rom/command_registry.rb
55
55
 
56
- # Even a single escaped slash can be confusing
57
- Style/RegexpLiteral:
58
- MaxSlashes: 0
59
-
60
56
  # Don’t introduce semantic fail/raise distinction
61
57
  Style/SignalException:
62
58
  EnforcedStyle: only_raise
@@ -1,15 +1,21 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-03-01 15:08:21 +0100 using RuboCop version 0.29.1.
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.
3
4
  # The point is for the user to remove these configuration records
4
5
  # one by one as the offenses are removed from the code base.
5
6
  # Note that changes in the inspected code, or installation of new
6
7
  # versions of RuboCop, may require this file to be generated again.
7
8
 
8
9
  # Offense count: 1
9
- Lint/HandleExceptions:
10
- Enabled: false
10
+ Metrics/AbcSize:
11
+ Max: 19
11
12
 
12
- # Offense count: 1
13
+ # Offense count: 4
13
14
  # Configuration parameters: AllowURI, URISchemes.
14
15
  Metrics/LineLength:
15
- Max: 81
16
+ Max: 83
17
+
18
+ # Offense count: 1
19
+ # Configuration parameters: CountComments.
20
+ Metrics/MethodLength:
21
+ Max: 11
@@ -4,11 +4,11 @@ cache: bundler
4
4
  bundler_args: --without tools
5
5
  script: "bundle exec rake ci"
6
6
  rvm:
7
- - 2.0
8
7
  - 2.1
9
8
  - 2.2
9
+ - 2.3.1
10
10
  - rbx-2
11
- - jruby
11
+ - jruby-9.0.5.0
12
12
  - jruby-head
13
13
  - ruby-head
14
14
  env:
@@ -1,6 +1,10 @@
1
+ ## v0.3.0 2016-07-31
2
+
3
+ Updated to work with rom 2.0.0
4
+
1
5
  ## v0.2.0 2015-08-19
2
6
 
3
- Updated to work with ROM 0.9.0
7
+ Updated to work with rom 0.9.0
4
8
 
5
9
  [Compare v0.1.1...v0.2.0](https://github.com/rom-rb/rom-yaml/compare/v0.1.0...v0.2.0)
6
10
 
@@ -8,17 +12,17 @@ Updated to work with ROM 0.9.0
8
12
 
9
13
  ### Changed
10
14
 
11
- * Updated to work with ROM 0.8 (solnic)
15
+ * Updated to work with rom 0.8 (solnic)
12
16
 
13
17
  [Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom-yaml/compare/v0.1.0...v0.1.1)
14
18
 
15
19
  ## v0.1.0 2015-03-22
16
20
 
17
- Bump ROM dep to 0.6.0 final
21
+ Bump rom dep to 0.6.0 final
18
22
 
19
23
  ## v0.0.2 2015-03-21
20
24
 
21
- Update to work with ROM 0.6.0
25
+ Update to work with rom 0.6.0
22
26
 
23
27
  ## v0.0.1 2015-03-01
24
28
 
data/Gemfile CHANGED
@@ -3,18 +3,13 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem 'rom', github: 'rom-rb/rom', branch: 'master'
7
6
  gem 'inflecto'
8
- gem 'rspec', '~> 3.1'
7
+ gem 'rspec', '~> 3.5'
9
8
  gem 'codeclimate-test-reporter', require: false
10
9
  gem 'sqlite3', platforms: [:mri, :rbx]
11
10
  gem 'jdbc-sqlite3', platforms: :jruby
12
11
  end
13
12
 
14
13
  group :tools do
15
- gem 'guard'
16
14
  gem 'byebug', platforms: [:mri]
17
- gem 'guard-rspec'
18
- gem 'guard-rubocop'
19
- gem 'rubocop', '~> 0.28'
20
15
  end
data/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
  [codeclimate]: https://codeclimate.com/github/rom-rb/rom-yesql
5
5
  [inchpages]: http://inch-ci.org/github/rom-rb/rom-yesql
6
6
 
7
- # ROM::Yesql
7
+ # rom-yesql
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/rom-yesql.svg)][gem]
10
10
  [![Build Status](https://travis-ci.org/rom-rb/rom-yesql.svg?branch=master)][travis]
11
- [![Dependency Status](https://gemnasium.com/rom-rb/rom-yesql.png)][gemnasium]
11
+ [![Dependency Status](https://gemnasium.com/rom-rb/rom-yesql.svg)][gemnasium]
12
12
  [![Code Climate](https://codeclimate.com/github/rom-rb/rom-yesql/badges/gpa.svg)][codeclimate]
13
13
  [![Test Coverage](https://codeclimate.com/github/rom-rb/rom-yesql/badges/coverage.svg)][codeclimate]
14
14
  [![Inline docs](http://inch-ci.org/github/rom-rb/rom-yesql.svg?branch=master)][inchpages]
@@ -16,6 +16,9 @@
16
16
 
17
17
  [Yesql](https://github.com/krisajenkins/yesql)-like adapter for [Ruby Object Mapper](https://github.com/rom-rb/rom).
18
18
 
19
+ * [API docs](http://rubydoc.info/gems/rom-yesql)
20
+ * [ROM user docs](http://rom-rb.org/learn)
21
+
19
22
  ## Installation
20
23
 
21
24
  Add this line to your application's Gemfile:
@@ -32,22 +35,6 @@ Or install it yourself as:
32
35
 
33
36
  $ gem install rom-yesql
34
37
 
35
- ## Synopsis
36
-
37
- ``` ruby
38
- # given sql/my_queries/users.sql includes "SELECT * FROM users WHERE name = '%{name}'"
39
-
40
- ROM.setup(:yesql, ['sqlite://path/to/your/db', path: './sql'])
41
-
42
- class MyQueries < ROM::Relation[:yesql]
43
- end
44
-
45
- rom = ROM.finalize.env
46
-
47
- my_queries = rom.relations[:my_queries]
48
- my_queries.users(name: 'Jane').to_a # => gets the users
49
- ```
50
-
51
38
  ## License
52
39
 
53
40
  See `LICENSE` file.
@@ -1,5 +1,7 @@
1
1
  require 'sequel'
2
2
 
3
+ require 'rom/support/options'
4
+
3
5
  require 'rom/yesql/dataset'
4
6
  require 'rom/yesql/relation'
5
7
 
@@ -7,49 +9,60 @@ module ROM
7
9
  module Yesql
8
10
  # Yesql gateway exposes access to configured SQL queries
9
11
  #
10
- # @example
11
- # # Load all queries from a specific path
12
- # ROM::Yesql::Gateway.new(uri, path: '/path/to/my_queries')
13
- #
14
- # # Provide queries explicitly using a hash
15
- # ROM::Yesql::Gateway.new(uri, queries: {
16
- # reports: {
17
- # all_users: 'SELECT * FROM users'
18
- # }
19
- # })
20
- #
21
- # # Override default query proc handler
22
- # ROM::Yesql::Gateway.new(uri, query_proc: proc { |name, query, *args|
23
- # # do something to return an sql string
24
- # })
12
+ # Relations created with datasets provided by this gateway automatically
13
+ # expose access to gateway's queries.
25
14
  #
26
15
  # @api public
27
16
  class Gateway < ROM::Gateway
28
17
  include Options
29
18
 
19
+ # @!attribute [r] path
20
+ # @return [String] a path to files with SQL queries
30
21
  option :path, reader: true
31
- option :queries, type: Hash, default: EMPTY_HASH
32
- option :query_proc, reader: true, default: proc { |gateway|
22
+
23
+ # @!attribute [r] queries
24
+ # @return [Hash] a hash with queries
25
+ option :queries, type: Hash, default: EMPTY_HASH, reader: true
26
+
27
+ # @!attribute [r] query_proc
28
+ # This defaults to simple interpolation of the query using option hash passed to a relation
29
+ # @return [Proc] custom query proc for pre-processing a query string
30
+ option :query_proc, reader: true, default: proc { |_gateway|
33
31
  proc do |_name, query, opts|
34
32
  query % opts
35
33
  end
36
34
  }
37
35
 
38
- # Return Sequel database connection
39
- #
40
- # @return [Sequel::Database]
41
- #
42
- # @api private
36
+ # @!attribute [r] connection
37
+ # @return [Sequel::Database] Sequel database connection
43
38
  attr_reader :connection
44
39
 
45
- # Hash with loaded queries indexed using dataset names
40
+ # Initializes a yesql gateway
46
41
  #
47
- # @return [Hash]
42
+ # @example
43
+ # # Load all queries from a specific path
44
+ # ROM::Yesql::Gateway.new(uri, path: '/path/to/my_queries')
48
45
  #
49
- # @api private
50
- attr_reader :queries
51
-
52
- # @api private
46
+ # # Provide queries explicitly using a hash
47
+ # ROM::Yesql::Gateway.new(uri, queries: {
48
+ # reports: {
49
+ # all_users: 'SELECT * FROM users'
50
+ # }
51
+ # })
52
+ #
53
+ # # Override default query proc handler
54
+ # ROM::Yesql::Gateway.new(uri, query_proc: proc { |name, query, *args|
55
+ # # do something to return an sql string
56
+ # })
57
+ #
58
+ # @param uri [String]
59
+ #
60
+ # @param options [Hash]
61
+ # @option :path [String]
62
+ # @option :queries [Hash]
63
+ # @option :query_proc [Proc]
64
+ #
65
+ # @api public
53
66
  def initialize(uri, options = {})
54
67
  super
55
68
  @connection = Sequel.connect(uri, options)
@@ -59,15 +72,23 @@ module ROM
59
72
  Relation.load_queries(queries)
60
73
  end
61
74
 
62
- # Initialize a dataset
75
+ # Initializes a dataset
63
76
  #
64
77
  # Since all relations use the same dataset we simply create one instance
65
78
  #
79
+ # @return [Dataset]
80
+ #
66
81
  # @api private
67
82
  def dataset(_name)
68
83
  @dataset ||= Dataset.new(connection)
69
84
  end
70
85
 
86
+ # Returns if a dataset with the given name exists
87
+ #
88
+ # This always returns true because all relations use the same dataset
89
+ #
90
+ # @return [True]
91
+ #
71
92
  # @api private
72
93
  def dataset?(_name)
73
94
  ! @dataset.nil?
@@ -75,7 +96,7 @@ module ROM
75
96
 
76
97
  private
77
98
 
78
- # Load queries from filesystem if :path was provided
99
+ # Loads queries from filesystem if :path was provided
79
100
  #
80
101
  # @api private
81
102
  def initialize_queries
@@ -11,7 +11,9 @@ module ROM
11
11
  # It also supports overriding query_proc
12
12
  #
13
13
  # @example
14
- # ROM.setup(:yesql, [uri, path: '/my/sql/queries/are/here'])
14
+ # conf = ROM::Configuration.new(
15
+ # :yesql, ['sqlite::memory', path: '/my/sql/queries/are/here']
16
+ # )
15
17
  #
16
18
  # class Reports < ROM::Relation[:yesql]
17
19
  # query_proc(proc { |name, query, *args|
@@ -19,9 +21,11 @@ module ROM
19
21
  # })
20
22
  # end
21
23
  #
22
- # rom = ROM.finalize.env
24
+ # conf.register_relation(Reports)
23
25
  #
24
- # rom.relation(:reports) # use like a normal rom relation
26
+ # rom = ROM.container(conf)
27
+ #
28
+ # rom.relations[:reports] # use like a normal rom relation
25
29
  #
26
30
  # @api public
27
31
  class Relation < ROM::Relation
@@ -46,7 +50,7 @@ module ROM
46
50
  define_query_methods(klass, queries[klass.dataset] || {})
47
51
  end
48
52
 
49
- # Extend provided klass with query methods
53
+ # Extends provided klass with query methods
50
54
  #
51
55
  # @param [Class] klass A relation class
52
56
  # @param [Hash] queries A hash with name, query pairs for the relation
@@ -66,7 +70,7 @@ module ROM
66
70
  #
67
71
  # @return [Hash]
68
72
  #
69
- # @api privatek
73
+ # @api private
70
74
  def self.queries
71
75
  @queries || {}
72
76
  end
@@ -86,7 +90,7 @@ module ROM
86
90
  @queries
87
91
  end
88
92
 
89
- # Return query proc set on a relation class
93
+ # Returns query proc set on a relation class
90
94
  #
91
95
  # By default this returns whatever was set in the gateway or the default
92
96
  # one which simply uses hash % query to evaluate a query string
@@ -2,11 +2,13 @@ module ROM
2
2
  module Yesql
3
3
  class Relation < ROM::Relation
4
4
  module ClassInterface
5
- # Set dataset name for the relation class
5
+ # Sets dataset name for the relation class
6
6
  #
7
7
  # The class will be extended with queries registered under that name.
8
8
  # 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
9
+ # have to match the key under which its queries were registered
10
+ #
11
+ # @param name [String]
10
12
  #
11
13
  # @return [Symbol]
12
14
  #
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Yesql
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
@@ -14,5 +14,5 @@ begin
14
14
  end
15
15
  end
16
16
 
17
- rescue LoadError
17
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
18
18
  end
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'rom', '~> 0.9', '>= 0.9.0'
22
- spec.add_runtime_dependency 'sequel', '~> 4.19.0'
21
+ spec.add_runtime_dependency "rom", "~> 2.0"
22
+ spec.add_runtime_dependency 'sequel', '~> 4.27'
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  end
@@ -3,23 +3,21 @@ require 'spec_helper'
3
3
  describe 'ROM / Yesql' do
4
4
  include_context 'users and tasks'
5
5
 
6
- let(:rom) { setup.finalize }
6
+ let(:container) { ROM.container(configuration) }
7
7
 
8
- let!(:setup) do
9
- ROM.setup(:yesql, [uri, path: path, queries: { reports: report_queries }])
8
+ let!(:configuration) do
9
+ ROM::Configuration.new(:yesql, [uri, path: path, queries: { reports: report_queries }])
10
10
  end
11
11
 
12
12
  let(:report_queries) { { all_users: 'SELECT * FROM users ORDER BY %{order}' } }
13
13
 
14
- let(:users) { rom.relation(:users) }
15
- let(:tasks) { rom.relation(:tasks) }
16
- let(:reports) { rom.relation(:reports) }
14
+ let(:users) { container.relation(:users) }
15
+ let(:tasks) { container.relation(:tasks) }
16
+ let(:reports) { container.relation(:reports) }
17
17
 
18
18
  before do
19
- class Users < ROM::Relation[:yesql]
20
- end
21
-
22
- class Tasks < ROM::Relation[:yesql]
19
+ configuration.relation(:users)
20
+ configuration.relation(:tasks) do
23
21
  query_proc(proc { |_name, query, opts| query.gsub(':id:', opts[:id].to_s) })
24
22
  end
25
23
 
@@ -28,6 +26,8 @@ describe 'ROM / Yesql' do
28
26
  dataset :reports
29
27
  end
30
28
  end
29
+
30
+ configuration.register_relation(Test::Reports)
31
31
  end
32
32
 
33
33
  describe 'query method' do
@@ -16,7 +16,7 @@ require 'logger'
16
16
 
17
17
  begin
18
18
  require 'byebug'
19
- rescue LoadError
19
+ rescue LoadError # rubocop:disable Lint/HandleExceptions
20
20
  end
21
21
 
22
22
  LOGGER = Logger.new(File.open('./log/test.log', 'a'))
@@ -35,5 +35,3 @@ RSpec.configure do |config|
35
35
  added_constants.each { |name| Object.send(:remove_const, name) }
36
36
  end
37
37
  end
38
-
39
- ROM.use :auto_registration
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: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2016-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rom
@@ -16,34 +16,28 @@ 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: '2.0'
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
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.9.0
26
+ version: '2.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: sequel
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: 4.19.0
33
+ version: '4.27'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: 4.19.0
40
+ version: '4.27'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: bundler
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
123
  version: '0'
130
124
  requirements: []
131
125
  rubyforge_project:
132
- rubygems_version: 2.4.5
126
+ rubygems_version: 2.5.1
133
127
  signing_key:
134
128
  specification_version: 4
135
129
  summary: Yesql adapter for ROM