Class: Superbolt::Messenger
- Inherits:
-
Object
- Object
- Superbolt::Messenger
- Defined in:
- lib/superbolt/messenger.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#env ⇒ Object
Returns the value of attribute env.
-
#event ⇒ Object
Returns the value of attribute event.
-
#name ⇒ Object
Returns the value of attribute name.
-
#origin ⇒ Object
Returns the value of attribute origin.
Class Method Summary collapse
Instance Method Summary collapse
- #attr_chainer(attr, val) ⇒ Object
- #data(val = nil) ⇒ Object
- #destination_name ⇒ Object
- #from(val = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Messenger
constructor
A new instance of Messenger.
- #message ⇒ Object
- #pack_files ⇒ Object
- #queue ⇒ Object
- #re(val = nil) ⇒ Object
-
#send!(args = nil) ⇒ Object
alias ——-.
-
#to(val = nil) ⇒ Object
chainer methods.
Constructor Details
#initialize(options = {}) ⇒ Messenger
Returns a new instance of Messenger.
5 6 7 8 9 10 11 |
# File 'lib/superbolt/messenger.rb', line 5 def initialize(={}) @name = .delete(:to) @origin = .delete(:from) || Superbolt.app_name @event = .delete(:event) || self.class.defaultevent @env = Superbolt.env @arguments = end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
3 4 5 |
# File 'lib/superbolt/messenger.rb', line 3 def arguments @arguments end |
#env ⇒ Object
Returns the value of attribute env.
3 4 5 |
# File 'lib/superbolt/messenger.rb', line 3 def env @env end |
#event ⇒ Object
Returns the value of attribute event.
3 4 5 |
# File 'lib/superbolt/messenger.rb', line 3 def event @event end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/superbolt/messenger.rb', line 3 def name @name end |
#origin ⇒ Object
Returns the value of attribute origin.
3 4 5 |
# File 'lib/superbolt/messenger.rb', line 3 def origin @origin end |
Class Method Details
.defaultevent ⇒ Object
73 74 75 |
# File 'lib/superbolt/messenger.rb', line 73 def self.defaultevent 'default' end |
Instance Method Details
#attr_chainer(attr, val) ⇒ Object
39 40 41 42 43 |
# File 'lib/superbolt/messenger.rb', line 39 def attr_chainer(attr, val) return send(attr) unless val self.send("#{attr}=", val) self end |
#data(val = nil) ⇒ Object
35 36 37 |
# File 'lib/superbolt/messenger.rb', line 35 def data(val=nil) attr_chainer(:arguments, val) end |
#destination_name ⇒ Object
69 70 71 |
# File 'lib/superbolt/messenger.rb', line 69 def destination_name "#{name}_#{env}" end |
#from(val = nil) ⇒ Object
27 28 29 |
# File 'lib/superbolt/messenger.rb', line 27 def from(val=nil) attr_chainer(:origin, val) end |
#message ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/superbolt/messenger.rb', line 13 def { origin: origin, event: event, arguments: arguments } end |
#pack_files ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/superbolt/messenger.rb', line 54 def pack_files return unless arguments.is_a?(Hash) file_keys = arguments.keys.find_all { |key| key.to_s.match(Superbolt.file_matcher) } file_keys.each do |key| arguments[key] = FileMarshal::Dumper.new(arguments[key]).to_hash end end |
#queue ⇒ Object
62 63 64 65 66 67 |
# File 'lib/superbolt/messenger.rb', line 62 def queue unless name raise "no destination app name defined, please pass one in" end Queue.new(destination_name) end |
#re(val = nil) ⇒ Object
31 32 33 |
# File 'lib/superbolt/messenger.rb', line 31 def re(val=nil) attr_chainer(:event, val) end |
#send!(args = nil) ⇒ Object
alias
48 49 50 51 52 |
# File 'lib/superbolt/messenger.rb', line 48 def send!(args=nil) self.arguments = args if args pack_files queue.push() end |
#to(val = nil) ⇒ Object
chainer methods
23 24 25 |
# File 'lib/superbolt/messenger.rb', line 23 def to(val=nil) attr_chainer(:name, val) end |