Module: PactBroker::Repositories::Helpers
- Extended by:
- Helpers
- Included in:
- Labels::Repository, Matrix::Repository, Pacticipants::Repository, Pacts::PactsForVerificationRepository, Pacts::Repository, Helpers, Tags::Repository, Verifications, Verifications::Repository, Versions::Repository
- Defined in:
- lib/pact_broker/repositories/helpers.rb
Instance Method Summary collapse
- #all_allowing_lazy_load ⇒ Object
- #all_forbidding_lazy_load ⇒ Object
- #max_group_by(max_column, group_by_columns, &extra_criteria_block) ⇒ Object
- #mysql? ⇒ Boolean
- #name_like(column_name, value) ⇒ Object
- #no_columns_selected? ⇒ Boolean
- #order_append_ignore_case(column_name = :name) ⇒ Object
- #order_ignore_case(column_name = :name) ⇒ Object
- #pacticipant_id_for_name(pacticipant_name) ⇒ Object
- #postgres? ⇒ Boolean
- #select_all_qualified ⇒ Object
- #select_append_all_qualified ⇒ Object
- #select_for_subquery(column) ⇒ Object
Instance Method Details
#all_allowing_lazy_load ⇒ Object
13 14 15 |
# File 'lib/pact_broker/repositories/helpers.rb', line 13 def all_allowing_lazy_load all.each{ | row | row.allow_lazy_load if row.respond_to?(:allow_lazy_load) } end |
#all_forbidding_lazy_load ⇒ Object
9 10 11 |
# File 'lib/pact_broker/repositories/helpers.rb', line 9 def all_forbidding_lazy_load all.each{ | row | row.forbid_lazy_load if row.respond_to?(:forbid_lazy_load) } end |
#max_group_by(max_column, group_by_columns, &extra_criteria_block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pact_broker/repositories/helpers.rb', line 60 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 |
#mysql? ⇒ Boolean
42 43 44 |
# File 'lib/pact_broker/repositories/helpers.rb', line 42 def mysql? Sequel::Model.db.adapter_scheme.to_s =~ /mysql/ end |
#name_like(column_name, value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pact_broker/repositories/helpers.rb', line 17 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 |
#no_columns_selected? ⇒ Boolean
80 81 82 |
# File 'lib/pact_broker/repositories/helpers.rb', line 80 def no_columns_selected? opts[:select].nil? end |
#order_append_ignore_case(column_name = :name) ⇒ Object
38 39 40 |
# File 'lib/pact_broker/repositories/helpers.rb', line 38 def order_append_ignore_case column_name = :name order_append(Sequel.function(:lower, column_name)) end |
#order_ignore_case(column_name = :name) ⇒ Object
34 35 36 |
# File 'lib/pact_broker/repositories/helpers.rb', line 34 def order_ignore_case column_name = :name order(Sequel.function(:lower, column_name)) end |
#pacticipant_id_for_name(pacticipant_name) ⇒ Object
30 31 32 |
# File 'lib/pact_broker/repositories/helpers.rb', line 30 def pacticipant_id_for_name pacticipant_name Sequel::Model.db[:pacticipants].select(:id).where(name_like(:name, pacticipant_name)).limit(1) end |
#postgres? ⇒ Boolean
46 47 48 |
# File 'lib/pact_broker/repositories/helpers.rb', line 46 def postgres? Sequel::Model.db.adapter_scheme.to_s =~ /postgres/ end |
#select_all_qualified ⇒ Object
50 51 52 |
# File 'lib/pact_broker/repositories/helpers.rb', line 50 def select_all_qualified select(Sequel[model.table_name].*) end |
#select_append_all_qualified ⇒ Object
54 55 56 |
# File 'lib/pact_broker/repositories/helpers.rb', line 54 def select_append_all_qualified select_append(Sequel[model.table_name].*) end |
#select_for_subquery(column) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/pact_broker/repositories/helpers.rb', line 71 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 |