Class: Flok::UserCompilerAction
- Inherits:
-
Object
- Object
- Flok::UserCompilerAction
- Includes:
- UserCompilerMacro
- Defined in:
- lib/flok/user_compiler.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#every_handlers ⇒ Object
Returns the value of attribute every_handlers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ons ⇒ Object
Returns the value of attribute ons.
Instance Method Summary collapse
- #every(seconds, str) ⇒ Object
-
#initialize(controller, name, ctx, &block) ⇒ UserCompilerAction
constructor
A new instance of UserCompilerAction.
-
#method_missing(method, *args, &block) ⇒ Object
You can def things in controller and use them as macros inside actions But these defs.
- #on(name, js_src) ⇒ Object
- #on_entry(js_src) ⇒ Object
- #on_entry_src ⇒ Object
Methods included from UserCompilerMacro
Constructor Details
#initialize(controller, name, ctx, &block) ⇒ UserCompilerAction
Returns a new instance of UserCompilerAction.
422 423 424 425 426 427 428 429 430 431 |
# File 'lib/flok/user_compiler.rb', line 422 def initialize controller, name, ctx, &block @controller = controller @name = name @ctx = ctx @_on_entry_src = "" @ons = [] #Event handlers @every_handlers = [] self.instance_eval(&block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
You can def things in controller and use them as macros inside actions But these defs. live in the UserCompilerController instance and we need to delegate these calls to the controller that are not available in the action
457 458 459 460 461 462 463 464 |
# File 'lib/flok/user_compiler.rb', line 457 def method_missing method, *args, &block if macro = @controller.macros[method] #Call the macro in our context self.instance_eval(¯o) else raise "No macro found named: #{method}" end end |
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
419 420 421 |
# File 'lib/flok/user_compiler.rb', line 419 def controller @controller end |
#every_handlers ⇒ Object
Returns the value of attribute every_handlers.
419 420 421 |
# File 'lib/flok/user_compiler.rb', line 419 def every_handlers @every_handlers end |
#name ⇒ Object
Returns the value of attribute name.
419 420 421 |
# File 'lib/flok/user_compiler.rb', line 419 def name @name end |
#ons ⇒ Object
Returns the value of attribute ons.
419 420 421 |
# File 'lib/flok/user_compiler.rb', line 419 def ons @ons end |
Instance Method Details
#every(seconds, str) ⇒ Object
446 447 448 449 450 451 452 |
# File 'lib/flok/user_compiler.rb', line 446 def every seconds, str @every_handlers << { :name => "#{seconds}_sec_#{SecureRandom.hex[0..6]}", :ticks => seconds*4, :src => _macro(str) } end |
#on(name, js_src) ⇒ Object
442 443 444 |
# File 'lib/flok/user_compiler.rb', line 442 def on name, js_src @ons << {:name => name, :src => _macro(js_src)} end |
#on_entry(js_src) ⇒ Object
433 434 435 436 |
# File 'lib/flok/user_compiler.rb', line 433 def on_entry js_src #returns a string @_on_entry_src = _macro(js_src) end |
#on_entry_src ⇒ Object
438 439 440 |
# File 'lib/flok/user_compiler.rb', line 438 def on_entry_src return @_on_entry_src end |