Class: Solis::SparqlAdaptor
- Inherits:
-
Graphiti::Adapters::Abstract
- Object
- Graphiti::Adapters::Abstract
- Solis::SparqlAdaptor
- Defined in:
- lib/solis/sparql_adaptor.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#associate(parent, child, association_name, association_type) ⇒ Object
geeft fout als associate super gebruikt wordt 127.0.0.1:9292/autocirculaties?filter%5Bgebruiker_id%5D%5Beq%5D=1221&include=uitleenformaat,wat_uitlenen.
- #base_scope(*scope) ⇒ Object
- #count(scope, attr) ⇒ Object
- #filter(scope, attribute, value, is_not = false, operator = '=') ⇒ Object (also: #filter_eq, #filter_string_eq, #filter_integer_eq, #filter_float_eq, #filter_big_decimal_eq, #filter_date_eq, #filter_boolean_eq, #filter_uuid_eq, #filter_enum_eq, #filter_datetime_eq, #filter_lang_string_eq, #filter_anyuri_eq)
- #filter_contains(scope, attribute, value) ⇒ Object (also: #filter_string_contains, #filter_lang_string_contains)
- #filter_gt(scope, attribute, value) ⇒ Object (also: #filter_string_gt, #filter_integer_gt, #filter_float_gt, #filter_big_decimal_gt, #filter_date_gt, #filter_boolean_gt, #filter_uuid_gt, #filter_enum_gt, #filter_datetime_gt, #filter_anyuri_gt)
- #filter_gte(scope, attribute, value) ⇒ Object (also: #filter_date_gte)
- #filter_lt(scope, attribute, value) ⇒ Object (also: #filter_string_lt, #filter_integer_lt, #filter_float_lt, #filter_big_decimal_lt, #filter_date_lt, #filter_boolean_lt, #filter_uuid_lt, #filter_enum_lt, #filter_datetime_lt, #filter_anyuri_lt)
- #filter_lte(scope, attribute, value) ⇒ Object (also: #filter_date_lte)
- #filter_not_eq(scope, attribute, value) ⇒ Object (also: #filter_string_not_eq, #filter_integer_not_eq, #filter_float_not_eq, #filter_big_decimal_not_eq, #filter_date_not_eq, #filter_boolean_not_eq, #filter_uuid_not_eq, #filter_enum_not_eq, #filter_datetime_not_eq, #filter_lang_string_not_eq, #filter_anyuri_not_eq)
- #filter_not_gt(scope, attribute, value) ⇒ Object (also: #filter_string_not_gt, #filter_integer_not_gt, #filter_float_not_gt, #filter_big_decimal_not_gt, #filter_date_not_gt, #filter_boolean_not_gt, #filter_uuid_not_gt, #filter_enum_not_gt, #filter_datetime_not_gt)
- #filter_not_gte(scope, attribute, value) ⇒ Object (also: #filter_date_not_gte)
- #filter_not_lt(scope, attribute, value) ⇒ Object (also: #filter_string_not_lt, #filter_integer_not_lt, #filter_float_not_lt, #filter_big_decimal_not_lt, #filter_date_not_lt, #filter_boolean_not_lt, #filter_uuid_not_lt, #filter_enum_not_lt, #filter_datetime_not_lt)
- #filter_not_lte(scope, attribute, value) ⇒ Object (also: #filter_date_not_lte)
- #order(scope, att, dir) ⇒ Object
- #paginate(scope, current, per) ⇒ Object
-
#resolve(scope) ⇒ Object
def associate(parent, child, association_name, association_type) pp parent, children, association_name, association_type super end.
- #transaction ⇒ Object
Class Method Details
.default_operators ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/solis/sparql_adaptor.rb', line 38 def self.default_operators { string: [:eq, :not_eq, :contains], lang_string: [:eq, :not_eq, :contains], integer: [:eq, :not_eq, :gt, :lt], float: [:eq, :not_eq, :gt, :lt], big_decimal: [:eq, :not_eq, :gt, :lt], date: [:eq, :not_eq, :gt, :gte, :lt, :lte], boolean: [:eq, :not_eq], uuid: [:eq, :not_eq, :gt, :lt], enum: [:eq], datetime: [:eq, :not_eq, :gt, :lt], anyuri: [:eq, :not_eq, :gt, :lt], } end |
.sideloading_classes ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/solis/sparql_adaptor.rb', line 4 def self.sideloading_classes { has_many: HasMany, belongs_to: BelongsTo, has_one: HasOne, many_to_many: ::Graphiti::Sideload::ManyToMany, polymorphic_belongs_to: ::Graphiti::Sideload::PolymorphicBelongsTo } end |
Instance Method Details
#associate(parent, child, association_name, association_type) ⇒ Object
geeft fout als associate super gebruikt wordt 127.0.0.1:9292/autocirculaties?filter%5Bgebruiker_id%5D%5Beq%5D=1221&include=uitleenformaat,wat_uitlenen
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/solis/sparql_adaptor.rb', line 233 def associate(parent, child, association_name, association_type) if activerecord_associate?(parent, child, association_name) activerecord_adapter.associate \ parent, child, association_name, association_type elsif [:has_many, :many_to_many].include?(association_type) if parent.send(:"#{association_name}").nil? parent.send(:"#{association_name}=", [child]) else parent_child_data = parent.send(:"#{association_name}") if parent_child_data.is_a?(Array) parent_child_data = parent_child_data.map do |m| m.id.eql?(child.id) ? child : m end else if parent_child_data.id.eql?(child.id) parent_child_data = [child] # else # parent_child_data = nil end end parent.send(:"#{association_name}=", parent_child_data) #parent.send(:"#{association_name}") << child end else parent_child_data = parent.send(:"#{association_name}") if parent_child_data.is_a?(Array) parent_child_data = parent_child_data.map do |m| m.id.eql?(child.id) ? child : m end else if parent_child_data&.id.eql?(child.id) parent_child_data = [child] else parent_child_data = nil end end parent.send(:"#{association_name}=", parent_child_data) end end |
#base_scope(*scope) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/solis/sparql_adaptor.rb', line 14 def base_scope(*scope) types = ObjectSpace.each_object(Class).select { |klass| klass < self.resource.model}.map{|m| m.name.tableize.pluralize.to_sym} types << self.resource.model.name.tableize.pluralize.to_sym if types.empty? { type: types, sort: {}, filters: {} } rescue Exception => e types = [self.resource.model.name.tableize.pluralize.to_sym] { type: types, sort: {}, filters: {} } end |
#count(scope, attr) ⇒ Object
28 29 30 31 |
# File 'lib/solis/sparql_adaptor.rb', line 28 def count(scope, attr) count = self.resource.model.new().query.paging(scope).filter(scope).sort(scope).count scope[attr] = count end |
#filter(scope, attribute, value, is_not = false, operator = '=') ⇒ Object Also known as: filter_eq, filter_string_eq, filter_integer_eq, filter_float_eq, filter_big_decimal_eq, filter_date_eq, filter_boolean_eq, filter_uuid_eq, filter_enum_eq, filter_datetime_eq, filter_lang_string_eq, filter_anyuri_eq
55 56 57 58 |
# File 'lib/solis/sparql_adaptor.rb', line 55 def filter(scope, attribute, value, is_not = false, operator = '=') scope[:filters][attribute] = {value: value, operator: operator, is_not: is_not} scope end |
#filter_contains(scope, attribute, value) ⇒ Object Also known as: filter_string_contains, filter_lang_string_contains
89 90 91 |
# File 'lib/solis/sparql_adaptor.rb', line 89 def filter_contains(scope, attribute, value) filter_eq(scope, attribute, value, false, '~') end |
#filter_gt(scope, attribute, value) ⇒ Object Also known as: filter_string_gt, filter_integer_gt, filter_float_gt, filter_big_decimal_gt, filter_date_gt, filter_boolean_gt, filter_uuid_gt, filter_enum_gt, filter_datetime_gt, filter_anyuri_gt
96 97 98 |
# File 'lib/solis/sparql_adaptor.rb', line 96 def filter_gt(scope, attribute, value) filter_eq(scope, attribute, value, false, '>') end |
#filter_gte(scope, attribute, value) ⇒ Object Also known as: filter_date_gte
154 155 156 |
# File 'lib/solis/sparql_adaptor.rb', line 154 def filter_gte(scope, attribute, value) filter_eq(scope, attribute, value, false, '>=') end |
#filter_lt(scope, attribute, value) ⇒ Object Also known as: filter_string_lt, filter_integer_lt, filter_float_lt, filter_big_decimal_lt, filter_date_lt, filter_boolean_lt, filter_uuid_lt, filter_enum_lt, filter_datetime_lt, filter_anyuri_lt
125 126 127 |
# File 'lib/solis/sparql_adaptor.rb', line 125 def filter_lt(scope, attribute, value) filter_eq(scope, attribute, value, false, '<') end |
#filter_lte(scope, attribute, value) ⇒ Object Also known as: filter_date_lte
166 167 168 |
# File 'lib/solis/sparql_adaptor.rb', line 166 def filter_lte(scope, attribute, value) filter_eq(scope, attribute, value, false, '<=') end |
#filter_not_eq(scope, attribute, value) ⇒ Object Also known as: filter_string_not_eq, filter_integer_not_eq, filter_float_not_eq, filter_big_decimal_not_eq, filter_date_not_eq, filter_boolean_not_eq, filter_uuid_not_eq, filter_enum_not_eq, filter_datetime_not_eq, filter_lang_string_not_eq, filter_anyuri_not_eq
73 74 75 |
# File 'lib/solis/sparql_adaptor.rb', line 73 def filter_not_eq(scope, attribute, value) filter_eq(scope, attribute, value, true, '=') end |
#filter_not_gt(scope, attribute, value) ⇒ Object Also known as: filter_string_not_gt, filter_integer_not_gt, filter_float_not_gt, filter_big_decimal_not_gt, filter_date_not_gt, filter_boolean_not_gt, filter_uuid_not_gt, filter_enum_not_gt, filter_datetime_not_gt
111 112 113 |
# File 'lib/solis/sparql_adaptor.rb', line 111 def filter_not_gt(scope, attribute, value) filter_eq(scope, attribute, value, true, '>') end |
#filter_not_gte(scope, attribute, value) ⇒ Object Also known as: filter_date_not_gte
160 161 162 |
# File 'lib/solis/sparql_adaptor.rb', line 160 def filter_not_gte(scope, attribute, value) filter_eq(scope, attribute, value, true, '>=') end |
#filter_not_lt(scope, attribute, value) ⇒ Object Also known as: filter_string_not_lt, filter_integer_not_lt, filter_float_not_lt, filter_big_decimal_not_lt, filter_date_not_lt, filter_boolean_not_lt, filter_uuid_not_lt, filter_enum_not_lt, filter_datetime_not_lt
140 141 142 |
# File 'lib/solis/sparql_adaptor.rb', line 140 def filter_not_lt(scope, attribute, value) filter_eq(scope, attribute, value, true, '<') end |
#filter_not_lte(scope, attribute, value) ⇒ Object Also known as: filter_date_not_lte
172 173 174 |
# File 'lib/solis/sparql_adaptor.rb', line 172 def filter_not_lte(scope, attribute, value) filter_eq(scope, attribute, value, true, '<=') end |
#order(scope, att, dir) ⇒ Object
33 34 35 36 |
# File 'lib/solis/sparql_adaptor.rb', line 33 def order(scope, att, dir) scope[:sort].merge!({ att => dir }) scope end |
#paginate(scope, current, per) ⇒ Object
24 25 26 |
# File 'lib/solis/sparql_adaptor.rb', line 24 def paginate(scope, current, per) scope.merge!(current_page: current, per_page: per) end |
#resolve(scope) ⇒ Object
def associate(parent, child, association_name, association_type)
pp parent, children, association_name, association_type
super
end
def associate_all(parent, children, association_name, association_type)
pp parent, children, association_name, association_type
super
end
def disassociate(parent, child, association_name, association_type)
pp parent, children, association_name, association_type
super
end
215 216 217 218 219 220 221 222 223 |
# File 'lib/solis/sparql_adaptor.rb', line 215 def resolve(scope) self.resource.model.before_read_proc&.call(scope) query = self.resource.model.new().query.paging(scope).filter(scope).sort(scope) data = query.find_all.map { |m| m } self.resource.model.after_read_proc&.call(data) data end |
#transaction ⇒ Object
178 179 180 |
# File 'lib/solis/sparql_adaptor.rb', line 178 def transaction(*) yield end |