-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename PactBroker::Repository::Helpers to PactBroker::Dataset
- Loading branch information
Showing
39 changed files
with
152 additions
and
195 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require "sequel" | ||
require "pact_broker/dataset/page" | ||
|
||
Sequel.extension :escaped_like | ||
|
||
module PactBroker | ||
module Dataset | ||
def name_like column_name, value | ||
if PactBroker.configuration.use_case_sensitive_resource_names | ||
if mysql? | ||
# sigh, mysql, this is the only way to perform a case sensitive search | ||
Sequel.like(column_name, value.gsub("_", "\\_"), { case_insensitive: false }) | ||
else | ||
{ column_name => value } | ||
end | ||
else | ||
Sequel.like(column_name, value.gsub("_", "\\_"), { case_insensitive: true }) | ||
end | ||
end | ||
|
||
def select_all_qualified | ||
select(Sequel[model.table_name].*) | ||
end | ||
|
||
def all_with_pagination_options(pagination_options) | ||
if pagination_options&.any? | ||
query = paginate(pagination_options[:page_number], pagination_options[:page_size]) | ||
Page.new(query.all, query) | ||
else | ||
all | ||
end | ||
end | ||
|
||
def all_forbidding_lazy_load | ||
all.each{ | row | row.forbid_lazy_load if row.respond_to?(:forbid_lazy_load) } | ||
end | ||
|
||
def all_allowing_lazy_load | ||
all.each{ | row | row.allow_lazy_load if row.respond_to?(:allow_lazy_load) } | ||
end | ||
|
||
# @param [Symbol] max_column the name of the column of which to calculate the maxiumum | ||
# @param [Array<Symbol>] group_by_columns the names of the columns by which to group | ||
def max_group_by(max_column, group_by_columns, &extra_criteria_block) | ||
maximums_base_query = extra_criteria_block ? extra_criteria_block.call(self) : self | ||
maximums = maximums_base_query.select_group(*group_by_columns).select_append(Sequel.function(:max, max_column).as(:max_value)) | ||
|
||
max_join = group_by_columns.each_with_object({ Sequel[:maximums][:max_value] => max_column }) do | column_name, joins | | ||
joins[Sequel[:maximums][column_name]] = column_name | ||
end | ||
|
||
join(maximums, max_join, table_alias: :maximums) | ||
end | ||
|
||
def select_for_subquery column | ||
if mysql? #stoopid mysql doesn't allow you to modify datasets with subqueries | ||
column_name = column.respond_to?(:alias) ? column.alias : column | ||
select(column).collect{ | it | it[column_name] } | ||
else | ||
select(column) | ||
end | ||
end | ||
|
||
def no_columns_selected? | ||
opts[:select].nil? | ||
end | ||
|
||
def order_ignore_case column_name = :name | ||
order(Sequel.function(:lower, column_name)) | ||
end | ||
|
||
def order_append_ignore_case column_name = :name | ||
order_append(Sequel.function(:lower, column_name)) | ||
end | ||
|
||
def mysql? | ||
Sequel::Model.db.adapter_scheme.to_s =~ /mysql/ | ||
end | ||
|
||
def postgres? | ||
Sequel::Model.db.adapter_scheme.to_s =~ /postgres/ | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "forwardable" | ||
|
||
# An array that provides the pagination details | ||
|
||
module PactBroker | ||
module Dataset | ||
class Page < Array | ||
extend Forwardable | ||
|
||
attr_reader :query | ||
|
||
PAGE_PROPERTIES = [:page_size, :page_count, :page_range, :current_page, :next_page, :prev_page, :first_page?, :last_page?, :pagination_record_count, :current_page_record_count, :current_page_record_range] | ||
|
||
delegate PAGE_PROPERTIES => :query | ||
|
||
def initialize(array, query) | ||
super(array) | ||
@query = query | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require "pact_broker/db" | ||
require "pact_broker/json" | ||
require "pact_broker/pacts/content" | ||
|
||
|
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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require "sequel" | ||
require "ostruct" | ||
require "pact_broker/logging" | ||
require "pact_broker/pacts/generate_sha" | ||
|
Oops, something went wrong.