Class: Urbit::Bucket
- Inherits:
-
Object
- Object
- Urbit::Bucket
- Defined in:
- lib/urbit/bucket.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#name ⇒ Object
Returns the value of attribute name.
-
#setting ⇒ Object
Returns the value of attribute setting.
Instance Method Summary collapse
- #[](key:) ⇒ Object
- #[]=(key, val) ⇒ Object
-
#initialize(setting:, name:, entries:) ⇒ Bucket
constructor
A new instance of Bucket.
- #remove_entry(key:) ⇒ Object
- #ship ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #to_string ⇒ Object
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
#entries ⇒ Object
Returns the value of attribute entries.
4 5 6 |
# File 'lib/urbit/bucket.rb', line 4 def entries @entries end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/urbit/bucket.rb', line 4 def name @name end |
#setting ⇒ Object
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 |
#ship ⇒ Object
28 29 30 |
# File 'lib/urbit/bucket.rb', line 28 def ship self.setting.ship end |
#to_h ⇒ Object
32 33 34 |
# File 'lib/urbit/bucket.rb', line 32 def to_h {name: @name, entries: @entries} end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/urbit/bucket.rb', line 36 def to_s "a Bucket(#{self.to_h})" end |
#to_string ⇒ Object
40 41 42 |
# File 'lib/urbit/bucket.rb', line 40 def to_string "#{self.name}: #{self.entries.count} entries" end |