Class: Myxi::Action
- Inherits:
-
Object
- Object
- Myxi::Action
- Defined in:
- lib/myxi/action.rb
Constant Summary collapse
- ACTIONS =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #execute(session, payload = {}) ⇒ Object
-
#initialize(name, &block) ⇒ Action
constructor
A new instance of Action.
Constructor Details
#initialize(name, &block) ⇒ Action
Returns a new instance of Action.
12 13 14 15 |
# File 'lib/myxi/action.rb', line 12 def initialize(name, &block) @name = name @block = block end |
Class Method Details
.add(name, &block) ⇒ Object
8 9 10 |
# File 'lib/myxi/action.rb', line 8 def self.add(name, &block) ACTIONS[name.to_sym] = self.new(name, &block) end |
Instance Method Details
#execute(session, payload = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/myxi/action.rb', line 17 def execute(session, payload = {}) environment = Environment.new(session, payload) environment.instance_exec(session, payload, &@block) rescue Environment::Error => e session.send('Error', :error => e.class.to_s.split('::').last) rescue => e Myxi.logger.debug "[#{session.id}] \e[41;37mERROR\e[0m \e[31m#{e.class.to_s} #{e.}\e[0m" e.backtrace { |br| Myxi.logger.debug "[#{session.id}] \e[41;37mERROR\e[0m #{br}" } session.send('InternalError', :error => e.class.to_s, :message => e.) end |