Class: Ant::Server::Nanoservice::Datasource::JSONRepository
- Inherits:
-
Repository
- Object
- Repository
- Ant::Server::Nanoservice::Datasource::JSONRepository
show all
- Defined in:
- lib/ant/server/nanoservice/datasource/json_repository.rb
Instance Method Summary
collapse
Methods inherited from Repository
#create, #create_initial_object, #exist?
Constructor Details
#initialize(folder, id, id_generator) ⇒ JSONRepository
Returns a new instance of JSONRepository.
8
9
10
11
|
# File 'lib/ant/server/nanoservice/datasource/json_repository.rb', line 8
def initialize(folder, id, id_generator)
@path = folder
super(id, id_generator)
end
|
Instance Method Details
#create_(data) ⇒ Object
20
21
22
23
|
# File 'lib/ant/server/nanoservice/datasource/json_repository.rb', line 20
def create_(data)
store(data)
data
end
|
#get(id) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/ant/server/nanoservice/datasource/json_repository.rb', line 13
def get(id)
path = full_path(id)
raise(ObjectNotFound, id) unless File.file?(path)
contents = File.read(path)
JSON.parse(contents, symbolize_names: true)
end
|
#store(data) ⇒ Object
25
26
27
28
|
# File 'lib/ant/server/nanoservice/datasource/json_repository.rb', line 25
def store(data)
id = data[@id]
File.write(full_path(id), data.to_json)
end
|