wise_gopher 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: dc88a6090305daa53b83df1cd298531d6209dbb74cce4aa2c1492a2c3987c168
4
- data.tar.gz: 874dc19cf652522bdb9ebf89e45543c5ce912dd8a636d6dd01bc7ab7e78e10ec
3
+ metadata.gz: 5c02358a22e231202bc1a07982b001432e9cf5ebbce2b0839a0370a77b2ce96d
4
+ data.tar.gz: 5cfdbb8afdd8ba7d818eba10ad9d5351ff7f33bc18b9412cd4461d59e944ad4b
5
5
  SHA512:
6
- metadata.gz: 4b0f65b90b90414aa03e572e33e0d3ac360f886c61afd19dc3b026b9ff0e76c9fd7040b77cf8c1b1bf89dcddd665d36e1125ff5ec27ff21c73d232b42dfeab09
7
- data.tar.gz: ed4ceb261617680856ad9896b68b1ac0711ae911edf264d3d14fde7a5b7405b2d6843cd03333be036927fe762e45b7054e023d6f53e353cd19e117f05e451db7
6
+ metadata.gz: da3df8754c9efbd3f942e61ab8e70fc6dfb9c3c349b5e537ab0b51268cd25fc490fee060d9cd33f5ded259fe42d014023a88d7a0db5295201231cdf9b47cbf1b
7
+ data.tar.gz: 123df478769d1757782525b0d18ecd43a0ecc3fb7ea22cb31bdd750f6d1bb220d88aa33976f7140737b3dd4888d7e4db9139d4a5c77bad1ae4739465773c46cf
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ # test file
14
+ .testing.rb
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wise_gopher (0.2.0)
4
+ wise_gopher (0.2.1)
5
5
  activerecord (>= 5, < 7)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.1.4)
11
- activesupport (= 6.1.4)
12
- activerecord (6.1.4)
13
- activemodel (= 6.1.4)
14
- activesupport (= 6.1.4)
15
- activesupport (6.1.4)
10
+ activemodel (6.1.4.1)
11
+ activesupport (= 6.1.4.1)
12
+ activerecord (6.1.4.1)
13
+ activemodel (= 6.1.4.1)
14
+ activesupport (= 6.1.4.1)
15
+ activesupport (6.1.4.1)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
@@ -79,9 +79,10 @@ GEM
79
79
  concurrent-ruby (~> 1.0)
80
80
  unicode-display_width (2.0.0)
81
81
  yard (0.9.26)
82
- zeitwerk (2.4.2)
82
+ zeitwerk (2.5.1)
83
83
 
84
84
  PLATFORMS
85
+ x86_64-darwin-21
85
86
  x86_64-linux
86
87
 
87
88
  DEPENDENCIES
@@ -98,4 +99,4 @@ DEPENDENCIES
98
99
  wise_gopher!
99
100
 
100
101
  BUNDLED WITH
101
- 2.2.20
102
+ 2.2.22
data/README.md CHANGED
@@ -9,7 +9,7 @@ This gem tries to solve some problems found when you need to execute custom and/
9
9
  3. The column types are not always correctly retrieved by ActiveRecord, or sometimes you need a little more ruby treatment on the value before using it.
10
10
 
11
11
  [This article](https://blog.saeloun.com/2019/10/28/bind-parameters-in-activerecord-sql-queries.html) describe the benefits of using bind parameters with ActiveRecord.
12
- [This one](https://use-the-index-luke.com/sql/where-clause/bind-parameters) goes further one the subject.
12
+ [This one](https://use-the-index-luke.com/sql/where-clause/bind-parameters) goes further on the subject.
13
13
 
14
14
  The basic idea of this gem is to provide you a way to declare what your query needs as input, what columns it returns and their type. In returns it will allow you to retrieve the rows from result as an array of plain Ruby objects. It will also dynamically creates a class for the row objects that you can customize or can provide it yourself.
15
15
 
@@ -59,9 +59,9 @@ class PopularArticle < WiseGopher::Base
59
59
 
60
60
  row do
61
61
  column :title, :string, transform: :capitalize
62
- column :average_rating, :float, -> { round(2) }
62
+ column :average_rating, :float, transform: -> { round(2) }
63
63
  column :published_at, :datetime
64
- column :author_username, as: :author
64
+ column :author_username, :string, as: :author
65
65
 
66
66
  def to_s
67
67
  "Article '#{title}' by #{author} is rated #{"%.2f" % average_rating}/5."
@@ -151,7 +151,7 @@ end
151
151
 
152
152
  ------
153
153
  ## Raw params
154
- If you need to dinamically interpolate raw SQL in your query, you can use `raw_param`. The value passed with `execute_with` will be interpolated in the base query before inserting the other params.
154
+ If you need to dynamically interpolate raw SQL in your query, you can use `raw_param`. The value passed with `execute_with` will be interpolated in the base query before inserting the other params.
155
155
  ```ruby
156
156
  class AnnualReport < WiseGopher::Base
157
157
  query <<-SQL
@@ -5,13 +5,19 @@ require "forwardable"
5
5
  module WiseGopher
6
6
  # Main inteface of the gem. Class to be inherited by the query class
7
7
  class Base
8
- def self.inherited(base)
9
- base.class_eval do
10
- @raw_params = {}
11
- @params = {}
8
+ def self.inherited(child_class)
9
+ parent_class = self
10
+ child_class.extend ClassMethods
11
+ child_class.set_defaults
12
+
13
+ # if child_class is already a WiseGopher::Base
14
+ child_class.ancestors.include?(Methods) && child_class.class_eval do
15
+ @raw_params = parent_class.raw_params.deep_dup
16
+ @params = parent_class.params.deep_dup
17
+ @row_class = parent_class.row_class
12
18
  end
13
- base.include Methods
14
- base.extend ClassMethods
19
+
20
+ child_class.include Methods
15
21
  end
16
22
 
17
23
  # class methods for WiseGopher::Base
@@ -41,7 +47,7 @@ module WiseGopher
41
47
  def row(base = nil, &block)
42
48
  @row_class ||= base || define_generic_row_class
43
49
 
44
- @row_class.include WiseGopher::Row
50
+ @row_class.include WiseGopher::Row unless @row_class.ancestors.include?(WiseGopher::Row)
45
51
 
46
52
  @row_class.class_eval(&block) if block_given?
47
53
  end
@@ -64,6 +70,11 @@ module WiseGopher
64
70
  raise WiseGopher::ArgumentError, required_params.slice(*missing_params) if missing_params.any?
65
71
  end
66
72
 
73
+ def set_defaults
74
+ @raw_params = {}
75
+ @params = {}
76
+ end
77
+
67
78
  private
68
79
 
69
80
  def define_generic_row_class
@@ -4,7 +4,7 @@ module WiseGopher
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 2
7
- PATCH = 0
7
+ PATCH = 1
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].join(".")
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wise_gopher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PageHey
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-04 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -210,7 +210,7 @@ metadata:
210
210
  homepage_uri: https://github.com/Pagehey/wise_gopher
211
211
  source_code_uri: https://github.com/Pagehey/wise_gopher
212
212
  changelog_uri: https://github.com/Pagehey/wise_gopher/blob/main/CHANGELOG.md
213
- post_install_message:
213
+ post_install_message:
214
214
  rdoc_options: []
215
215
  require_paths:
216
216
  - lib
@@ -225,8 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  - !ruby/object:Gem::Version
226
226
  version: '0'
227
227
  requirements: []
228
- rubygems_version: 3.1.6
229
- signing_key:
228
+ rubygems_version: 3.2.22
229
+ signing_key:
230
230
  specification_version: 4
231
231
  summary: Encapsulate raw SQL queries and return result as plain Ruby objects, using
232
232
  ActiveRecord.