Module: CQL::Dsl

Included in:
MapReduce, Query
Defined in:
lib/cql/dsl.rb

Overview

The Domain Specific Language used for performing queries.

Defined Under Namespace

Classes: Comparison

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object

Any undefined method is assumed to mean its String equivalent, thus allowing a more convenient query syntax.



9
10
11
# File 'lib/cql/dsl.rb', line 9

def method_missing(method_name)
  method_name.to_s
end

Instance Method Details

#as(*name_transforms) ⇒ Object

Adds an as clause to the query. See the corresponding Cucumber documentation for details.



26
27
28
29
30
# File 'lib/cql/dsl.rb', line 26

def as(*name_transforms)
  prep_variable('name_transforms', name_transforms) unless @name_transforms

  add_transforms(name_transforms, @name_transforms)
end

#eq(amount) ⇒ Object

Adds an eq filter operator to the query. See the corresponding Cucumber documentation for details.



143
144
145
# File 'lib/cql/dsl.rb', line 143

def eq amount
  Comparison.new '==', amount
end

#from(*targets) ⇒ Object

Adds a from clause to the query. See the corresponding Cucumber documentation for details.



53
54
55
56
57
58
59
# File 'lib/cql/dsl.rb', line 53

def from(*targets)
  @from ||= []

  targets.map! { |target| target.is_a?(String) ? determine_class(target) : target }

  @from.concat(targets)
end

#gt(amount) ⇒ Object

Adds a gt filter operator to the query. See the corresponding Cucumber documentation for details.



123
124
125
# File 'lib/cql/dsl.rb', line 123

def gt amount
  Comparison.new '>', amount
end

#gte(amount) ⇒ Object

Adds a gte filter operator to the query. See the corresponding Cucumber documentation for details.



128
129
130
# File 'lib/cql/dsl.rb', line 128

def gte amount
  Comparison.new '>=', amount
end

#lc(comparison) ⇒ Object

Adds a lc filter to the query. See the corresponding Cucumber documentation for details.



103
104
105
# File 'lib/cql/dsl.rb', line 103

def lc comparison
  CQL::SsoLineCountFilter.new('lc', comparison)
end

#line(*args) ⇒ Object

Adds a line filter to the query. See the corresponding Cucumber documentation for details.



47
48
49
50
# File 'lib/cql/dsl.rb', line 47

def line *args
  return 'line' if args.size == 0
  CQL::LineFilter.new args.first
end

#lt(amount) ⇒ Object

Adds an lt filter operator to the query. See the corresponding Cucumber documentation for details.



133
134
135
# File 'lib/cql/dsl.rb', line 133

def lt amount
  Comparison.new '<', amount
end

#lte(amount) ⇒ Object

Adds an lte filter operator to the query. See the corresponding Cucumber documentation for details.



138
139
140
# File 'lib/cql/dsl.rb', line 138

def lte amount
  Comparison.new '<=', amount
end

#name(*args) ⇒ Object

Adds a name filter to the query. See the corresponding Cucumber documentation for details.



41
42
43
44
# File 'lib/cql/dsl.rb', line 41

def name *args
  return 'name' if args.size == 0
  CQL::NameFilter.new args[0]
end

#sc(comparison) ⇒ Object

Adds an sc filter to the query. See the corresponding Cucumber documentation for details.



113
114
115
# File 'lib/cql/dsl.rb', line 113

def sc comparison
  TestCountFilter.new([CukeModeler::Scenario], comparison)
end

#select(*what) ⇒ Object

Adds a select clause to the query. See the corresponding Cucumber documentation for details.



33
34
35
36
37
38
# File 'lib/cql/dsl.rb', line 33

def select *what
  what = [:self] if what.empty?

  @what ||= []
  @what.concat(what)
end

#soc(comparison) ⇒ Object

Adds an soc filter to the query. See the corresponding Cucumber documentation for details.



118
119
120
# File 'lib/cql/dsl.rb', line 118

def soc comparison
  TestCountFilter.new([CukeModeler::Outline], comparison)
end

#ssoc(comparison) ⇒ Object

Adds an ssoc filter to the query. See the corresponding Cucumber documentation for details.



108
109
110
# File 'lib/cql/dsl.rb', line 108

def ssoc comparison
  TestCountFilter.new([CukeModeler::Scenario, CukeModeler::Outline], comparison)
end

#tags(*tags) ⇒ Object

Adds a tags filter to the query. See the corresponding Cucumber documentation for details.



148
149
150
151
152
# File 'lib/cql/dsl.rb', line 148

def tags *tags
  return "tags" if tags.size == 0

  TagFilter.new tags
end

#tc(comparison) ⇒ Object

Adds a tc filter to the query. See the corresponding Cucumber documentation for details.



98
99
100
# File 'lib/cql/dsl.rb', line 98

def tc comparison
  TagCountFilter.new 'tc', comparison
end

#transform(*attribute_transforms, &block) ⇒ Object

Adds a transform clause to the query. See the corresponding Cucumber documentation for details.



14
15
16
17
18
19
20
21
22
23
# File 'lib/cql/dsl.rb', line 14

def transform(*attribute_transforms, &block)
  # todo - Still feels like some as/transform code duplication but I think that it would get too meta if I
  # reduced it any further. Perhaps change how the transforms are handled so that there doesn't have to be
  # an array/hash difference in the first place?
  prep_variable('value_transforms', attribute_transforms) unless @value_transforms

  # todo - what if they pass in a hash transform and a block?
  attribute_transforms << block if block
  add_transforms(attribute_transforms, @value_transforms)
end

#with(*conditions, &block) ⇒ Object

Adds a with clause to the query. See the corresponding Cucumber documentation for details.



62
63
64
65
66
67
68
69
# File 'lib/cql/dsl.rb', line 62

def with(*conditions, &block)
  @filters ||= []

  @filters << {:negate => false, :filter => block} if block
  conditions.each do |condition|
    @filters << {:negate => false, :filter => condition}
  end
end

#without(*conditions, &block) ⇒ Object

Adds a without clause to the query. See the corresponding Cucumber documentation for details.



72
73
74
75
76
77
78
79
# File 'lib/cql/dsl.rb', line 72

def without(*conditions, &block)
  @filters ||= []

  @filters << {:negate => true, :filter => block} if block
  conditions.each do |condition|
    @filters << {:negate => true, :filter => condition}
  end
end