Class: Urbit::Settings

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



23
24
25
# File 'lib/urbit/settings.rb', line 23

def initialize
  @hash    = {}
end

Class Method Details

.load(ship:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/urbit/settings.rb', line 8

def load(ship:)
  ship.subscribe(app: 'settings-store', path: '/all')
  scry = ship.scry(app: "settings-store", path: "/all", mark: "json")
  # scry = self.scry(app: "settings-store", path: "/desk/#{desk}", mark: "json")
  s = Settings.new
  if scry[:body]
    body = JSON.parse scry[:body]
    body["all"].each do |k, v|  # At this level the keys are the desks and the values are the buckets
      s << Setting.new(ship: ship, desk: k, buckets: v)
    end
  end
  s
end

Instance Method Details

#[](desk:) ⇒ Object



27
28
29
# File 'lib/urbit/settings.rb', line 27

def [](desk:)
  self.select {|s| desk == s.desk}.first
end

#listObject



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

def list
  self.each {|s| puts s.to_string}
  nil
end