Class: Urbit::Group
- Inherits:
-
Object
- Object
- Urbit::Group
- Defined in:
- lib/urbit/group.rb
Instance Attribute Summary collapse
-
#graphs ⇒ Object
Returns the value of attribute graphs.
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#manager ⇒ Object
Returns the value of attribute manager.
-
#members ⇒ Object
Returns the value of attribute members.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #<=>(another_group) ⇒ Object
- #==(another_group) ⇒ Object
- #creator ⇒ Object
-
#delete ⇒ Object
This is the action labeled as “Archive” in the Landscape UI.
- #description ⇒ Object
- #eql?(another_group) ⇒ Boolean
- #host ⇒ Object
-
#initialize(path:, members:, policy:, tags:, hidden:) ⇒ Group
constructor
A new instance of Group.
- #invite(ship_names:, message:) ⇒ Object
- #key ⇒ Object
- #leave ⇒ Object
- #path_tokens ⇒ Object
- #pending_invites ⇒ Object
- #picture ⇒ Object
- #to_h ⇒ Object
- #to_list ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path:, members:, policy:, tags:, hidden:) ⇒ Group
Returns a new instance of Group.
8 9 10 11 12 13 14 15 16 |
# File 'lib/urbit/group.rb', line 8 def initialize(path:, members:, policy:, tags:, hidden:) @graphs = Set.new @hidden = hidden @manager = nil @members = Set.new(members) @path = path @policy = policy @tags = self.() end |
Instance Attribute Details
#graphs ⇒ Object
Returns the value of attribute graphs.
5 6 7 |
# File 'lib/urbit/group.rb', line 5 def graphs @graphs end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
6 7 8 |
# File 'lib/urbit/group.rb', line 6 def hidden @hidden end |
#manager ⇒ Object
Returns the value of attribute manager.
5 6 7 |
# File 'lib/urbit/group.rb', line 5 def manager @manager end |
#members ⇒ Object
Returns the value of attribute members.
5 6 7 |
# File 'lib/urbit/group.rb', line 5 def members @members end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/urbit/group.rb', line 6 def path @path end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
6 7 8 |
# File 'lib/urbit/group.rb', line 6 def policy @policy end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/urbit/group.rb', line 5 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/urbit/group.rb', line 5 def title @title end |
Instance Method Details
#<=>(another_group) ⇒ Object
22 23 24 |
# File 'lib/urbit/group.rb', line 22 def <=>(another_group) self.path <=> another_group.path end |
#==(another_group) ⇒ Object
18 19 20 |
# File 'lib/urbit/group.rb', line 18 def ==(another_group) another_group.path == self.path end |
#creator ⇒ Object
26 27 28 29 |
# File 'lib/urbit/group.rb', line 26 def creator self.fetch_link if @creator.nil? @creator end |
#delete ⇒ Object
This is the action labeled as “Archive” in the Landscape UI. As of now, you can only do this to groups on your own ship.
40 41 42 43 44 45 46 47 |
# File 'lib/urbit/group.rb', line 40 def delete if (self.host == self.manager.ship.name) spdr = self.manager.spider('group-delete', %Q({"remove": {"ship": "#{self.host}", "name": "#{self.key}"}})) self.manager.remove(self) if 200 == spdr[:status] return spdr end {status: 400, code: 'bad_request', body: 'Can only delete Groups on your own ship.'} end |
#description ⇒ Object
31 32 33 34 |
# File 'lib/urbit/group.rb', line 31 def description self.fetch_link if @description.nil? @description end |
#eql?(another_group) ⇒ Boolean
49 50 51 |
# File 'lib/urbit/group.rb', line 49 def eql?(another_group) another_group.path == self.path end |
#host ⇒ Object
60 61 62 |
# File 'lib/urbit/group.rb', line 60 def host self.path_tokens[0] end |
#invite(ship_names:, message:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/urbit/group.rb', line 64 def invite(ship_names:, message:) data = %Q({ "invite": { "resource": { "ship": "#{self.host}", "name": "#{self.key}" }, "ships": [ "#{ship_names.join(',')}" ], "description": "#{}" } }) self.manager.spider('group-invite', data) end |
#key ⇒ Object
80 81 82 |
# File 'lib/urbit/group.rb', line 80 def key self.path_tokens[1] end |
#leave ⇒ Object
84 85 86 87 88 |
# File 'lib/urbit/group.rb', line 84 def leave spdr = self.manager.spider('group-leave', %Q({"leave": {"ship": "#{self.host}", "name": "#{self.key}"}})) self.manager.remove(self) if 200 == spdr[:status] spdr end |
#path_tokens ⇒ Object
90 91 92 |
# File 'lib/urbit/group.rb', line 90 def path_tokens self.path.split('/') end |
#pending_invites ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/urbit/group.rb', line 94 def pending_invites if (i = @policy["invite"]) if (p = i["pending"]) return p.count end end '?' end |
#picture ⇒ Object
103 104 105 106 |
# File 'lib/urbit/group.rb', line 103 def picture self.fetch_link if @picture.nil? @picture end |
#to_h ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/urbit/group.rb', line 113 def to_h { title: self.title, description: self.description, host: self.host, key: self.key, member_count: self.members.count, pending_invites: self.pending_invites, hidden: self.hidden } end |
#to_list ⇒ Object
125 126 127 |
# File 'lib/urbit/group.rb', line 125 def to_list self.title || "Untitled - #{self.path}" end |
#to_s ⇒ Object
129 130 131 |
# File 'lib/urbit/group.rb', line 129 def to_s "a Group(#{self.to_h})" end |