-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate quo to be a Rails Engine, change config to use more standard …
…engine like configuration and setup autoloading. Also make derived Quo Query classes use a configurable base class
- Loading branch information
Showing
15 changed files
with
121 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ Gemfile.lock | |
/.idea/ | ||
/.gem_rbs_collection/ | ||
rbs_collection.lock.yaml | ||
*.gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "~> 7.0" | ||
|
||
group :development, :test do | ||
gem "sqlite3" | ||
gem "rake", "~> 13.0" | ||
gem "minitest", "~> 5.0" | ||
gem "standard" | ||
gem "steep" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "~> 7.1" | ||
|
||
group :development, :test do | ||
gem "sqlite3" | ||
gem "rake", "~> 13.0" | ||
gem "minitest", "~> 5.0" | ||
gem "standard" | ||
gem "steep" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "~> 7.2" | ||
|
||
group :development, :test do | ||
gem "sqlite3" | ||
gem "rake", "~> 13.0" | ||
gem "minitest", "~> 5.0" | ||
gem "standard" | ||
gem "steep" | ||
end | ||
|
||
gemspec path: "../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "quo/version" | ||
require_relative "quo/railtie" if defined?(Rails) | ||
require_relative "quo/query" | ||
require_relative "quo/eager_query" | ||
require_relative "quo/loaded_query" | ||
require_relative "quo/wrapped_query" | ||
require_relative "quo/composed_query" | ||
require_relative "quo/results" | ||
require "quo/engine" | ||
|
||
module Quo | ||
class << self | ||
def configuration | ||
@configuration ||= Configuration.new | ||
end | ||
extend ActiveSupport::Autoload | ||
|
||
def configure | ||
yield(configuration) if block_given? | ||
configuration | ||
end | ||
end | ||
autoload :Callstack, "quo/utilities/callstack" | ||
autoload :Compose, "quo/utilities/compose" | ||
autoload :Sanitize, "quo/utilities/sanitize" | ||
autoload :Wrap, "quo/utilities/wrap" | ||
|
||
autoload :Query | ||
autoload :Results | ||
autoload :ComposedQuery | ||
autoload :EagerQuery | ||
autoload :LoadedQuery | ||
autoload :WrappedQuery | ||
|
||
class Configuration | ||
attr_accessor :formatted_query_log, | ||
:query_show_callstack_size, | ||
:logger, | ||
:max_page_size, | ||
:default_page_size | ||
mattr_accessor :base_query_class, default: "Quo::Query" | ||
mattr_accessor :formatted_query_log, default: true | ||
mattr_accessor :query_show_callstack_size, default: 10 | ||
mattr_accessor :logger, default: nil | ||
mattr_accessor :max_page_size, default: 200 | ||
mattr_accessor :default_page_size, default: 20 | ||
|
||
def initialize | ||
@formatted_query_log = true | ||
@query_show_callstack_size = 10 | ||
@logger = nil | ||
@max_page_size = 200 | ||
@default_page_size = 20 | ||
end | ||
def self.base_query_class | ||
@@base_query_class.constantize | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationQuery < Quo::Query | ||
def hello | ||
"world" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Quo.configure do |config| | ||
config.formatted_query_log = true | ||
config.query_show_callstack_size = 5 | ||
config.logger = -> { Rails.logger } | ||
end | ||
Quo.formatted_query_log = true | ||
Quo.query_show_callstack_size = 5 | ||
Quo.logger = -> { Rails.logger } | ||
Quo.base_query_class = "ApplicationQuery" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../test_helper" | ||
|
||
class Quo::CustomBaseClassTest < ActiveSupport::TestCase | ||
def setup | ||
a1 = Author.create!(name: "John") | ||
a2 = Author.create!(name: "Jane") | ||
p1 = Post.create!(title: "Post 1", author: a1) | ||
p2 = Post.create!(title: "Post 2", author: a2) | ||
Comment.create!(post: p1, body: "abc", read: false) | ||
Comment.create!(post: p2, body: "def", read: false, spam_score: 0.8) | ||
|
||
@q1 = Quo::WrappedQuery.wrap(props: {since_date: Time}) do | ||
Comment.recent(since_date) | ||
end | ||
@q2 = Quo::WrappedQuery.wrap(props: {spam_score: Float}) do | ||
Comment.not_spam(spam_score) | ||
end | ||
end | ||
|
||
test "wrapped query inherits from custom base class" do | ||
assert_kind_of ApplicationQuery, @q1.new(since_date: 1.day.ago) | ||
assert_equal "world", @q1.new(since_date: 1.day.ago).hello | ||
|
||
klass = Quo::ComposedQuery.compose(Comment.recent, Comment.not_spam) | ||
assert_kind_of ApplicationQuery, klass.new | ||
end | ||
end |