yesql 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -22
  3. data/lib/.rbnext/2.3/yesql/errors/file_path_does_not_exist_error.rb +40 -0
  4. data/lib/.rbnext/2.3/yesql/errors/no_bindings_provided_error.rb +38 -0
  5. data/lib/.rbnext/2.3/yesql/errors/output_argument_error.rb +31 -0
  6. data/lib/.rbnext/2.3/yesql/query/transform_result.rb +48 -0
  7. data/lib/.rbnext/2.7/yesql/bindings/extract.rb +71 -0
  8. data/lib/.rbnext/2.7/yesql/bindings/extractor.rb +38 -0
  9. data/lib/.rbnext/2.7/yesql/bindings/transformed.rb +58 -0
  10. data/lib/.rbnext/2.7/yesql/bindings/utils.rb +16 -0
  11. data/lib/.rbnext/2.7/yesql/errors/file_path_does_not_exist_error.rb +43 -0
  12. data/lib/.rbnext/2.7/yesql/errors/no_bindings_provided_error.rb +41 -0
  13. data/lib/.rbnext/2.7/yesql/query/transform_result.rb +48 -0
  14. data/lib/.rbnext/2.7/yesql/statement.rb +44 -0
  15. data/lib/.rbnext/2.7/yesql/utils/read.rb +20 -0
  16. data/lib/.rbnext/3.0/yesql/bindings/extract.rb +71 -0
  17. data/lib/.rbnext/3.0/yesql/bindings/transformed.rb +58 -0
  18. data/lib/.rbnext/3.0/yesql/common/adapter.rb +18 -0
  19. data/lib/.rbnext/3.0/yesql/config/configuration.rb +32 -0
  20. data/lib/.rbnext/3.0/yesql/errors/file_path_does_not_exist_error.rb +43 -0
  21. data/lib/.rbnext/3.0/yesql/errors/no_bindings_provided_error.rb +41 -0
  22. data/lib/.rbnext/3.0/yesql/params/output.rb +26 -0
  23. data/lib/.rbnext/3.0/yesql/query/performer.rb +44 -0
  24. data/lib/.rbnext/3.0/yesql/query/result.rb +41 -0
  25. data/lib/.rbnext/3.0/yesql/query/transform_result.rb +48 -0
  26. data/lib/.rbnext/3.0/yesql/statement.rb +44 -0
  27. data/lib/.rbnext/3.0/yesql/utils/read.rb +20 -0
  28. data/lib/yesql.rb +25 -31
  29. data/lib/yesql/bindings/extract.rb +15 -21
  30. data/lib/yesql/bindings/extractor.rb +21 -21
  31. data/lib/yesql/bindings/transformed.rb +8 -11
  32. data/lib/yesql/bindings/utils.rb +7 -5
  33. data/lib/yesql/common/adapter.rb +6 -13
  34. data/lib/yesql/config/configuration.rb +4 -5
  35. data/lib/yesql/errors/file_path_does_not_exist_error.rb +22 -17
  36. data/lib/yesql/errors/no_bindings_provided_error.rb +18 -19
  37. data/lib/yesql/errors/output_argument_error.rb +13 -4
  38. data/lib/yesql/params/output.rb +6 -14
  39. data/lib/yesql/query/performer.rb +13 -42
  40. data/lib/yesql/query/result.rb +12 -17
  41. data/lib/yesql/query/transform_result.rb +11 -21
  42. data/lib/yesql/statement.rb +19 -24
  43. data/lib/yesql/utils/read.rb +11 -8
  44. data/lib/yesql/version.rb +1 -1
  45. metadata +47 -17
  46. data/.gitignore +0 -4
  47. data/.rubocop.yml +0 -20
  48. data/Gemfile +0 -9
  49. data/Gemfile.lock +0 -167
  50. data/Rakefile +0 -1
  51. data/bin/console +0 -14
  52. data/bin/setup +0 -8
  53. data/lib/yesql/errors/cache_expiration_error.rb +0 -18
  54. data/yesql.gemspec +0 -28
@@ -1,49 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
3
+ require "active_record"
4
4
 
5
- require 'yesql/utils/read'
6
- require 'yesql/bindings/extractor'
7
- require 'yesql/common/adapter'
5
+ require "forwardable"
6
+
7
+ require "yesql/utils/read"
8
+ require "yesql/bindings/extractor"
9
+ require "yesql/common/adapter"
8
10
 
9
11
  module ::YeSQL
10
12
  class Statement
11
- extend Forwardable
13
+ extend ::Forwardable
12
14
 
13
15
  include ::YeSQL::Common::Adapter
16
+ include ::YeSQL::Utils::Read
17
+ # Give access to the quote method.
18
+ include ::ActiveRecord::ConnectionAdapters::Quoting
14
19
 
15
20
  def initialize(bindings = {}, file_path)
16
21
  @bindings = bindings
17
- @connection = ::ActiveRecord::Base.connection
18
22
  @file_path = file_path
19
23
  end
20
24
 
21
25
  def bound
22
- to_s.gsub(::YeSQL::BIND_REGEX) do |match|
23
- extractor[match[/(\w+)/].to_sym].tap do |extract|
24
- break quote(extract[:value]) if view?
25
-
26
- break extract[:bind][:vars]
27
- end
28
- end
29
- end
30
-
31
- def to_s
32
- @to_s ||= ::YeSQL::Utils::Read.statement(file_path, readable: true)
26
+ to_s.gsub(::YeSQL::BIND_REGEX) { extract_bind_values(extractor[_1[/(\w+)/].to_sym]) }
33
27
  end
34
28
 
35
- def view?
36
- to_s =~ /^create\s.*view\s/i
37
- end
29
+ def to_s = @to_s ||= statement(readable: true)
30
+ def view? = to_s =~ /^create\s.*view\s/i
38
31
 
39
32
  private
40
33
 
41
- def_delegator(:connection, :quote)
34
+ attr_reader :bindings, :file_path
42
35
 
43
- attr_reader :bindings, :connection, :file_path
36
+ def extract_bind_values(match)
37
+ return quote(match[:value]) if view?
44
38
 
45
- def extractor
46
- ::YeSQL::Bindings::Extractor.new(bindings: bindings).call
39
+ match[:bind][:vars]
47
40
  end
41
+
42
+ def extractor = @extractor ||= ::YeSQL::Bindings::Extractor.new(bindings: bindings).call
48
43
  end
49
44
  end
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module YeSQL
3
+ module ::YeSQL
4
4
  module Utils
5
5
  module Read
6
- def self.statement(file_path, readable: false)
7
- Dir["./#{::YeSQL.config.path}/**/*.sql"]
8
- .find { |dir_file_path| dir_file_path.include?("#{file_path}.sql") }
9
- .tap do |sql_file_path|
10
- break File.readlines(sql_file_path, chomp: true).join(' ') if readable == true
6
+ def statement(readable: false) = read_file(found_file, readable)
11
7
 
12
- break File.read(sql_file_path)
13
- end
8
+ private
9
+
10
+ def read_file(file, readable)
11
+ return File.readlines(file, chomp: true).join(" ") if readable == true
12
+
13
+ File.read(file)
14
14
  end
15
+
16
+ def found_file = dir_sql_files.find { _1.include?("#{file_path}.sql") }
17
+ def dir_sql_files = Dir["./#{::YeSQL.config.path}/**/*.sql"]
15
18
  end
16
19
  end
17
20
  end
data/lib/yesql/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YeSQL
4
- VERSION = '0.1.8'
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yesql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastián Palma
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-16 00:00:00.000000000 Z
11
+ date: 2021-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: 4.0.0.beta1
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: '5.0'
26
+ version: 4.0.0.beta1
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-next-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.12.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.12.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: mysql2
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -87,15 +101,33 @@ executables: []
87
101
  extensions: []
88
102
  extra_rdoc_files: []
89
103
  files:
90
- - ".gitignore"
91
- - ".rubocop.yml"
92
- - Gemfile
93
- - Gemfile.lock
94
104
  - LICENSE.txt
95
105
  - README.md
96
- - Rakefile
97
- - bin/console
98
- - bin/setup
106
+ - lib/.rbnext/2.3/yesql/errors/file_path_does_not_exist_error.rb
107
+ - lib/.rbnext/2.3/yesql/errors/no_bindings_provided_error.rb
108
+ - lib/.rbnext/2.3/yesql/errors/output_argument_error.rb
109
+ - lib/.rbnext/2.3/yesql/query/transform_result.rb
110
+ - lib/.rbnext/2.7/yesql/bindings/extract.rb
111
+ - lib/.rbnext/2.7/yesql/bindings/extractor.rb
112
+ - lib/.rbnext/2.7/yesql/bindings/transformed.rb
113
+ - lib/.rbnext/2.7/yesql/bindings/utils.rb
114
+ - lib/.rbnext/2.7/yesql/errors/file_path_does_not_exist_error.rb
115
+ - lib/.rbnext/2.7/yesql/errors/no_bindings_provided_error.rb
116
+ - lib/.rbnext/2.7/yesql/query/transform_result.rb
117
+ - lib/.rbnext/2.7/yesql/statement.rb
118
+ - lib/.rbnext/2.7/yesql/utils/read.rb
119
+ - lib/.rbnext/3.0/yesql/bindings/extract.rb
120
+ - lib/.rbnext/3.0/yesql/bindings/transformed.rb
121
+ - lib/.rbnext/3.0/yesql/common/adapter.rb
122
+ - lib/.rbnext/3.0/yesql/config/configuration.rb
123
+ - lib/.rbnext/3.0/yesql/errors/file_path_does_not_exist_error.rb
124
+ - lib/.rbnext/3.0/yesql/errors/no_bindings_provided_error.rb
125
+ - lib/.rbnext/3.0/yesql/params/output.rb
126
+ - lib/.rbnext/3.0/yesql/query/performer.rb
127
+ - lib/.rbnext/3.0/yesql/query/result.rb
128
+ - lib/.rbnext/3.0/yesql/query/transform_result.rb
129
+ - lib/.rbnext/3.0/yesql/statement.rb
130
+ - lib/.rbnext/3.0/yesql/utils/read.rb
99
131
  - lib/yesql.rb
100
132
  - lib/yesql/bindings/extract.rb
101
133
  - lib/yesql/bindings/extractor.rb
@@ -103,7 +135,6 @@ files:
103
135
  - lib/yesql/bindings/utils.rb
104
136
  - lib/yesql/common/adapter.rb
105
137
  - lib/yesql/config/configuration.rb
106
- - lib/yesql/errors/cache_expiration_error.rb
107
138
  - lib/yesql/errors/file_path_does_not_exist_error.rb
108
139
  - lib/yesql/errors/no_bindings_provided_error.rb
109
140
  - lib/yesql/errors/output_argument_error.rb
@@ -114,7 +145,6 @@ files:
114
145
  - lib/yesql/statement.rb
115
146
  - lib/yesql/utils/read.rb
116
147
  - lib/yesql/version.rb
117
- - yesql.gemspec
118
148
  homepage: https://github.com/sebastian-palma/yesql
119
149
  licenses:
120
150
  - MIT
@@ -122,7 +152,7 @@ metadata:
122
152
  homepage_uri: https://github.com/sebastian-palma/yesql
123
153
  source_code_uri: https://github.com/sebastian-palma/yesql
124
154
  changelog_uri: https://github.com/sebastian-palma/yesql
125
- post_install_message:
155
+ post_install_message:
126
156
  rdoc_options: []
127
157
  require_paths:
128
158
  - lib
@@ -138,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
168
  version: '0'
139
169
  requirements: []
140
170
  rubygems_version: 3.2.3
141
- signing_key:
171
+ signing_key:
142
172
  specification_version: 4
143
173
  summary: Ruby library to use SQL
144
174
  test_files: []
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- spec/minimalpg/log/*
2
- spec/minimalmysql/log/*
3
- spec/minimalpg/db/*
4
- spec/minimalmysql/db/*
data/.rubocop.yml DELETED
@@ -1,20 +0,0 @@
1
- require: rubocop-rspec
2
-
3
- Metrics/BlockLength:
4
- Exclude:
5
- - spec/**/*_spec.rb
6
- - spec/spec_helper.rb
7
- - spec/yesql/shared/*
8
-
9
- RSpec/FilePath:
10
- Exclude:
11
- - spec/**/*_spec.rb
12
-
13
- RSpec/NestedGroups:
14
- Enabled: False
15
-
16
- RSpec/ExampleLength:
17
- Enabled: False
18
-
19
- RSpec/BeforeAfterAll:
20
- Enabled: False
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- gemspec
6
-
7
- group :docs do
8
- gem 'yard'
9
- end
data/Gemfile.lock DELETED
@@ -1,167 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- yesql (0.1.7)
5
- rails (>= 5.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (6.0.3.4)
11
- actionpack (= 6.0.3.4)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.3.4)
15
- actionpack (= 6.0.3.4)
16
- activejob (= 6.0.3.4)
17
- activerecord (= 6.0.3.4)
18
- activestorage (= 6.0.3.4)
19
- activesupport (= 6.0.3.4)
20
- mail (>= 2.7.1)
21
- actionmailer (6.0.3.4)
22
- actionpack (= 6.0.3.4)
23
- actionview (= 6.0.3.4)
24
- activejob (= 6.0.3.4)
25
- mail (~> 2.5, >= 2.5.4)
26
- rails-dom-testing (~> 2.0)
27
- actionpack (6.0.3.4)
28
- actionview (= 6.0.3.4)
29
- activesupport (= 6.0.3.4)
30
- rack (~> 2.0, >= 2.0.8)
31
- rack-test (>= 0.6.3)
32
- rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.3.4)
35
- actionpack (= 6.0.3.4)
36
- activerecord (= 6.0.3.4)
37
- activestorage (= 6.0.3.4)
38
- activesupport (= 6.0.3.4)
39
- nokogiri (>= 1.8.5)
40
- actionview (6.0.3.4)
41
- activesupport (= 6.0.3.4)
42
- builder (~> 3.1)
43
- erubi (~> 1.4)
44
- rails-dom-testing (~> 2.0)
45
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.3.4)
47
- activesupport (= 6.0.3.4)
48
- globalid (>= 0.3.6)
49
- activemodel (6.0.3.4)
50
- activesupport (= 6.0.3.4)
51
- activerecord (6.0.3.4)
52
- activemodel (= 6.0.3.4)
53
- activesupport (= 6.0.3.4)
54
- activestorage (6.0.3.4)
55
- actionpack (= 6.0.3.4)
56
- activejob (= 6.0.3.4)
57
- activerecord (= 6.0.3.4)
58
- marcel (~> 0.3.1)
59
- activesupport (6.0.3.4)
60
- concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (>= 0.7, < 2)
62
- minitest (~> 5.1)
63
- tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2, >= 2.2.2)
65
- builder (3.2.4)
66
- coderay (1.1.3)
67
- concurrent-ruby (1.1.8)
68
- crass (1.0.6)
69
- diff-lcs (1.4.4)
70
- erubi (1.10.0)
71
- globalid (0.4.2)
72
- activesupport (>= 4.2.0)
73
- i18n (1.8.9)
74
- concurrent-ruby (~> 1.0)
75
- loofah (2.9.0)
76
- crass (~> 1.0.2)
77
- nokogiri (>= 1.5.9)
78
- mail (2.7.1)
79
- mini_mime (>= 0.1.1)
80
- marcel (0.3.3)
81
- mimemagic (~> 0.3.2)
82
- method_source (1.0.0)
83
- mimemagic (0.3.5)
84
- mini_mime (1.0.2)
85
- minitest (5.14.4)
86
- mysql2 (0.5.3)
87
- nio4r (2.5.7)
88
- nokogiri (1.11.2-x86_64-darwin)
89
- racc (~> 1.4)
90
- pg (1.2.3)
91
- pry (0.13.1)
92
- coderay (~> 1.1)
93
- method_source (~> 1.0)
94
- racc (1.5.2)
95
- rack (2.2.3)
96
- rack-test (1.1.0)
97
- rack (>= 1.0, < 3)
98
- rails (6.0.3.4)
99
- actioncable (= 6.0.3.4)
100
- actionmailbox (= 6.0.3.4)
101
- actionmailer (= 6.0.3.4)
102
- actionpack (= 6.0.3.4)
103
- actiontext (= 6.0.3.4)
104
- actionview (= 6.0.3.4)
105
- activejob (= 6.0.3.4)
106
- activemodel (= 6.0.3.4)
107
- activerecord (= 6.0.3.4)
108
- activestorage (= 6.0.3.4)
109
- activesupport (= 6.0.3.4)
110
- bundler (>= 1.3.0)
111
- railties (= 6.0.3.4)
112
- sprockets-rails (>= 2.0.0)
113
- rails-dom-testing (2.0.3)
114
- activesupport (>= 4.2.0)
115
- nokogiri (>= 1.6)
116
- rails-html-sanitizer (1.3.0)
117
- loofah (~> 2.3)
118
- railties (6.0.3.4)
119
- actionpack (= 6.0.3.4)
120
- activesupport (= 6.0.3.4)
121
- method_source
122
- rake (>= 0.8.7)
123
- thor (>= 0.20.3, < 2.0)
124
- rake (13.0.3)
125
- rspec (3.9.0)
126
- rspec-core (~> 3.9.0)
127
- rspec-expectations (~> 3.9.0)
128
- rspec-mocks (~> 3.9.0)
129
- rspec-core (3.9.2)
130
- rspec-support (~> 3.9.3)
131
- rspec-expectations (3.9.2)
132
- diff-lcs (>= 1.2.0, < 2.0)
133
- rspec-support (~> 3.9.0)
134
- rspec-mocks (3.9.1)
135
- diff-lcs (>= 1.2.0, < 2.0)
136
- rspec-support (~> 3.9.0)
137
- rspec-support (3.9.3)
138
- sprockets (4.0.2)
139
- concurrent-ruby (~> 1.0)
140
- rack (> 1, < 3)
141
- sprockets-rails (3.2.2)
142
- actionpack (>= 4.0)
143
- activesupport (>= 4.0)
144
- sprockets (>= 3.0.0)
145
- thor (1.1.0)
146
- thread_safe (0.3.6)
147
- tzinfo (1.2.9)
148
- thread_safe (~> 0.1)
149
- websocket-driver (0.7.3)
150
- websocket-extensions (>= 0.1.0)
151
- websocket-extensions (0.1.5)
152
- yard (0.9.25)
153
- zeitwerk (2.4.2)
154
-
155
- PLATFORMS
156
- ruby
157
-
158
- DEPENDENCIES
159
- mysql2 (~> 0.5.3)
160
- pg (>= 0.18)
161
- pry (~> 0.13.1)
162
- rspec (~> 3.9.0)
163
- yard
164
- yesql!
165
-
166
- BUNDLED WITH
167
- 2.2.3
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- # frozen_string_literal: true
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "yesql"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)