Class: Cline::FileContent

Inherits:
Object
  • Object
show all
Includes:
Serializable::File
Defined in:
lib/cline/file_content.rb

Overview

Store a file's content, either from an existing file or just in memory for later persistence.

Instance Attribute Summary

Attributes included from Serializable::File

#file

Public API collapse

Methods included from Serializable::File

included, #initialize_from_file

Constructor Details

#initialize(content = nil) ⇒ FileContent

Constructor

Parameters:

  • content (String, nil) (defaults to: nil)

    Content, or nil if the content is taken from a real file



29
30
31
# File 'lib/cline/file_content.rb', line 29

def initialize(content = nil)
  @content = content
end

Instance Method Details

#==(other) ⇒ Boolean

Equality check

Parameters:

  • other (Object)

    The other to check equality with

Returns:

  • (Boolean)

    True if objects are equal



17
18
19
20
# File 'lib/cline/file_content.rb', line 17

def ==(other)
  other.is_a?(FileContent) &&
    other.content == content
end

#contentString

Retrieve the file's content

Returns:

  • (String)

    The file's content



9
10
11
# File 'lib/cline/file_content.rb', line 9

def content
  @content ||= File.read(file)
end