Sha256: c7add996fab2608003550148d9860ab29686628a0c7495e99c375bf3588a8933

Contents?: true

Size: 679 Bytes

Versions: 4

Compression:

Stored size: 679 Bytes

Contents

module Philtre
  # 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.
  class PredicateDsl < Module
    def initialize( &bloc )
      if bloc
        if bloc.arity == 0
          module_eval &bloc
        else
          bloc.call self
        end
      end
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
philtre-0.1.2 lib/philtre/predicate_dsl.rb
philtre-0.1.1 lib/philtre/predicate_dsl.rb
philtre-0.1.0 lib/philtre/predicate_dsl.rb
philtre-0.0.1 lib/philtre/predicate_dsl.rb