cql 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/cql.rb +71 -63
- data/lib/dsl.rb +110 -110
- data/lib/feature_filters.rb +88 -72
- data/lib/map_reduce.rb +104 -40
- data/lib/sso_filters.rb +81 -72
- data/spec/filter_feature_dsl_spec.rb +284 -486
- data/spec/filter_sso_spec.rb +161 -288
- data/spec/line_count_filterable_specs.rb +73 -0
- data/spec/line_filterable_specs.rb +40 -0
- data/spec/map_reduce_spec.rb +132 -132
- data/spec/multiple_queries_spec.rb +27 -0
- data/spec/name_filterable_specs.rb +40 -0
- data/spec/select_feature_dsl_spec.rb +191 -50
- data/spec/select_scen_outline_dsl_spec.rb +323 -126
- data/spec/select_scenario_dsl_spec.rb +197 -73
- data/spec/spec_helper.rb +27 -0
- data/spec/tag_filterable_specs.rb +106 -0
- metadata +54 -37
- data/spec/unit_spec.rb +0 -22
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODIxODczMTZmOTQwODJjMGFjODIwZjE5Zjk2OWJhYzY2YTQ0MzMzNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWMyODEwMzRmOGZkMDlkZGFhNzcyOTQ2OTNlZTViZmQ4OTVhOTk0Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Yzg2YzE0YjNjZmY1NGMxNDMzY2QxNDFiZTMxOTU5NDE5NDNhMmZlMTJkY2Vi
|
10
|
+
YzRiNjQwMzk2OGYyNjYzNTg1NzM3YmM3M2M1OTBhNzM2ZWY1NDZjN2I2N2Mx
|
11
|
+
MjYzMmYyNTA2NzJiNzExOTk2MmFlMzI4NmQ3ZWFkNzliYTQwNzI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDg5MGNjNmYxZGRkODE0ODNmNmU1M2MyNjlkY2RhOGE0NDNjZDhiZjExYzhh
|
14
|
+
YTAzNzE3YTc4NDU4ZDg1MGNkM2M0MGMxYmFhMGIyN2I5YjcxYWViOGQ1YmM5
|
15
|
+
Nzk0ZTZlN2UyNmIzZGUzNTM4NWI5MDQxMDk0M2Y4MjI3ZjcwZjM=
|
data/lib/cql.rb
CHANGED
@@ -1,63 +1,71 @@
|
|
1
|
-
require '
|
2
|
-
require
|
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
|
-
@data=
|
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
|
-
|
1
|
+
require 'cuke_modeler'
|
2
|
+
require File.dirname(__FILE__) + "/dsl"
|
3
|
+
|
4
|
+
module CQL
|
5
|
+
|
6
|
+
class Query
|
7
|
+
include Dsl
|
8
|
+
attr_reader :data, :what
|
9
|
+
|
10
|
+
def format_to_ary_of_hsh data
|
11
|
+
result = Array.new(data.size).map { |e| {} }
|
12
|
+
|
13
|
+
@what.each do |w|
|
14
|
+
CQL::MapReduce.send(w, data).each_with_index do |e, i|
|
15
|
+
if e.class.to_s =~ /CukeModeler/
|
16
|
+
result[i][w]=e.raw_element
|
17
|
+
else
|
18
|
+
result[i][w]=e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize features, &block
|
27
|
+
@data = features
|
28
|
+
@data = self.instance_eval(&block)
|
29
|
+
|
30
|
+
#getting the children of features
|
31
|
+
@data= CQL::MapReduce.feature_children(@data, 'what'=>@from[0, @from.size-1]) if @from != "features"
|
32
|
+
|
33
|
+
@data= format_to_ary_of_hsh(@data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
class Repository
|
39
|
+
attr_reader :parsed_feature_files
|
40
|
+
|
41
|
+
def initialize features_home_dir
|
42
|
+
@parsed_feature_files = collect_feature_models(CukeModeler::Directory.new(features_home_dir))
|
43
|
+
end
|
44
|
+
|
45
|
+
def query &block
|
46
|
+
new_repo = Marshal::load(Marshal.dump(parsed_feature_files))
|
47
|
+
|
48
|
+
Query.new(new_repo, &block).data
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
|
55
|
+
def collect_feature_models(directory_model)
|
56
|
+
Array.new.tap { |accumulated_features| collect_all_in(:features, directory_model, accumulated_features) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Recursively gathers all things of the given type found in the passed container.
|
60
|
+
def collect_all_in(type_of_thing, container, accumulated_things)
|
61
|
+
accumulated_things.concat container.send(type_of_thing) if container.respond_to?(type_of_thing)
|
62
|
+
|
63
|
+
if container.respond_to?(:contains)
|
64
|
+
container.contains.each do |child_container|
|
65
|
+
collect_all_in(type_of_thing, child_container, accumulated_things)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/dsl.rb
CHANGED
@@ -1,111 +1,111 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/map_reduce"
|
2
|
-
module CQL
|
3
|
-
module Dsl
|
4
|
-
#Select clause
|
5
|
-
def select *what
|
6
|
-
@what = what
|
7
|
-
end
|
8
|
-
|
9
|
-
(CQL::QUERY_VALUES + %w(all step_lines examples)).each do |method_name|
|
10
|
-
define_method(method_name) { |*args|
|
11
|
-
return method_name if args.size == 0
|
12
|
-
{method_name=>args}
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
alias :everything :all
|
17
|
-
alias :complete :all
|
18
|
-
|
19
|
-
def name *args
|
20
|
-
return 'name' if args.size == 0
|
21
|
-
CQL::NameFilter.new args[0]
|
22
|
-
end
|
23
|
-
|
24
|
-
def line *args
|
25
|
-
return 'line' if args.size == 0
|
26
|
-
CQL::LineFilter.new args.first
|
27
|
-
end
|
28
|
-
|
29
|
-
#from clause
|
30
|
-
def from where
|
31
|
-
@from = where
|
32
|
-
@data
|
33
|
-
end
|
34
|
-
|
35
|
-
%w(features scenario_outlines scenarios).each do |method_name|
|
36
|
-
define_method(method_name) { |*args|
|
37
|
-
return method_name if args.size == 0
|
38
|
-
{method_name=>args}
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
#with clause
|
43
|
-
def with filter
|
44
|
-
@data = filter.execute(@data)
|
45
|
-
end
|
46
|
-
|
47
|
-
class Comparison
|
48
|
-
attr_accessor :op, :amount
|
49
|
-
|
50
|
-
def initialize op, amount
|
51
|
-
@op = op
|
52
|
-
@amount = amount
|
53
|
-
end
|
54
|
-
|
55
|
-
def operator
|
56
|
-
{"lt"=>'<', 'lte'=>'<=', 'gt'=>'>', 'gte'=>'>='}[@op]
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
def tc comparison
|
62
|
-
if @from == 'features'
|
63
|
-
FeatureTagCountFilter.new('tc', comparison)
|
64
|
-
else
|
65
|
-
SsoTagCountFilter.new 'tc', comparison
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def lc comparison
|
70
|
-
CQL::SsoLineCountFilter.new('lc', comparison)
|
71
|
-
end
|
72
|
-
|
73
|
-
def ssoc comparison
|
74
|
-
Filter.new('ssoc', comparison)
|
75
|
-
end
|
76
|
-
|
77
|
-
def sc comparison
|
78
|
-
Filter.new('sc', comparison)
|
79
|
-
end
|
80
|
-
|
81
|
-
def soc comparison
|
82
|
-
Filter.new('soc', comparison)
|
83
|
-
end
|
84
|
-
|
85
|
-
def gt amount
|
86
|
-
Comparison.new 'gt', amount
|
87
|
-
end
|
88
|
-
|
89
|
-
def gte amount
|
90
|
-
Comparison.new 'gte', amount
|
91
|
-
end
|
92
|
-
|
93
|
-
def lt amount
|
94
|
-
Comparison.new 'lt', amount
|
95
|
-
end
|
96
|
-
|
97
|
-
def lte amount
|
98
|
-
Comparison.new 'lte', amount
|
99
|
-
end
|
100
|
-
|
101
|
-
def tags *tags
|
102
|
-
return "tags" if tags.size == 0
|
103
|
-
if @from == 'features'
|
104
|
-
FeatureTagFilter.new tags
|
105
|
-
else
|
106
|
-
CQL::SsoTagFilter.new tags
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
1
|
+
require File.dirname(__FILE__) + "/map_reduce"
|
2
|
+
module CQL
|
3
|
+
module Dsl
|
4
|
+
#Select clause
|
5
|
+
def select *what
|
6
|
+
@what = what
|
7
|
+
end
|
8
|
+
|
9
|
+
(CQL::QUERY_VALUES + %w(all step_lines examples)).each do |method_name|
|
10
|
+
define_method(method_name) { |*args|
|
11
|
+
return method_name if args.size == 0
|
12
|
+
{method_name=>args}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
alias :everything :all
|
17
|
+
alias :complete :all
|
18
|
+
|
19
|
+
def name *args
|
20
|
+
return 'name' if args.size == 0
|
21
|
+
CQL::NameFilter.new args[0]
|
22
|
+
end
|
23
|
+
|
24
|
+
def line *args
|
25
|
+
return 'line' if args.size == 0
|
26
|
+
CQL::LineFilter.new args.first
|
27
|
+
end
|
28
|
+
|
29
|
+
#from clause
|
30
|
+
def from where
|
31
|
+
@from = where
|
32
|
+
@data
|
33
|
+
end
|
34
|
+
|
35
|
+
%w(features scenario_outlines scenarios).each do |method_name|
|
36
|
+
define_method(method_name) { |*args|
|
37
|
+
return method_name if args.size == 0
|
38
|
+
{method_name=>args}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
#with clause
|
43
|
+
def with filter
|
44
|
+
@data = filter.execute(@data)
|
45
|
+
end
|
46
|
+
|
47
|
+
class Comparison
|
48
|
+
attr_accessor :op, :amount
|
49
|
+
|
50
|
+
def initialize op, amount
|
51
|
+
@op = op
|
52
|
+
@amount = amount
|
53
|
+
end
|
54
|
+
|
55
|
+
def operator
|
56
|
+
{"lt"=>'<', 'lte'=>'<=', 'gt'=>'>', 'gte'=>'>='}[@op]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
def tc comparison
|
62
|
+
if @from == 'features'
|
63
|
+
FeatureTagCountFilter.new('tc', comparison)
|
64
|
+
else
|
65
|
+
SsoTagCountFilter.new 'tc', comparison
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def lc comparison
|
70
|
+
CQL::SsoLineCountFilter.new('lc', comparison)
|
71
|
+
end
|
72
|
+
|
73
|
+
def ssoc comparison
|
74
|
+
Filter.new('ssoc', comparison)
|
75
|
+
end
|
76
|
+
|
77
|
+
def sc comparison
|
78
|
+
Filter.new('sc', comparison)
|
79
|
+
end
|
80
|
+
|
81
|
+
def soc comparison
|
82
|
+
Filter.new('soc', comparison)
|
83
|
+
end
|
84
|
+
|
85
|
+
def gt amount
|
86
|
+
Comparison.new 'gt', amount
|
87
|
+
end
|
88
|
+
|
89
|
+
def gte amount
|
90
|
+
Comparison.new 'gte', amount
|
91
|
+
end
|
92
|
+
|
93
|
+
def lt amount
|
94
|
+
Comparison.new 'lt', amount
|
95
|
+
end
|
96
|
+
|
97
|
+
def lte amount
|
98
|
+
Comparison.new 'lte', amount
|
99
|
+
end
|
100
|
+
|
101
|
+
def tags *tags
|
102
|
+
return "tags" if tags.size == 0
|
103
|
+
if @from == 'features'
|
104
|
+
FeatureTagFilter.new tags
|
105
|
+
else
|
106
|
+
CQL::SsoTagFilter.new tags
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
111
|
end
|
data/lib/feature_filters.rb
CHANGED
@@ -1,73 +1,89 @@
|
|
1
|
-
module CQL
|
2
|
-
class NameFilter
|
3
|
-
attr_reader :name
|
4
|
-
|
5
|
-
def initialize name
|
6
|
-
@name = name
|
7
|
-
end
|
8
|
-
|
9
|
-
def execute input
|
10
|
-
if name.class == String
|
11
|
-
input = input.find_all { |feature| feature
|
12
|
-
elsif name.class == Regexp
|
13
|
-
input = input.find_all { |feature| feature
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
size.
|
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
|
-
|
1
|
+
module CQL
|
2
|
+
class NameFilter
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize name
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute input
|
10
|
+
if name.class == String
|
11
|
+
input = input.find_all { |feature| feature.name == name }
|
12
|
+
elsif name.class == Regexp
|
13
|
+
input = input.find_all { |feature| feature.name =~ name }
|
14
|
+
end
|
15
|
+
|
16
|
+
input
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Filter
|
21
|
+
attr_reader :type, :comparison
|
22
|
+
|
23
|
+
def initialize type, comparison
|
24
|
+
@type = type
|
25
|
+
@comparison = comparison
|
26
|
+
end
|
27
|
+
|
28
|
+
def full_type
|
29
|
+
{"sc"=>["Scenario"], "soc"=>["Scenario Outline"], "ssoc"=>["Scenario", "Scenario Outline"]}[@type]
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute input
|
33
|
+
input.find_all do |feature|
|
34
|
+
size = feature.tests.find_all { |test|
|
35
|
+
|
36
|
+
element_class = test.class.to_s[/::.*$/].gsub(':', '')
|
37
|
+
|
38
|
+
case element_class
|
39
|
+
when 'Outline'
|
40
|
+
element_class = 'Scenario Outline'
|
41
|
+
when 'Scenario'
|
42
|
+
element_class = 'Scenario'
|
43
|
+
else
|
44
|
+
raise "Unknown class: #{element_class}"
|
45
|
+
end
|
46
|
+
|
47
|
+
full_type.include?(element_class)
|
48
|
+
}.size
|
49
|
+
|
50
|
+
size.send(comparison.operator, comparison.amount)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class FeatureTagCountFilter < Filter
|
57
|
+
def execute input
|
58
|
+
input.find_all do |feature|
|
59
|
+
feature.tags && feature.tags.size.send(comparison.operator, comparison.amount)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class TagFilter
|
65
|
+
attr_reader :tags
|
66
|
+
|
67
|
+
def initialize tags
|
68
|
+
@tags = tags
|
69
|
+
end
|
70
|
+
|
71
|
+
def has_tags given, search
|
72
|
+
return false if given == nil
|
73
|
+
search.count do |tag_for_search|
|
74
|
+
given.map { |t| t["name"] }.include?(tag_for_search)
|
75
|
+
end ==search.size
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class FeatureTagFilter < TagFilter
|
80
|
+
def initialize tags
|
81
|
+
super tags
|
82
|
+
end
|
83
|
+
|
84
|
+
def execute input
|
85
|
+
input.find_all { |feature| has_tags feature.raw_element['tags'], tags }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
73
89
|
end
|