Module: Cline::Serializable::Dir

Included in:
Config, Data, Cline::Session, Cline::Skill, Task, Workspace
Defined in:
lib/cline/serializable/dir.rb

Overview

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

Provides:

  • .open(dir) -> [Object, nil] Provides a new instance initialized from the directory, or nil if no directory.
  • #dir -> [String] The directory from which this object was initialized.
  • #subpath(path) -> [String] Provide a sub-path from the directory the object was initialized from.

Defined Under Namespace

Modules: ClassMethods

Internal collapse

Internal collapse

Instance Attribute Details

#createBoolean (readonly)

Returns Should data be created if it does not exist?.

Returns:

  • (Boolean)

    Should data be created if it does not exist?



61
62
63
# File 'lib/cline/serializable/dir.rb', line 61

def create
  @create
end

#dirString (readonly)

Returns The directory used for the object's initialization.

Returns:

  • (String)

    The directory used for the object's initialization



58
59
60
# File 'lib/cline/serializable/dir.rb', line 58

def dir
  @dir
end

Class Method Details

.included(base) ⇒ Object

Hook used when this mixin is included in a base class

Parameters:

  • base (Class)

    The base class



53
54
55
# File 'lib/cline/serializable/dir.rb', line 53

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

Instance Method Details

#initialize_from_dir(dir, create:) ⇒ Object

Initialize this instance from a directory

Parameters:

  • dir (String)

    The directory to be used to initialize this instance

  • create (Boolean)

    Should data be created if it does not exist?



67
68
69
70
# File 'lib/cline/serializable/dir.rb', line 67

def initialize_from_dir(dir, create:)
  @dir = dir
  @create = create
end

#subpath(path) ⇒ String

Return the path to a sub-path of our instance directory

Parameters:

  • path (String)

    The relative sub-path

Returns:

  • (String)

    The full path to the sub-path



76
77
78
# File 'lib/cline/serializable/dir.rb', line 76

def subpath(path)
  ::File.join(dir, path)
end