...
This commit is contained in:
@@ -25,7 +25,7 @@ pub fn new(args ArgsGet) !&MeilisearchClient {
|
||||
name: args.name
|
||||
}
|
||||
set(obj)!
|
||||
return &obj
|
||||
return get(name: args.name)!
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&MeilisearchClient {
|
||||
@@ -36,7 +36,7 @@ pub fn get(args ArgsGet) !&MeilisearchClient {
|
||||
if r.hexists('context:meilisearch', args.name)! {
|
||||
data := r.hget('context:meilisearch', args.name)!
|
||||
if data.len == 0 {
|
||||
return error('meilisearch with name: meilisearch does not exist, prob bug.')
|
||||
return error('MeilisearchClient with name: meilisearch does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(MeilisearchClient, data)!
|
||||
set_in_mem(obj)!
|
||||
@@ -56,11 +56,11 @@ pub fn get(args ArgsGet) !&MeilisearchClient {
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o MeilisearchClient) ! {
|
||||
set_in_mem(o)!
|
||||
meilisearch_default = o.name
|
||||
mut o2 := set_in_mem(o)!
|
||||
meilisearch_default = o2.name
|
||||
mut context := base.context()!
|
||||
mut r := context.redis()!
|
||||
r.hset('context:meilisearch', o.name, json.encode(o))!
|
||||
r.hset('context:meilisearch', o2.name, json.encode(o2))!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
@@ -109,18 +109,17 @@ pub fn list(args ArgsList) ![]&MeilisearchClient {
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o MeilisearchClient) ! {
|
||||
fn set_in_mem(o MeilisearchClient) !MeilisearchClient {
|
||||
mut o2 := obj_init(o)!
|
||||
meilisearch_global[o.name] = &o2
|
||||
meilisearch_default = o.name
|
||||
}
|
||||
|
||||
// switch instance to be used for meilisearch
|
||||
pub fn switch(name string) {
|
||||
meilisearch_default = name
|
||||
meilisearch_global[o2.name] = &o2
|
||||
meilisearch_default = o2.name
|
||||
return o2
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
if !plbook.exists(filter: 'meilisearch.') {
|
||||
return
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'meilisearch.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
@@ -130,3 +129,8 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for meilisearch
|
||||
pub fn switch(name string) {
|
||||
meilisearch_default = name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user