Class: Fabulator::Expr::StatementList
- Inherits:
-
Object
- Object
- Fabulator::Expr::StatementList
- Defined in:
- lib/fabulator/expr/statement_list.rb
Instance Method Summary collapse
- #add_catch(s) ⇒ Object
- #add_ensure(s) ⇒ Object
- #add_statement(s) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ StatementList
constructor
A new instance of StatementList.
- #is_noop? ⇒ Boolean
- #run(context, autovivify = false) ⇒ Object
- #use_context(c) ⇒ Object
Constructor Details
#initialize ⇒ StatementList
Returns a new instance of StatementList.
4 5 6 7 8 9 |
# File 'lib/fabulator/expr/statement_list.rb', line 4 def initialize @statements = [ ] @ensures = [ ] @catches = [ ] @context = nil end |
Instance Method Details
#add_catch(s) ⇒ Object
23 24 25 |
# File 'lib/fabulator/expr/statement_list.rb', line 23 def add_catch(s) @catches << s end |
#add_ensure(s) ⇒ Object
19 20 21 |
# File 'lib/fabulator/expr/statement_list.rb', line 19 def add_ensure(s) @ensures << s end |
#add_statement(s) ⇒ Object
15 16 17 |
# File 'lib/fabulator/expr/statement_list.rb', line 15 def add_statement(s) @statements << s if !s.nil? end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/fabulator/expr/statement_list.rb', line 31 def empty? @statements.empty? && @ensures.empty? end |
#is_noop? ⇒ Boolean
27 28 29 |
# File 'lib/fabulator/expr/statement_list.rb', line 27 def is_noop? @statements.empty? && @ensures.empty? end |
#run(context, autovivify = false) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fabulator/expr/statement_list.rb', line 35 def run(context, autovivify = false) if !@context.nil? context = @context end result = [ ] begin if !@statements.nil? (@statements - [nil]).each do |s| result = s.run(context, autovivify) end end rescue Fabulator::StateChangeException => e raise e rescue => e result = [] caught = false ex = nil if e.is_a?(Fabulator::Expr::Exception) ex = e.node else ex = context.root.anon_node(e.to_s, [ FAB_NS, 'string' ]) ex.set_attribute('class', 'ruby.' + e.class.to_s.gsub(/::/, '.')) end if !@catches.nil? @catches.each do |s| if !s.nil? && s.run_test(ex) caught = true result = s.run(context.with_root(ex), autovivify) end end end raise e unless caught ensure if !@ensures.nil? && !@ensures.empty? @ensures.each do |s| s.run(context, autovivify) unless s.nil? end end end return result end |
#use_context(c) ⇒ Object
11 12 13 |
# File 'lib/fabulator/expr/statement_list.rb', line 11 def use_context(c) @context = c end |