Class: RailsAgents::GeneratedFile

Inherits:
Data
  • Object
show all
Defined in:
lib/rails_agents/generated_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type

Returns:

  • (Object)

    the current value of content_type



4
5
6
# File 'lib/rails_agents/generated_file.rb', line 4

def content_type
  @content_type
end

#dataObject (readonly)

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



4
5
6
# File 'lib/rails_agents/generated_file.rb', line 4

def data
  @data
end

#file_idObject (readonly)

Returns the value of attribute file_id

Returns:

  • (Object)

    the current value of file_id



4
5
6
# File 'lib/rails_agents/generated_file.rb', line 4

def file_id
  @file_id
end

#filenameObject (readonly)

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



4
5
6
# File 'lib/rails_agents/generated_file.rb', line 4

def filename
  @filename
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/rails_agents/generated_file.rb', line 4

def path
  @path
end

Instance Method Details

#save(directory) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/rails_agents/generated_file.rb', line 5

def save(directory)
  dir = File.expand_path(directory)
  FileUtils.mkdir_p(dir)
  destination = File.join(dir, filename)
  File.binwrite(destination, data)
  self.class.new(file_id:, filename:, content_type:, data:, path: destination)
end

#sizeObject



13
# File 'lib/rails_agents/generated_file.rb', line 13

def size = data.bytesize