Module: Cline::Serializable::File

Included in:
FileContent, Logs
Defined in:
lib/cline/serializable/file.rb

Overview

Add features to initialize from and save an object to a file.

Provides:

  • .open(file) -> [Object, nil] Provides a new instance initialized from the file, or nil if no file.
  • .monitor_file_changes(file, on_change) Provides a monitor to be notified on file changes.
  • .monitor_updates(file, on_change) Provides a monitor to be notified on new instances upon updates.
  • #file -> [String] The file from which this object was initialized.

Defined Under Namespace

Modules: ClassMethods

Internal collapse

Internal collapse

Instance Attribute Details

#fileString (readonly)

Returns The file used for the object's initialization.

Returns:

  • (String)

    The file used for the object's initialization



96
97
98
# File 'lib/cline/serializable/file.rb', line 96

def file
  @file
end

Class Method Details

.included(base) ⇒ Object

Hook used when this mixin is included in a base class

Parameters:

  • base (Class)

    The base class



91
92
93
# File 'lib/cline/serializable/file.rb', line 91

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize_from_file(file) ⇒ Object

Initialize this instance from a file

Parameters:

  • file (String)

    The file to be used to initialize this instance



101
102
103
# File 'lib/cline/serializable/file.rb', line 101

def initialize_from_file(file)
  @file = file
end