Class: Urbit::Groups
- Inherits:
-
Set
- Object
- Set
- Urbit::Groups
- Defined in:
- lib/urbit/groups.rb
Instance Attribute Summary collapse
-
#ship ⇒ Object
Returns the value of attribute ship.
Instance Method Summary collapse
- #[](path: nil, title: nil) ⇒ Object
-
#add(a_group) ⇒ Object
Adds a Group to this Manager’s groups collection.
- #add_members(group_path:, ships:) ⇒ Object
- #add_tag(group_path:, ships:, tag:) ⇒ Object
- #create(name:, title:, description:) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(ship:) ⇒ Groups
constructor
A new instance of Groups.
- #join(host:, name:, share_contact: false, auto_join: false) ⇒ Object
- #list ⇒ Object
- #load ⇒ Object
- #remove(group) ⇒ Object
- #remove_members(group_path:, ships:) ⇒ Object
- #remove_tag(group_path:, ships:, tag:) ⇒ Object
- #spider(thread, data) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ship:) ⇒ Groups
Returns a new instance of Groups.
7 8 9 10 |
# File 'lib/urbit/groups.rb', line 7 def initialize(ship:) @ship = ship @hash = {} end |
Instance Attribute Details
#ship ⇒ Object
Returns the value of attribute ship.
5 6 7 |
# File 'lib/urbit/groups.rb', line 5 def ship @ship end |
Instance Method Details
#[](path: nil, title: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/urbit/groups.rb', line 12 def [](path: nil, title: nil) if title.nil? if (g = self.select {|g| g.path == path}.first) g.manager = self return g end else if (g = self.select {|g| g.title == title}.first) g.manager = self return g end end nil end |
#add(a_group) ⇒ Object
Adds a Group to this Manager’s groups collection
30 31 32 33 |
# File 'lib/urbit/groups.rb', line 30 def add(a_group) a_group.manager = self self << a_group end |
#add_members(group_path:, ships:) ⇒ Object
35 36 37 38 39 |
# File 'lib/urbit/groups.rb', line 35 def add_members(group_path:, ships:) if (group = self[path: group_path]) group.members += ships end end |
#add_tag(group_path:, ships:, tag:) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/urbit/groups.rb', line 41 def add_tag(group_path:, ships:, tag:) if (group = self[path: group_path]) if (group..include? tag) group.[tag] += ships end end end |
#create(name:, title:, description:) ⇒ Object
49 50 51 |
# File 'lib/urbit/groups.rb', line 49 def create(name:, title:, description:) self.spider('group-create', %Q({"create": {"name": "#{name}", "title": "#{title}", "description": "#{description}", "policy": {"open": {"banRanks": [], "banned": []}}}})) end |
#empty? ⇒ Boolean
53 54 55 |
# File 'lib/urbit/groups.rb', line 53 def empty? self.empty? end |
#join(host:, name:, share_contact: false, auto_join: false) ⇒ Object
57 58 59 60 61 |
# File 'lib/urbit/groups.rb', line 57 def join(host:, name:, share_contact: false, auto_join: false) data = {join: {resource: {ship: "#{host}", name: "#{name}"}, ship: "#{host}", shareContact: share_contact, app: "groups", autojoin: auto_join}} self.ship.poke(app: 'group-view', mark: 'group-view-action', message: data) nil end |
#list ⇒ Object
63 64 65 |
# File 'lib/urbit/groups.rb', line 63 def list self.map {|g| g.to_list}.join("\n") end |
#load ⇒ Object
85 86 87 88 89 90 |
# File 'lib/urbit/groups.rb', line 85 def load if self.ship.logged_in? self.ship.subscribe(app: 'group-store', path: '/groups') end nil end |
#remove(group) ⇒ Object
67 68 69 |
# File 'lib/urbit/groups.rb', line 67 def remove(group) self.delete(group) end |
#remove_members(group_path:, ships:) ⇒ Object
71 72 73 74 75 |
# File 'lib/urbit/groups.rb', line 71 def remove_members(group_path:, ships:) if (group = self[path: group_path]) group.members -= ships end end |
#remove_tag(group_path:, ships:, tag:) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/urbit/groups.rb', line 77 def remove_tag(group_path:, ships:, tag:) if (group = self[path: group_path]) if (group..include? tag) group.[tag] -= ships end end end |
#spider(thread, data) ⇒ Object
92 93 94 |
# File 'lib/urbit/groups.rb', line 92 def spider(thread, data) self.ship.spider(mark_in: 'group-view-action', mark_out: 'json', thread: thread, data: data) end |
#to_s ⇒ Object
96 97 98 |
# File 'lib/urbit/groups.rb', line 96 def to_s self.sort.each {|g| puts g} end |