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_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_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_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_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_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)
- #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 |
# 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, :lt], boolean: [:eq, :not_eq], uuid: [:eq, :not_eq], enum: [:eq], datetime: [: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: ::Graphiti::Sideload::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
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/solis/sparql_adaptor.rb', line 204 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
54 55 56 57 |
# File 'lib/solis/sparql_adaptor.rb', line 54 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
86 87 88 |
# File 'lib/solis/sparql_adaptor.rb', line 86 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
93 94 95 |
# File 'lib/solis/sparql_adaptor.rb', line 93 def filter_gt(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
121 122 123 |
# File 'lib/solis/sparql_adaptor.rb', line 121 def filter_lt(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
71 72 73 |
# File 'lib/solis/sparql_adaptor.rb', line 71 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
107 108 109 |
# File 'lib/solis/sparql_adaptor.rb', line 107 def filter_not_gt(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
135 136 137 |
# File 'lib/solis/sparql_adaptor.rb', line 135 def filter_not_lt(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
186 187 188 189 190 191 192 193 194 |
# File 'lib/solis/sparql_adaptor.rb', line 186 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
149 150 151 |
# File 'lib/solis/sparql_adaptor.rb', line 149 def transaction(*) yield end |