Class: EPO::DB::StoreResourceAction

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#extObject

Returns the value of attribute ext

Returns:

  • (Object)

    the current value of ext



202
203
204
# File 'lib/epo/core/db.rb', line 202

def ext
  @ext
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



202
203
204
# File 'lib/epo/core/db.rb', line 202

def path
  @path
end

#perspObject

Returns the value of attribute persp

Returns:

  • (Object)

    the current value of persp



202
203
204
# File 'lib/epo/core/db.rb', line 202

def persp
  @persp
end

#resourceObject

Returns the value of attribute resource

Returns:

  • (Object)

    the current value of resource



202
203
204
# File 'lib/epo/core/db.rb', line 202

def resource
  @resource
end

Instance Method Details

#performObject



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