/
ClyQueryBrowserFilter.class.st
74 lines (56 loc) · 2.08 KB
/
ClyQueryBrowserFilter.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"
I am a query filter which specifically created for the query browser which can represent different kind of items in one list.
I delegate actual testing logic to the actual object of given browser items:
actualObject matchesQueryBrowserFilter: self
This method is implemented by methods, classes and class comments. So this objects can be shown and filtered in query browser.
Implementors call be back with #matchesString: messge where I check given string for my pattern.
I also provide special trick to filter items by script. To activate it the pattern string should be in form of one arg block. For example:
[ :each | each linesOfCode > 10 ]
Such block will be evaluated with actual object of browser item.
Internal Representation and Key Implementation Points.
Instance Variables
badScript: <Boolean>
scriptBlock: <BlockClosure>
"
Class {
#name : #ClyQueryBrowserFilter,
#superclass : #ClyItemStringFilter,
#instVars : [
'scriptBlock',
'badScript'
],
#category : #'Calypso-SystemQueries-Queries'
}
{ #category : #private }
ClyQueryBrowserFilter >> createBlockFromPattern [
(pattern value endsWith: ']') ifFalse: [
badScript := true.
^self].
[scriptBlock := self class compiler evaluate: pattern value]
on: Exception do: [:err | badScript := true ]
]
{ #category : #initialization }
ClyQueryBrowserFilter >> initialize [
super initialize.
badScript := false.
]
{ #category : #testing }
ClyQueryBrowserFilter >> matches: aBrowserItem [
| actualObject |
actualObject := aBrowserItem class = ClyBrowserItem
ifTrue: [ aBrowserItem actualObject] ifFalse: [ aBrowserItem ].
(pattern value beginsWith: '[') ifTrue: [
^self matchesByScript: actualObject].
^actualObject matchesQueryBrowserFilter: self
]
{ #category : #testing }
ClyQueryBrowserFilter >> matchesByScript: anObject [
badScript ifTrue: [ ^true ].
scriptBlock ifNil: [ self createBlockFromPattern].
badScript ifTrue: [ ^true ].
^[(scriptBlock value: anObject) ~~ false] ifErrorDo: [ false ]
]
{ #category : #testing }
ClyQueryBrowserFilter >> matchesString: aString [
^pattern matches: aString
]