Class: Urbit::Setting
- Inherits:
-
Object
- Object
- Urbit::Setting
- Defined in:
- lib/urbit/setting.rb
Instance Attribute Summary collapse
-
#buckets ⇒ Object
Returns the value of attribute buckets.
-
#desk ⇒ Object
readonly
Returns the value of attribute desk.
-
#ship ⇒ Object
readonly
Returns the value of attribute ship.
Instance Method Summary collapse
- #<=>(another_group) ⇒ Object
- #==(another_group) ⇒ Object
- #[](bucket:) ⇒ Object
- #add_bucket(name:, entries:) ⇒ Object
- #entries(bucket:) ⇒ Object
-
#initialize(ship:, desk:, buckets:) ⇒ Setting
constructor
A new instance of Setting.
- #remove_bucket(name:) ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(ship:, desk:, buckets:) ⇒ Setting
Returns a new instance of Setting.
10 11 12 13 14 15 |
# File 'lib/urbit/setting.rb', line 10 def initialize(ship:, desk:, buckets:) @ship = ship @desk = desk @buckets = Set.new buckets.each {|k, v| @buckets << Bucket.new(setting: self, name: k, entries: v)} end |
Instance Attribute Details
#buckets ⇒ Object
Returns the value of attribute buckets.
7 8 9 |
# File 'lib/urbit/setting.rb', line 7 def buckets @buckets end |
#desk ⇒ Object (readonly)
Returns the value of attribute desk.
8 9 10 |
# File 'lib/urbit/setting.rb', line 8 def desk @desk end |
#ship ⇒ Object (readonly)
Returns the value of attribute ship.
8 9 10 |
# File 'lib/urbit/setting.rb', line 8 def ship @ship end |
Instance Method Details
#<=>(another_group) ⇒ Object
21 22 23 |
# File 'lib/urbit/setting.rb', line 21 def <=>(another_group) self.desk <=> another_group.desk end |
#==(another_group) ⇒ Object
17 18 19 |
# File 'lib/urbit/setting.rb', line 17 def ==(another_group) another_setting.desk == self.desk end |
#[](bucket:) ⇒ Object
25 26 27 |
# File 'lib/urbit/setting.rb', line 25 def [](bucket:) self.buckets.select {|b| bucket == b.name}.first end |
#add_bucket(name:, entries:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/urbit/setting.rb', line 29 def add_bucket(name:, entries:) msg = { "put-bucket": { "bucket-key": "#{name}", "desk": "#{self.desk}", "bucket": entries } } self.ship.poke(app: 'settings-store', mark: 'settings-event', message: msg) nil end |
#entries(bucket:) ⇒ Object
41 42 43 |
# File 'lib/urbit/setting.rb', line 41 def entries(bucket:) self[bucket: bucket].entries end |
#remove_bucket(name:) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/urbit/setting.rb', line 45 def remove_bucket(name:) msg = { "del-bucket": { "bucket-key": "#{name}", "desk": "#{self.desk}" } } self.ship.poke(app: 'settings-store', mark: 'settings-event', message: msg) nil end |
#to_h ⇒ Object
56 57 58 59 60 61 |
# File 'lib/urbit/setting.rb', line 56 def to_h { desk: @desk, buckets: self.buckets, } end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/urbit/setting.rb', line 63 def to_s "a Setting(#{self.to_h})" end |
#to_string ⇒ Object
67 68 69 |
# File 'lib/urbit/setting.rb', line 67 def to_string "desk: #{self.desk}\n buckets: #{self.buckets.collect {|b| b.to_string}}" end |