Class: Urbit::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/urbit/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting:, name:, entries:) ⇒ Bucket

Returns a new instance of Bucket.



6
7
8
9
10
# File 'lib/urbit/bucket.rb', line 6

def initialize(setting:, name:, entries:)
  @setting = setting
  @name = name
  @entries = Hash.new.replace(entries)
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



4
5
6
# File 'lib/urbit/bucket.rb', line 4

def entries
  @entries
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/urbit/bucket.rb', line 4

def name
  @name
end

#settingObject

Returns the value of attribute setting.



4
5
6
# File 'lib/urbit/bucket.rb', line 4

def setting
  @setting
end

Instance Method Details

#[](key:) ⇒ Object



12
13
14
# File 'lib/urbit/bucket.rb', line 12

def [](key:)
  self.entries[key]
end

#[]=(key, val) ⇒ Object



16
17
18
19
20
# File 'lib/urbit/bucket.rb', line 16

def []=(key, val)
  msg = {"put-entry": {"desk": "#{@setting.desk}", "bucket-key": "#{self.name}", "entry-key": "#{key[:key]}", "value": val}}
  self.ship.poke(app: 'settings-store', mark: 'settings-event', message: msg)
  nil
end

#remove_entry(key:) ⇒ Object



22
23
24
25
26
# File 'lib/urbit/bucket.rb', line 22

def remove_entry(key:)
  msg = {"del-entry": {"desk": "#{@setting.desk}", "bucket-key": "#{self.name}", "entry-key": "#{key}"}}
  self.ship.poke(app: 'settings-store', mark: 'settings-event', message: msg)
  nil
end

#shipObject



28
29
30
# File 'lib/urbit/bucket.rb', line 28

def ship
  self.setting.ship
end

#to_hObject



32
33
34
# File 'lib/urbit/bucket.rb', line 32

def to_h
  {name: @name, entries: @entries}
end

#to_sObject



36
37
38
# File 'lib/urbit/bucket.rb', line 36

def to_s
  "a Bucket(#{self.to_h})"
end

#to_stringObject



40
41
42
# File 'lib/urbit/bucket.rb', line 40

def to_string
  "#{self.name}: #{self.entries.count} entries"
end