Class: Cline::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Serializable::Dir
Defined in:
lib/cline/config.rb

Overview

Accesses all configuration of a Cline directory. Wraps for example the content of ~/.cline. The following properties can be used while opening a Config directory:

  • include_project_config [Boolean] Do we include the project-specific objects as well in this configuration? Defaults to true.

Instance Attribute Summary

Attributes included from Serializable::Dir

#create, #dir

Public API collapse

Internal collapse

Methods included from Serializable::Dir

included, #initialize_from_dir, #subpath

Constructor Details

#initialize(include_project_config: true) ⇒ Config

Constructor

Parameters:

  • include_project_config (Boolean) (defaults to: true)

    Do we include the project configuration in the objects read?



89
90
91
# File 'lib/cline/config.rb', line 89

def initialize(include_project_config: true)
  @include_project_config = include_project_config
end

Class Method Details

.globalConfig

Get the global Cline config

Returns:

  • (Config)

    The global config for the current user



25
26
27
# File 'lib/cline/config.rb', line 25

def self.global
  @global ||= Config.open("#{Utils::Os.user_home_dir}/.cline", include_project_config: false)
end

.mainConfig

Get the main Cline config. The main Cline config is the global config, enriched with also project-specific objects (skills...)

Returns:

  • (Config)

    The main config for the current user



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

def self.main
  @main ||= Config.open("#{Utils::Os.user_home_dir}/.cline", include_project_config: true)
end

.projectConfig

Get the project Cline config

Returns:

  • (Config)

    The project config for the current repository



32
33
34
# File 'lib/cline/config.rb', line 32

def self.project
  @project ||= Config.open('.cline')
end

Instance Method Details

#==(other) ⇒ Boolean

Equality check

Parameters:

  • other (Object)

    The other to check equality with

Returns:

  • (Boolean)

    True if objects are equal



64
65
66
67
68
# File 'lib/cline/config.rb', line 64

def ==(other)
  other.is_a?(Config) &&
    other.skills == skills &&
    other.data == data
end

#cli(**kwargs) ⇒ Cli

Return a Cli instance that uses this config

Parameters:

  • kwargs (Hash{Symbol => Object})

    Global options (see #Cli.COMMANDS)

Returns:

  • (Cli)

    Cli instance that is running using this config



74
75
76
# File 'lib/cline/config.rb', line 74

def cli(**kwargs)
  Cli.new(config: dir, **kwargs)
end

#data(create: self.create) ⇒ Data

Get the data directory from this config

Parameters:

  • create (Boolean) (defaults to: self.create)

    Should the data be created if it does not exist?

Returns:

  • (Data)

    The Cline data directory content



56
57
58
# File 'lib/cline/config.rb', line 56

def data(create: self.create)
  @data ||= Data.open(subpath('data'), create:)
end

#refresh!Object

Refresh caches to reload data from disk.



79
80
81
82
# File 'lib/cline/config.rb', line 79

def refresh!
  @skills = nil
  @data = nil
end

#skills(create: self.create) ⇒ OverlayHash?

Get skills from this config

Parameters:

  • create (Boolean) (defaults to: self.create)

    Should the data be created if it does not exist?

Returns:

  • (OverlayHash, nil)

    Set of skills, including global ones and project ones if needed, or nil if non existent (see Skills).



45
46
47
48
49
50
# File 'lib/cline/config.rb', line 45

def skills(create: self.create)
  @skills ||= begin
    skills_layers = ([Skills.open(subpath('skills'), create:)] + [project_config&.skills]).compact
    skills_layers.empty? ? nil : OverlayHash.new(*skills_layers)
  end
end