lib/engine2/action.rb in engine2-1.0.0 vs lib/engine2/action.rb in engine2-1.0.1

- old
+ new

@@ -2,11 +2,11 @@ module Engine2 class Action < BasicObject ACCESS_FORBIDDEN ||= ->h{false} attr_reader :parent, :name, :number, :actions, :recheck_access - attr_reader :meta_proc + attr_reader :meta_proc, :meta_proc_chained class << self attr_accessor :count end @@ -19,16 +19,25 @@ @actions = {} end def * &blk if blk - ::Kernel.raise E2Error.new("Meta #{name} with proc already defined for action #{self.inspect}") if @meta_proc - @meta_proc = blk + @meta_proc = if meta_proc = @meta_proc + @meta_proc_chained = true + ::Kernel::lambda do |obj| + obj.instance_eval(&meta_proc) + obj.instance_eval(&blk) + end + else + blk + end end @meta end + alias :meta :* + def access! &blk ::Kernel.raise E2Error.new("Access for action #{name} already defined") if @access_block @access_block = blk end @@ -55,9 +64,15 @@ action end action.instance_eval(&blk) if blk action.*.action_defined action + end + + def define_action_meta name, meta_class = DummyMeta, assets = {}, &blk + define_action name, meta_class, assets do + self.* &blk + end end def undefine_action name ::Kernel.raise E2Error.new("No action #{name} defined") unless @actions[name] @actions.delete(name) \ No newline at end of file