Persist posts in Voyage
This commit is contained in:
@@ -4,9 +4,6 @@ Class {
|
||||
#instVars : [
|
||||
'posts'
|
||||
],
|
||||
#classInstVars : [
|
||||
'uniqueInstance'
|
||||
],
|
||||
#category : #TinyBlog
|
||||
}
|
||||
|
||||
@@ -35,7 +32,9 @@ TBBlog class >> createDemoPosts [
|
||||
{ #category : #initialization }
|
||||
TBBlog class >> current [
|
||||
"answer the instance of the TBRepository"
|
||||
^ uniqueInstance ifNil: [ uniqueInstance := self new ]
|
||||
^ self selectAll
|
||||
ifNotEmpty: [ :x | x anyOne ]
|
||||
ifEmpty: [ self new save ]
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
@@ -43,9 +42,20 @@ TBBlog class >> initialize [
|
||||
self reset
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
TBBlog class >> initializeVoyageOnMemoryDB [
|
||||
VOMemoryRepository new enableSingleton
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
TBBlog class >> isVoyageRoot [
|
||||
"Indicates that instances of this class are top level documents in noSQL databases"
|
||||
^ true
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
TBBlog class >> reset [
|
||||
uniqueInstance := nil
|
||||
self initializeVoyageOnMemoryDB.
|
||||
]
|
||||
|
||||
{ #category : #reading }
|
||||
@@ -81,7 +91,8 @@ TBBlog >> initialize [
|
||||
|
||||
{ #category : #deleting }
|
||||
TBBlog >> removeAllPosts [
|
||||
posts := OrderedCollection new
|
||||
posts := OrderedCollection new.
|
||||
self save
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
@@ -91,6 +102,7 @@ TBBlog >> size [
|
||||
|
||||
{ #category : #writing }
|
||||
TBBlog >> writeBlogPost: aPost [
|
||||
"Add the blog post to the list of posts."
|
||||
posts add: aPost
|
||||
"Add the blog post in database."
|
||||
self allBlogPosts add: aPost.
|
||||
self save
|
||||
]
|
||||
|
@@ -4,16 +4,17 @@ Class {
|
||||
#instVars : [
|
||||
'blog',
|
||||
'post',
|
||||
'first'
|
||||
'first',
|
||||
'previousRepository'
|
||||
],
|
||||
#category : #'TinyBlog-Tests'
|
||||
}
|
||||
|
||||
{ #category : #running }
|
||||
TBBlogTest >> setUp [
|
||||
previousRepository := VORepository current.
|
||||
VORepository setRepository: VOMemoryRepository new.
|
||||
blog := TBBlog current.
|
||||
blog removeAllPosts.
|
||||
|
||||
first := TBPost title: 'A title' text: 'A text' category: 'First Category'.
|
||||
blog writeBlogPost: first.
|
||||
|
||||
@@ -22,7 +23,7 @@ TBBlogTest >> setUp [
|
||||
|
||||
{ #category : #running }
|
||||
TBBlogTest >> tearDown [
|
||||
TBBlog reset
|
||||
VORepository setRepository: previousRepository
|
||||
]
|
||||
|
||||
{ #category : #tests }
|
||||
|
Reference in New Issue
Block a user