Module: PactBroker::Dataset

Includes:
Helpers
Defined in:
lib/pact_broker/dataset.rb,
lib/pact_broker/dataset/page.rb

Defined Under Namespace

Modules: Helpers Classes: Page

Instance Method Summary collapse

Methods included from Helpers

#escape_wildcards, #postgres?

Instance Method Details

#all_allowing_lazy_loadObject



58
59
60
# File 'lib/pact_broker/dataset.rb', line 58

def all_allowing_lazy_load
  all.each{ | row | row.allow_lazy_load if row.respond_to?(:allow_lazy_load) }
end

#all_forbidding_lazy_loadObject



54
55
56
# File 'lib/pact_broker/dataset.rb', line 54

def all_forbidding_lazy_load
  all.each{ | row | row.forbid_lazy_load if row.respond_to?(:forbid_lazy_load) }
end

#all_with_pagination_options(pagination_options) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/pact_broker/dataset.rb', line 45

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

#filter(column_name, query_string) ⇒ Sequel::Dataset

Return a dataset that only includes the rows where the specified column includes the given query string.

Returns:



25
26
27
# File 'lib/pact_broker/dataset.rb', line 25

def filter(column_name, query_string)
  where(Sequel.ilike(column_name, "%" + escape_wildcards(query_string) + "%"))
end

#max_group_by(max_column, group_by_columns, &extra_criteria_block) ⇒ Object

Parameters:

  • the name of the column of which to calculate the maxiumum

  • the names of the columns by which to group



64
65
66
67
68
69
70
71
72
73
# File 'lib/pact_broker/dataset.rb', line 64

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

#name_like(column_name, value) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/pact_broker/dataset.rb', line 29

def name_like column_name, value
  if PactBroker.configuration.use_case_sensitive_resource_names
    { column_name => value }
  else
    Sequel.like(column_name, escape_wildcards(value), { case_insensitive: true })
  end
end

#no_columns_selected?Boolean

Returns:



79
80
81
# File 'lib/pact_broker/dataset.rb', line 79

def no_columns_selected?
  opts[:select].nil?
end

#order_append_ignore_case(column_name = :name) ⇒ Object



87
88
89
# File 'lib/pact_broker/dataset.rb', line 87

def order_append_ignore_case column_name = :name
  order_append(Sequel.function(:lower, column_name))
end

#order_ignore_case(column_name = :name) ⇒ Object



83
84
85
# File 'lib/pact_broker/dataset.rb', line 83

def order_ignore_case column_name = :name
  order(Sequel.function(:lower, column_name))
end

#select_all_qualifiedObject



41
42
43
# File 'lib/pact_broker/dataset.rb', line 41

def select_all_qualified
  select(Sequel[model.table_name].*)
end

#select_for_subquery(column) ⇒ Object



75
76
77
# File 'lib/pact_broker/dataset.rb', line 75

def select_for_subquery column
  select(column)
end

#where_name_like(column_name, value) ⇒ Object



37
38
39
# File 'lib/pact_broker/dataset.rb', line 37

def where_name_like(column_name, value)
  where(name_like(column_name, value))
end