Skip to content

Commit

Permalink
EngineDSL#use accepts arity 0 and 1 blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Dec 14, 2011
1 parent adc8823 commit 1a0b40e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions lib/temple/mixins/engine_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def remove(name)

alias use append

# DEPRECATED!
#
# wildcard(:FilterName) { FilterClass.new(options) }
#
# is replaced by
#
# use(:FilterName) { FilterClass.new(options) }
#
alias wildcard use

def before(name, *args, &block)
name = Class === name ? name.name.to_sym : name
raise(ArgumentError, 'First argument must be Class or Symbol') unless Symbol === name
Expand Down Expand Up @@ -86,12 +96,6 @@ def generator(name, *options)
use(name, Temple::Generators.const_get(name), *options)
end

def wildcard(name, &block)
raise(ArgumentError, 'Block must have arity 0') unless block.arity <= 0
chain << [name, define_chain_method("WILDCARD #{name}", block)]
chain_modified!
end

private

def define_chain_method(name, proc)
Expand Down Expand Up @@ -125,7 +129,7 @@ def element(args, block)
# The proc is converted to a method of the engine class.
# The proc can then access the option hash of the engine.
raise(ArgumentError, 'Too many arguments') unless args.empty?
raise(ArgumentError, 'Proc or blocks must have arity 1') unless filter.arity == 1
raise(ArgumentError, 'Proc or blocks must have arity 0 or 1') if filter.arity != 1 && filter.arity != 0
[name, define_chain_method("FILTER #{name}", filter)]
when Class
# Class argument (e.g Filter class)
Expand Down
2 changes: 1 addition & 1 deletion test/test_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestEngine < Temple::Engine
filter :MultiFlattener
generator :ArrayBuffer
use :BeforeLast, Callable1.new
wildcard(:Last) { Callable2.new }
use(:Last) { Callable2.new }
end

describe Temple::Engine do
Expand Down

0 comments on commit 1a0b40e

Please sign in to comment.