Class: EPO::DB::StoreResourceAction
- Inherits:
-
Struct
- Object
- Struct
- EPO::DB::StoreResourceAction
- Defined in:
- lib/epo/core/db.rb
Overview
An action to serialize and store a resource seen in a given perspective into a file at path, under the format with a format given by its extension name.
Instance Attribute Summary collapse
-
#ext ⇒ Object
Returns the value of attribute ext.
-
#path ⇒ Object
Returns the value of attribute path.
-
#persp ⇒ Object
Returns the value of attribute persp.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
- #perform ⇒ Object
- #store_data_at_path(data, path, enum = :each, mode = 'w') ⇒ Object
- #write_data_to_io(data, io, enum = :each) ⇒ Object
Instance Attribute Details
#ext ⇒ Object
Returns the value of attribute ext
202 203 204 |
# File 'lib/epo/core/db.rb', line 202 def ext @ext end |
#path ⇒ Object
Returns the value of attribute path
202 203 204 |
# File 'lib/epo/core/db.rb', line 202 def path @path end |
#persp ⇒ Object
Returns the value of attribute persp
202 203 204 |
# File 'lib/epo/core/db.rb', line 202 def persp @persp end |
#resource ⇒ Object
Returns the value of attribute resource
202 203 204 |
# File 'lib/epo/core/db.rb', line 202 def resource @resource end |
Instance Method Details
#perform ⇒ Object
203 204 205 206 |
# File 'lib/epo/core/db.rb', line 203 def perform data = resource.to_ext(ext.to_s, persp) store_data_at_path(data, path) end |
#store_data_at_path(data, path, enum = :each, mode = 'w') ⇒ Object
208 209 210 211 212 |
# File 'lib/epo/core/db.rb', line 208 def store_data_at_path(data, path, enum=:each, mode='w') File.open(path, mode) do |f| write_data_to_io(data, f, enum) end end |
#write_data_to_io(data, io, enum = :each) ⇒ Object
214 215 216 217 218 219 220 221 222 |
# File 'lib/epo/core/db.rb', line 214 def write_data_to_io(data, io, enum=:each) if data.respond_to?(enum) data.each do |buf| io << buf end else io << data end end |