Class: Loco::Hub
- Inherits:
-
Object
- Object
- Loco::Hub
- Defined in:
- lib/loco/hub.rb
Constant Summary collapse
- PREFIX =
'hub:'
Class Method Summary collapse
Instance Method Summary collapse
- #add_member(member) ⇒ Object
- #del_member(member) ⇒ Object
- #destroy ⇒ Object
- #full_name ⇒ Object
- #include?(resource) ⇒ Boolean
-
#initialize(name, members = []) ⇒ Hub
constructor
A new instance of Hub.
- #members ⇒ Object
- #name ⇒ Object
- #raw_members ⇒ Object
Constructor Details
#initialize(name, members = []) ⇒ Hub
Returns a new instance of Hub.
23 24 25 26 |
# File 'lib/loco/hub.rb', line 23 def initialize(name, members = []) @name = self.class.full_name(name) members.map { |member| add_member(member) } end |
Class Method Details
.full_name(val) ⇒ Object
18 19 20 |
# File 'lib/loco/hub.rb', line 18 def full_name(val) "#{PREFIX}#{val}" end |
.get(name) ⇒ Object
12 13 14 15 16 |
# File 'lib/loco/hub.rb', line 12 def get(name) return nil if WsConnectionStorage.current.type("s:#{full_name(name)}") != 'set' new(name) end |
.set(name, members) ⇒ Object
8 9 10 |
# File 'lib/loco/hub.rb', line 8 def set(name, members) new(name, members) end |
Instance Method Details
#add_member(member) ⇒ Object
36 37 38 |
# File 'lib/loco/hub.rb', line 36 def add_member(member) WsConnectionStorage.current.add(@name, WsConnectionIdentifier.(member)) end |
#del_member(member) ⇒ Object
40 41 42 |
# File 'lib/loco/hub.rb', line 40 def del_member(member) WsConnectionStorage.current.rem(@name, WsConnectionIdentifier.(member)) end |
#destroy ⇒ Object
44 45 46 47 48 |
# File 'lib/loco/hub.rb', line 44 def destroy WsConnectionStorage.current.members(@name).each do |member| WsConnectionStorage.current.rem(@name, member) end end |
#full_name ⇒ Object
32 33 34 |
# File 'lib/loco/hub.rb', line 32 def full_name @name end |
#include?(resource) ⇒ Boolean
50 51 52 |
# File 'lib/loco/hub.rb', line 50 def include?(resource) WsConnectionStorage.current.member?(@name, WsConnectionIdentifier.(resource)) end |
#members ⇒ Object
58 59 60 61 62 63 |
# File 'lib/loco/hub.rb', line 58 def members raw_members.map do |serialized| klass, id = serialized.split(':') klass.classify.constantize.find_by(id: id) end end |
#name ⇒ Object
28 29 30 |
# File 'lib/loco/hub.rb', line 28 def name full_name.split(PREFIX).last end |
#raw_members ⇒ Object
54 55 56 |
# File 'lib/loco/hub.rb', line 54 def raw_members WsConnectionStorage.current.members(@name) end |