Class: Hecks::QuerySpecification::Common::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/hecks/query_specification/common/options.rb

Direct Known Subclasses

Bluebook::Query, ReadModel::Specification

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wheres: [], order_by: nil, limit: nil, offset: nil, cursor: nil, authorization: nil, inspection: nil, null_semantics: NullSemantics.default) ⇒ Options

Returns a new instance of Options.



10
11
12
13
14
15
# File 'lib/hecks/query_specification/common/options.rb', line 10

def initialize(wheres: [], order_by: nil, limit: nil, offset: nil, cursor: nil,
               authorization: nil,
               inspection: nil, null_semantics: NullSemantics.default)
  @wheres, @order_by, @limit, @offset, @cursor = wheres, order_by, limit, offset, cursor
  @authorization, @null_semantics, @inspection = authorization, null_semantics, inspection
end

Instance Attribute Details

#authorizationObject (readonly)

Returns the value of attribute authorization.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def authorization
  @authorization
end

#cursorObject (readonly)

Returns the value of attribute cursor.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def cursor
  @cursor
end

#inspectionObject (readonly)

Returns the value of attribute inspection.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def inspection
  @inspection
end

#limitObject (readonly)

Returns the value of attribute limit.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def limit
  @limit
end

#null_semanticsObject (readonly)

Returns the value of attribute null_semantics.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def null_semantics
  @null_semantics
end

#offsetObject (readonly)

Returns the value of attribute offset.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def offset
  @offset
end

#order_byObject (readonly)

Returns the value of attribute order_by.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def order_by
  @order_by
end

#wheresObject (readonly)

Returns the value of attribute wheres.



7
8
9
# File 'lib/hecks/query_specification/common/options.rb', line 7

def wheres
  @wheres
end

Instance Method Details

#extra_options_to_hObject



23
24
25
26
27
28
# File 'lib/hecks/query_specification/common/options.rb', line 23

def extra_options_to_h
  options_to_h.reject { |key, value|
    value.nil? || value == [] || (key == :null_semantics && value == { mode: "native" })
  }
              .reject { |key, _| %i[wheres order_by limit].include?(key) }
end

#options_to_hObject



17
18
19
20
21
# File 'lib/hecks/query_specification/common/options.rb', line 17

def options_to_h
  { wheres: @wheres.map(&:to_h), order_by: @order_by&.to_h, limit: @limit&.to_h,
    offset: @offset&.to_h, cursor: @cursor&.to_h, authorization: @authorization&.to_h,
    null_semantics: @null_semantics&.to_h, inspection: @inspection&.to_h }
end