Class: StatusPageRuby::Repositories::Status
- Inherits:
-
Object
- Object
- StatusPageRuby::Repositories::Status
- Defined in:
- lib/status_page_ruby/repositories/status.rb
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #all ⇒ Object
- #create(status) ⇒ Object
- #create_batch(statuses) ⇒ Object
- #exist?(status) ⇒ Boolean
-
#initialize(storage) ⇒ Status
constructor
A new instance of Status.
- #where(service:) ⇒ Object
Constructor Details
#initialize(storage) ⇒ Status
Returns a new instance of Status.
6 7 8 |
# File 'lib/status_page_ruby/repositories/status.rb', line 6 def initialize(storage) @storage = storage end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
4 5 6 |
# File 'lib/status_page_ruby/repositories/status.rb', line 4 def storage @storage end |
Instance Method Details
#all ⇒ Object
21 22 23 24 25 |
# File 'lib/status_page_ruby/repositories/status.rb', line 21 def all storage .read .map { |attrs| StatusPageRuby::Status.new(*attrs) } end |
#create(status) ⇒ Object
27 28 29 30 31 |
# File 'lib/status_page_ruby/repositories/status.rb', line 27 def create(status) return if exist?(status) storage.write(status.record) end |
#create_batch(statuses) ⇒ Object
33 34 35 36 37 |
# File 'lib/status_page_ruby/repositories/status.rb', line 33 def create_batch(statuses) return if statuses.empty? storage.merge(statuses.map(&:record)) end |
#exist?(status) ⇒ Boolean
10 11 12 |
# File 'lib/status_page_ruby/repositories/status.rb', line 10 def exist?(status) storage.include?(status.record) end |
#where(service:) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/status_page_ruby/repositories/status.rb', line 14 def where(service:) storage .read .select { |record| record.first == service } .map { |attrs| StatusPageRuby::Status.new(*attrs) } end |