Class: RedShift::TransitionSyntax::TransitionParser
- Defined in:
- lib/redshift/syntax.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#connects ⇒ Object
readonly
Returns the value of attribute connects.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#guards ⇒ Object
readonly
Returns the value of attribute guards.
-
#name(*n) ⇒ Object
readonly
Returns the value of attribute name.
-
#posts ⇒ Object
readonly
Returns the value of attribute posts.
-
#resets ⇒ Object
readonly
Returns the value of attribute resets.
-
#syncs ⇒ Object
readonly
Returns the value of attribute syncs.
Instance Method Summary collapse
- #action(meth = nil, &bl) ⇒ Object
-
#connect(h) ⇒ Object
h
is a hash of :var => proc port_expr_ruby or [:link, :var]. -
#event(*args, &bl) ⇒ Object
each arg can be an event name (string or symbol), exported with value
true
, or a hash of event_name => value. - #guard(*args, &block) ⇒ Object
-
#initialize(block) ⇒ TransitionParser
constructor
A new instance of TransitionParser.
- #literal(val) ⇒ Object
- #post(meth = nil, &bl) ⇒ Object (also: #after)
-
#reset(h) ⇒ Object
h
is a hash of :var => proc value_expr_ruby or “value_expr_c” or a literal. - #sync(*a) ⇒ Object
- #wait(*args) ⇒ Object
Constructor Details
#initialize(block) ⇒ TransitionParser
Returns a new instance of TransitionParser.
323 324 325 326 |
# File 'lib/redshift/syntax.rb', line 323 def initialize block @name = nil instance_eval(&block) end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def actions @actions end |
#connects ⇒ Object (readonly)
Returns the value of attribute connects.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def connects @connects end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def events @events end |
#guards ⇒ Object (readonly)
Returns the value of attribute guards.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def guards @guards end |
#name(*n) ⇒ Object (readonly)
Returns the value of attribute name.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def name @name end |
#posts ⇒ Object (readonly)
Returns the value of attribute posts.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def posts @posts end |
#resets ⇒ Object (readonly)
Returns the value of attribute resets.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def resets @resets end |
#syncs ⇒ Object (readonly)
Returns the value of attribute syncs.
318 319 320 |
# File 'lib/redshift/syntax.rb', line 318 def syncs @syncs end |
Instance Method Details
#action(meth = nil, &bl) ⇒ Object
392 393 394 395 396 |
# File 'lib/redshift/syntax.rb', line 392 def action(meth = nil, &bl) @actions ||= Component::ActionPhase.new @actions << meth if meth @actions << bl if bl end |
#connect(h) ⇒ Object
h
is a hash of :var => proc port_expr_ruby or [:link, :var].
427 428 429 430 431 432 433 434 435 |
# File 'lib/redshift/syntax.rb', line 427 def connect(h) badkeys = h.keys.reject {|k| k.is_a?(Symbol)} unless badkeys.empty? raise SyntaxError, "Keys #{badkeys.inspect} in connect must be symbols" end @connects ||= Component::ConnectPhase.new @connects.concat h.entries end |
#event(*args, &bl) ⇒ Object
each arg can be an event name (string or symbol), exported with value true
, or a hash of event_name => value. In the latter case, value can be either a Proc, string (C expr), or a literal. If you need to treat a Proc or string as a literal, use the notation
:e => literal("str")
:e => literal(proc {...})
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/redshift/syntax.rb', line 446 def event(*args, &bl) @events ||= Component::EventPhase.new for arg in args case arg when Symbol, String item = Component::EventPhaseItem.new item.event = arg item.value = true @events << item when Hash arg.sort_by {|e,v| e.to_s}.each do |e,v| item = Component::EventPhaseItem.new item.event = e item.value = v @events << item end else raise SyntaxError, "unrecognized event specifier #{arg}." end end if bl eb = EventBlockParser.new(bl) @events.concat(eb.events) end end |
#guard(*args, &block) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/redshift/syntax.rb', line 375 def guard(*args, &block) @guards ||= Component::GuardPhase.new args.each do |arg| case arg when String; @guards << arg.strip # "<expression>" when Proc; @guards << arg # proc { ... } when Symbol; @guards << arg # :method when nil, true; # no condition when false; @guards << arg else raise SyntaxError, "'guard #{arg.inspect}'" end end @guards << block if block end |
#literal(val) ⇒ Object
473 474 475 |
# File 'lib/redshift/syntax.rb', line 473 def literal val Component.literal val end |
#post(meth = nil, &bl) ⇒ Object Also known as: after
398 399 400 401 402 |
# File 'lib/redshift/syntax.rb', line 398 def post(meth = nil, &bl) @posts ||= Component::PostPhase.new @posts << meth if meth @posts << bl if bl end |
#reset(h) ⇒ Object
h
is a hash of :var => proc value_expr_ruby or “value_expr_c” or a literal.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/redshift/syntax.rb', line 406 def reset(h) badkeys = h.keys.reject {|k| k.is_a?(Symbol)} unless badkeys.empty? raise SyntaxError, "Keys #{badkeys.inspect} in reset must be symbols" end h.keys.each do |k| v = h[k] case v when String h[k] = v.strip end end @resets ||= Component::ResetPhase.new @resets.value_map ||= {} @resets.concat [nil, nil, nil] # continuous, constant, link @resets.value_map.update h end |
#sync(*a) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/redshift/syntax.rb', line 330 def sync(*a) @syncs ||= Component::SyncPhase.new if a.last.kind_of?(Hash) a.concat a.pop.to_a end a.each do |link_name, event| link_names = case link_name when Array; link_name else [link_name] end events = case event when Array; event else [event] end link_names.each do |ln| events.each do |e| item = Component::SyncPhaseItem.new item.link_name = ln item.event = e @syncs << item end end end end |
#wait(*args) ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/redshift/syntax.rb', line 359 def wait(*args) @guards ||= Component::GuardPhase.new args.each do |arg| case arg when Hash @guards.concat(arg.sort_by {|q,m| q.to_s}.map{|q,m| Component::QMatch[q.to_sym,*m]}) # { :queue => match } when Symbol @guards << Component::QMatch[arg] # :queue else raise SyntaxError end end end |