Class: Villein::Event
- Inherits:
-
Object
- Object
- Villein::Event
- Defined in:
- lib/villein/event.rb
Constant Summary collapse
- MEMBERS_EVENT =
%w(member-join member-leave member-failed member-update member-reap)
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#query_ltime ⇒ Object
readonly
Returns the value of attribute query_ltime.
-
#query_name ⇒ Object
readonly
Returns the value of attribute query_name.
-
#self_name ⇒ Object
readonly
Returns the value of attribute self_name.
-
#self_tags ⇒ Object
readonly
Returns the value of attribute self_tags.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#user_event ⇒ Object
readonly
Returns the value of attribute user_event.
-
#user_ltime ⇒ Object
readonly
Returns the value of attribute user_ltime.
Instance Method Summary collapse
-
#initialize(env = {}, payload: nil) ⇒ Event
constructor
A new instance of Event.
- #ltime ⇒ Object
-
#members ⇒ Object
Parse and returns member list in Array<Hash> when available.
Constructor Details
#initialize(env = {}, payload: nil) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/villein/event.rb', line 5 def initialize(env={}, payload: nil) @type = env['SERF_EVENT'] @self_name = env['SERF_SELF_NAME'] @self_tags = Hash[env.select{ |k, v| /^SERF_TAG_/ =~ k }.map { |k, v| [k.sub(/^SERF_TAG_/, ''), v] }] @user_event = env['SERF_USER_EVENT'] @query_name = env['SERF_QUERY_NAME'] @user_ltime = env['SERF_USER_LTIME'] @query_ltime = env['SERF_QUERY_LTIME'] @payload = payload end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def payload @payload end |
#query_ltime ⇒ Object (readonly)
Returns the value of attribute query_ltime.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def query_ltime @query_ltime end |
#query_name ⇒ Object (readonly)
Returns the value of attribute query_name.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def query_name @query_name end |
#self_name ⇒ Object (readonly)
Returns the value of attribute self_name.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def self_name @self_name end |
#self_tags ⇒ Object (readonly)
Returns the value of attribute self_tags.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def @self_tags end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def type @type end |
#user_event ⇒ Object (readonly)
Returns the value of attribute user_event.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def user_event @user_event end |
#user_ltime ⇒ Object (readonly)
Returns the value of attribute user_ltime.
16 17 18 |
# File 'lib/villein/event.rb', line 16 def user_ltime @user_ltime end |
Instance Method Details
#ltime ⇒ Object
18 19 20 |
# File 'lib/villein/event.rb', line 18 def ltime user_ltime || query_ltime end |
#members ⇒ Object
Parse and returns member list in Array<Hash> when available. Always return nil
if the event type is not member-*
.
25 26 27 28 29 30 31 32 33 |
# File 'lib/villein/event.rb', line 25 def members return nil unless MEMBERS_EVENT.include?(type) @members ||= begin payload.each_line.map do |line| name, address, _, = line.chomp.split(/\t/) {name: name, address: address, tags: ( || '')} end end end |