Class: Philtre::PredicateDsl

Inherits:
Module
  • Object
show all
Defined in:
lib/philtre/predicate_dsl.rb

Overview

This is a specialised module that also understands a simple DSL for creating predicates as methods.

This is how the DSL works: each meth is a predicate, args is a set of alternatives and the block must return something convertible to a Sequel.expr to create the expression for that predicate.

Instance Method Summary collapse

Constructor Details

#initialize(&bloc) ⇒ PredicateDsl

Returns a new instance of PredicateDsl.



10
11
12
13
14
15
16
17
18
# File 'lib/philtre/predicate_dsl.rb', line 10

def initialize( &bloc )
  if bloc
    if bloc.arity == 0
      module_eval &bloc
    else
      bloc.call self
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &bloc) ⇒ Object



20
21
22
23
# File 'lib/philtre/predicate_dsl.rb', line 20

def method_missing(meth, *args, &bloc)
  define_method meth, &bloc
  args.each{|arg| send :alias_method, arg, meth }
end