Class: FileMarshal::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/file_marshal/writer.rb,
lib/file_marshal/writer/file.rb,
lib/file_marshal/writer/temp.rb

Direct Known Subclasses

File, Temp

Defined Under Namespace

Classes: File, Temp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Writer

Returns a new instance of Writer.



5
6
7
# File 'lib/file_marshal/writer.rb', line 5

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/file_marshal/writer.rb', line 3

def attributes
  @attributes
end

#fileObject (readonly)

Returns the value of attribute file.

Raises:

  • (NotImplementedError)


3
4
5
# File 'lib/file_marshal/writer.rb', line 3

def file
  @file
end

Instance Method Details

#buildObject



12
13
14
15
16
# File 'lib/file_marshal/writer.rb', line 12

def build
  write
  set_time
  prepare
end

#prepareObject



31
32
33
34
# File 'lib/file_marshal/writer.rb', line 31

def prepare
  file.rewind
  file
end

#set_timeObject



27
28
29
# File 'lib/file_marshal/writer.rb', line 27

def set_time
  ::File.utime(file.atime, Time.parse(updated_at), file.path)
end

#writeObject



22
23
24
25
# File 'lib/file_marshal/writer.rb', line 22

def write
  file.write(content)
  file
end