Class: Graphiti::Adapters::Null

Inherits:
Abstract show all
Defined in:
lib/graphiti/adapters/null.rb

Overview

The Null adapter is a ‘pass-through’ adapter. It won’t modify the scope. Useful when your customization does not support all possible configuration (e.g. the service you hit does not support sorting)

Direct Known Subclasses

GraphitiAPI

Instance Attribute Summary

Attributes inherited from Abstract

#resource

Instance Method Summary collapse

Methods inherited from Abstract

#assign_attributes, #associate, #associate_all, #belongs_to_many_filter, #build, #close, default_operators, #destroy, #disassociate, #filter_big_decimal_eq, #filter_big_decimal_gt, #filter_big_decimal_gte, #filter_big_decimal_lt, #filter_big_decimal_lte, #filter_big_decimal_not_eq, #filter_string_match, #filter_string_not_match, #filter_string_not_prefix, #filter_string_not_suffix, #filter_string_prefix, #filter_string_suffix, #filter_uuid_eq, #filter_uuid_not_eq, #initialize, numerical_operators, #persistence_attributes, sideloading_classes

Methods included from Persistence::Associations

#process_belongs_to, #process_has_many, #update_foreign_key, #update_foreign_key_for_parents, #update_foreign_type

Constructor Details

This class inherits a constructor from Graphiti::Adapters::Abstract

Instance Method Details

#average(scope, attr) ⇒ Float

Returns the average of the scope.

Examples:

ActiveRecord default

def average(scope, attr)
  scope.average(attr).to_f
end

Parameters:

  • scope

    the scope object we are chaining

  • attr (Symbol)

    corresponding stat attribute name

Returns:

  • (Float)

    the average of the scope



191
192
193
# File 'lib/graphiti/adapters/null.rb', line 191

def average(scope, attr)
  scope
end

#base_scope(model) ⇒ Object



171
172
173
# File 'lib/graphiti/adapters/null.rb', line 171

def base_scope(model)
  {}
end

#count(scope, attr) ⇒ Numeric

Returns the count of the scope.

Examples:

ActiveRecord default

def count(scope, attr)
  column = attr == :total ? :all : attr
  scope.uniq.count(column)
end

Parameters:

  • scope

    the scope object we are chaining

  • attr (Symbol)

    corresponding stat attribute name

Returns:

  • (Numeric)

    the count of the scope



186
187
188
# File 'lib/graphiti/adapters/null.rb', line 186

def count(scope, attr)
  scope
end

#filter_boolean_eq(scope, attribute, value) ⇒ Object



167
168
169
# File 'lib/graphiti/adapters/null.rb', line 167

def filter_boolean_eq(scope, attribute, value)
  scope
end

#filter_date_eq(scope, attribute, value) ⇒ Object



143
144
145
# File 'lib/graphiti/adapters/null.rb', line 143

def filter_date_eq(scope, attribute, value)
  scope
end

#filter_date_gt(scope, attribute, value) ⇒ Object



151
152
153
# File 'lib/graphiti/adapters/null.rb', line 151

def filter_date_gt(scope, attribute, value)
  scope
end

#filter_date_gte(scope, attribute, value) ⇒ Object



155
156
157
# File 'lib/graphiti/adapters/null.rb', line 155

def filter_date_gte(scope, attribute, value)
  scope
end

#filter_date_lt(scope, attribute, value) ⇒ Object



159
160
161
# File 'lib/graphiti/adapters/null.rb', line 159

def filter_date_lt(scope, attribute, value)
  scope
end

#filter_date_lte(scope, attribute, value) ⇒ Object



163
164
165
# File 'lib/graphiti/adapters/null.rb', line 163

def filter_date_lte(scope, attribute, value)
  scope
end

#filter_date_not_eq(scope, attribute, value) ⇒ Object



147
148
149
# File 'lib/graphiti/adapters/null.rb', line 147

def filter_date_not_eq(scope, attribute, value)
  scope
end

#filter_datetime_eq(scope, attribute, value) ⇒ Object



119
120
121
# File 'lib/graphiti/adapters/null.rb', line 119

def filter_datetime_eq(scope, attribute, value)
  scope
end

#filter_datetime_gt(scope, attribute, value) ⇒ Object



127
128
129
# File 'lib/graphiti/adapters/null.rb', line 127

def filter_datetime_gt(scope, attribute, value)
  scope
end

#filter_datetime_gte(scope, attribute, value) ⇒ Object



131
132
133
# File 'lib/graphiti/adapters/null.rb', line 131

def filter_datetime_gte(scope, attribute, value)
  scope
end

#filter_datetime_lt(scope, attribute, value) ⇒ Object



135
136
137
# File 'lib/graphiti/adapters/null.rb', line 135

def filter_datetime_lt(scope, attribute, value)
  scope
end

#filter_datetime_lte(scope, attribute, value) ⇒ Object



139
140
141
# File 'lib/graphiti/adapters/null.rb', line 139

def filter_datetime_lte(scope, attribute, value)
  scope
end

#filter_datetime_not_eq(scope, attribute, value) ⇒ Object



123
124
125
# File 'lib/graphiti/adapters/null.rb', line 123

def filter_datetime_not_eq(scope, attribute, value)
  scope
end

#filter_decimal_eq(scope, attribute, value) ⇒ Object



95
96
97
# File 'lib/graphiti/adapters/null.rb', line 95

def filter_decimal_eq(scope, attribute, value)
  scope
end

#filter_decimal_gt(scope, attribute, value) ⇒ Object



103
104
105
# File 'lib/graphiti/adapters/null.rb', line 103

def filter_decimal_gt(scope, attribute, value)
  scope
end

#filter_decimal_gte(scope, attribute, value) ⇒ Object



107
108
109
# File 'lib/graphiti/adapters/null.rb', line 107

def filter_decimal_gte(scope, attribute, value)
  scope
end

#filter_decimal_lt(scope, attribute, value) ⇒ Object



111
112
113
# File 'lib/graphiti/adapters/null.rb', line 111

def filter_decimal_lt(scope, attribute, value)
  scope
end

#filter_decimal_lte(scope, attribute, value) ⇒ Object



115
116
117
# File 'lib/graphiti/adapters/null.rb', line 115

def filter_decimal_lte(scope, attribute, value)
  scope
end

#filter_decimal_not_eq(scope, attribute, value) ⇒ Object



99
100
101
# File 'lib/graphiti/adapters/null.rb', line 99

def filter_decimal_not_eq(scope, attribute, value)
  scope
end

#filter_float_eq(scope, attribute, value) ⇒ Object



71
72
73
# File 'lib/graphiti/adapters/null.rb', line 71

def filter_float_eq(scope, attribute, value)
  scope
end

#filter_float_gt(scope, attribute, value) ⇒ Object



79
80
81
# File 'lib/graphiti/adapters/null.rb', line 79

def filter_float_gt(scope, attribute, value)
  scope
end

#filter_float_gte(scope, attribute, value) ⇒ Object



83
84
85
# File 'lib/graphiti/adapters/null.rb', line 83

def filter_float_gte(scope, attribute, value)
  scope
end

#filter_float_lt(scope, attribute, value) ⇒ Object



87
88
89
# File 'lib/graphiti/adapters/null.rb', line 87

def filter_float_lt(scope, attribute, value)
  scope
end

#filter_float_lte(scope, attribute, value) ⇒ Object



91
92
93
# File 'lib/graphiti/adapters/null.rb', line 91

def filter_float_lte(scope, attribute, value)
  scope
end

#filter_float_not_eq(scope, attribute, value) ⇒ Object



75
76
77
# File 'lib/graphiti/adapters/null.rb', line 75

def filter_float_not_eq(scope, attribute, value)
  scope
end

#filter_integer_eq(scope, attribute, value) ⇒ Object



47
48
49
# File 'lib/graphiti/adapters/null.rb', line 47

def filter_integer_eq(scope, attribute, value)
  scope
end

#filter_integer_gt(scope, attribute, value) ⇒ Object



55
56
57
# File 'lib/graphiti/adapters/null.rb', line 55

def filter_integer_gt(scope, attribute, value)
  scope
end

#filter_integer_gte(scope, attribute, value) ⇒ Object



59
60
61
# File 'lib/graphiti/adapters/null.rb', line 59

def filter_integer_gte(scope, attribute, value)
  scope
end

#filter_integer_lt(scope, attribute, value) ⇒ Object



63
64
65
# File 'lib/graphiti/adapters/null.rb', line 63

def filter_integer_lt(scope, attribute, value)
  scope
end

#filter_integer_lte(scope, attribute, value) ⇒ Object



67
68
69
# File 'lib/graphiti/adapters/null.rb', line 67

def filter_integer_lte(scope, attribute, value)
  scope
end

#filter_integer_not_eq(scope, attribute, value) ⇒ Object



51
52
53
# File 'lib/graphiti/adapters/null.rb', line 51

def filter_integer_not_eq(scope, attribute, value)
  scope
end

#filter_string_eq(scope, attribute, value) ⇒ Object



7
8
9
# File 'lib/graphiti/adapters/null.rb', line 7

def filter_string_eq(scope, attribute, value)
  scope
end

#filter_string_eql(scope, attribute, value) ⇒ Object



11
12
13
# File 'lib/graphiti/adapters/null.rb', line 11

def filter_string_eql(scope, attribute, value)
  scope
end

#filter_string_match_eq(scope, attribute, value) ⇒ Object



39
40
41
# File 'lib/graphiti/adapters/null.rb', line 39

def filter_string_match_eq(scope, attribute, value)
  scope
end

#filter_string_not_eq(scope, attribute, value) ⇒ Object



15
16
17
# File 'lib/graphiti/adapters/null.rb', line 15

def filter_string_not_eq(scope, attribute, value)
  scope
end

#filter_string_not_eql(scope, attribute, value) ⇒ Object



19
20
21
# File 'lib/graphiti/adapters/null.rb', line 19

def filter_string_not_eql(scope, attribute, value)
  scope
end

#filter_string_not_match_eq(scope, attribute, value) ⇒ Object



43
44
45
# File 'lib/graphiti/adapters/null.rb', line 43

def filter_string_not_match_eq(scope, attribute, value)
  scope
end

#filter_string_not_prefix_eq(scope, attribute, value) ⇒ Object



27
28
29
# File 'lib/graphiti/adapters/null.rb', line 27

def filter_string_not_prefix_eq(scope, attribute, value)
  scope
end

#filter_string_not_suffix_eq(scope, attribute, value) ⇒ Object



35
36
37
# File 'lib/graphiti/adapters/null.rb', line 35

def filter_string_not_suffix_eq(scope, attribute, value)
  scope
end

#filter_string_prefix_eq(scope, attribute, value) ⇒ Object



23
24
25
# File 'lib/graphiti/adapters/null.rb', line 23

def filter_string_prefix_eq(scope, attribute, value)
  scope
end

#filter_string_suffix_eq(scope, attribute, value) ⇒ Object



31
32
33
# File 'lib/graphiti/adapters/null.rb', line 31

def filter_string_suffix_eq(scope, attribute, value)
  scope
end

#maximum(scope, attr) ⇒ Numeric

Returns the sum of the scope.

Examples:

ActiveRecord default

def sum(scope, attr)
  scope.sum(attr)
end

Parameters:

  • scope

    the scope object we are chaining

  • attr (Symbol)

    corresponding stat attribute name

Returns:

  • (Numeric)

    the sum of the scope



201
202
203
# File 'lib/graphiti/adapters/null.rb', line 201

def maximum(scope, attr)
  scope
end

#minimum(scope, attr) ⇒ Numeric

Returns the maximum value of the scope.

Examples:

ActiveRecord default

def maximum(scope, attr)
  scope.maximum(attr)
end

Parameters:

  • scope

    the scope object we are chaining

  • attr (Symbol)

    corresponding stat attribute name

Returns:

  • (Numeric)

    the maximum value of the scope



206
207
208
# File 'lib/graphiti/adapters/null.rb', line 206

def minimum(scope, attr)
  scope
end

#order(scope, attribute, direction) ⇒ Object

Returns the scope.

Examples:

ActiveRecord default

def order(scope, attribute, direction)
  scope.order(attribute => direction)
end

Parameters:

  • scope

    The scope object we are chaining

  • attribute (Symbol)

    The attribute name we are sorting

  • direction (Symbol)

    The direction we are sorting (asc/desc)

Returns:

  • the scope



176
177
178
# File 'lib/graphiti/adapters/null.rb', line 176

def order(scope, attribute, direction)
  scope
end

#paginate(scope, current_page, per_page, offset) ⇒ Object

Returns the scope.

Examples:

ActiveRecord default

# via kaminari gem
def paginate(scope, current_page, per_page, offset)
  scope.page(current_page).per(per_page)
end

Parameters:

  • scope

    The scope object we are chaining

  • current_page (Integer)

    The current page number

  • per_page (Integer)

    The number of results per page

  • offset (Integer)

    The offset to start from

Returns:

  • the scope



181
182
183
# File 'lib/graphiti/adapters/null.rb', line 181

def paginate(scope, current_page, per_page, offset)
  scope
end

#resolve(scope) ⇒ Object

Resolve the scope. This is where you’d actually fire SQL, actually make an HTTP call, etc.

Examples:

ActiveRecordDefault

def resolve(scope)
  scope.to_a
end

Suggested Customization

# When making a service call, we suggest this abstraction
# 'scope' here is a hash
def resolve(scope)
  # The implementation of .where can be whatever you want
  SomeModelClass.where(scope)
end

Parameters:

  • scope

    The scope object to resolve

Returns:

  • an array of Model instances

See Also:



219
220
221
# File 'lib/graphiti/adapters/null.rb', line 219

def resolve(scope)
  scope
end

#save(model) ⇒ Object



223
224
225
226
# File 'lib/graphiti/adapters/null.rb', line 223

def save(model)
  model.valid? if model.respond_to?(:valid?)
  model
end

#sum(scope, attr) ⇒ Numeric

Returns the sum of the scope.

Examples:

ActiveRecord default

def sum(scope, attr)
  scope.sum(attr)
end

Parameters:

  • scope

    the scope object we are chaining

  • attr (Symbol)

    corresponding stat attribute name

Returns:

  • (Numeric)

    the sum of the scope



196
197
198
# File 'lib/graphiti/adapters/null.rb', line 196

def sum(scope, attr)
  scope
end

#transaction(model_class) ⇒ Object

Since this is a null adapter, just yield

Parameters:

  • model_class (Class)

    The class we’re operating on

Returns:

  • Result of yield

See Also:



214
215
216
# File 'lib/graphiti/adapters/null.rb', line 214

def transaction(model_class)
  yield
end