Class: Fabulator::Core::Actions::Raise

Inherits:
Action
  • Object
show all
Defined in:
lib/fabulator/core/actions/choose.rb

Instance Method Summary collapse

Instance Method Details

#run(context, autovivify = false) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fabulator/core/actions/choose.rb', line 105

def run(context, autovivify = false)
  @context.with(context) do |ctx|
    select = ctx.get_select
    if !@test.nil?
      test_res = self.test(ctx).collect{ |a| !!a.value }
      return [ ] if test_res.nil? || test_res.empty? || !test_res.include?(true)
    end
    res = [ ]
    if select.nil? && self.has_actions?
      res = self.run_actions(ctx)
    elsif !select.nil?
      res = select.run(ctx, autovivify)
    else
      raise ctx   # default if <raise/> with no attributes
    end

    return [ ] if res.empty?

    raise Fabulator::Expr::Exception.new(res.first)
  end
end