module CQL::Dsl

The Domain Specific Language used for performing queries.

Public Instance Methods

as(*name_transforms) click to toggle source

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

# 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) click to toggle source

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

# File lib/cql/dsl.rb, line 143
def eq amount
  Comparison.new '==', amount
end
from(*targets) click to toggle source

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

# 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) click to toggle source

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

# File lib/cql/dsl.rb, line 123
def gt amount
  Comparison.new '>', amount
end
gte(amount) click to toggle source

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

# File lib/cql/dsl.rb, line 128
def gte amount
  Comparison.new '>=', amount
end
lc(comparison) click to toggle source

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

# File lib/cql/dsl.rb, line 103
def lc comparison
  CQL::SsoLineCountFilter.new('lc', comparison)
end
line(*args) click to toggle source

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

# File lib/cql/dsl.rb, line 47
def line *args
  return 'line' if args.size == 0
  CQL::LineFilter.new args.first
end
lt(amount) click to toggle source

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

# File lib/cql/dsl.rb, line 133
def lt amount
  Comparison.new '<', amount
end
lte(amount) click to toggle source

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

# File lib/cql/dsl.rb, line 138
def lte amount
  Comparison.new '<=', amount
end
method_missing(method_name) click to toggle source

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

# File lib/cql/dsl.rb, line 9
def method_missing(method_name)
  method_name.to_s
end
name(*args) click to toggle source

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

# File lib/cql/dsl.rb, line 41
def name *args
  return 'name' if args.size == 0
  CQL::NameFilter.new args[0]
end
sc(comparison) click to toggle source

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

# File lib/cql/dsl.rb, line 113
def sc comparison
  TestCountFilter.new([CukeModeler::Scenario], comparison)
end
select(*what) click to toggle source

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

# File lib/cql/dsl.rb, line 33
def select *what
  what = [:self] if what.empty?

  @what ||= []
  @what.concat(what)
end
soc(comparison) click to toggle source

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

# File lib/cql/dsl.rb, line 118
def soc comparison
  TestCountFilter.new([CukeModeler::Outline], comparison)
end
ssoc(comparison) click to toggle source

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

# File lib/cql/dsl.rb, line 108
def ssoc comparison
  TestCountFilter.new([CukeModeler::Scenario, CukeModeler::Outline], comparison)
end
tags(*tags) click to toggle source

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

# File lib/cql/dsl.rb, line 148
def tags *tags
  return "tags" if tags.size == 0

  TagFilter.new tags
end
tc(comparison) click to toggle source

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

# File lib/cql/dsl.rb, line 98
def tc comparison
  TagCountFilter.new 'tc', comparison
end
transform(*attribute_transforms, &block) click to toggle source

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

# 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) click to toggle source

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

# 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) click to toggle source

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

# 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

Private Instance Methods

add_transforms(new_transforms, transform_set) click to toggle source
# File lib/cql/dsl.rb, line 167
def add_transforms(new_transforms, transform_set)
  # todo - accept either array or a hash
  if new_transforms.first.is_a?(Hash)
    additional_transforms = new_transforms.first

    additional_transforms.each do |key, value|
      if transform_set.has_key?(key)
        transform_set[key] << value
      else
        transform_set[key] = [value]
      end
    end
  else

    transform_set.concat(new_transforms)
  end
end
determine_class(where) click to toggle source
# File lib/cql/dsl.rb, line 185
def determine_class(where)
  # Translate shorthand Strings to final class
  where = translate_shorthand(where)

  # Check for exact class match first because it should take precedence
  return CukeModeler.const_get(where) if CukeModeler.const_defined?(where)

  # Check for pluralization of class match (i.e. remove the final 's')
  return CukeModeler.const_get(where.chop) if CukeModeler.const_defined?(where.chop)

  # Then the class must not be a CukeModeler class
  raise(ArgumentError, "Class 'CukeModeler::#{where}' does not exist")
end
prep_variable(var_name, transforms) click to toggle source
# File lib/cql/dsl.rb, line 162
def prep_variable(var_name, transforms)
  starting_value = transforms.first.is_a?(Hash) ? {} : []
  instance_variable_set("@#{var_name}".to_sym, starting_value)
end
translate_shorthand(where) click to toggle source
# File lib/cql/dsl.rb, line 158
def translate_shorthand(where)
  where.split('_').map(&:capitalize).join
end