Class: Utils::ConfigFile
- Includes:
- DSLKit::Interpreter
- Defined in:
- lib/utils/config_file.rb
Overview
Configuration file manager for Utils library.
This class provides functionality for loading, parsing, and managing configuration settings from multiple sources. It supports DSL-style configuration blocks and integrates with various utility components to provide centralized configuration management.
Defined Under Namespace
Classes: BlockConfig, Classify, CodeComment, CodeIndexer, ConfigFileError, Discover, Edit, FileFinder, Probe, Search, SshTunnel, StripSpaces, SyncDir
Class Attribute Summary collapse
-
.config_file_paths ⇒ Array<String>
The config_file_paths accessor method provides read and write access to the config_file_paths instance variable.
Instance Method Summary collapse
-
#classify(&block) ⇒ Classify
The classify method initializes and returns a Classify object.
-
#code_comment(&block) ⇒ Utils::ConfigFile::CodeComment
The code_comment method provides access to a CodeComment configuration instance.
-
#code_indexer(&block) ⇒ Utils::ConfigFile::CodeIndexer
The code_indexer method manages and returns a CodeIndexer configuration instance.
-
#configure_from_paths(paths = self.class.config_file_paths) ⇒ Object
The configure_from_paths method initializes the configuration by parsing configuration files from the specified paths.
-
#discover(&block) ⇒ Utils::Discover
The discover method initializes and returns a Discover object.
-
#edit(&block) ⇒ Edit
The edit method initializes and returns an Edit object.
-
#initialize ⇒ ConfigFile
constructor
The initialize method sets up a new instance of the class.
-
#parse(source) ⇒ Object
The parse method processes the provided source code by interpreting it within the given binding context.
-
#parse_config_file(config_file_path) ⇒ Utils::ConfigFile
The parse_config_file method reads and processes a configuration file.
-
#probe(&block) ⇒ Utils::Probe
The probe method initializes and returns a Probe object.
-
#search(&block) ⇒ Utils::Search
The search method initializes and returns a Search object.
-
#ssh_tunnel(&block) ⇒ Utils::ConfigFile::SshTunnel
The ssh_tunnel method provides access to an SSH tunnel configuration instance.
-
#strip_spaces(&block) ⇒ Utils::StripSpaces
The strip_spaces method configures and returns a StripSpaces object for processing whitespace.
-
#sync_dir(&block) ⇒ SyncDir
The sync_dir method provides access to a SyncDir instance.
-
#to_ruby ⇒ String
The to_ruby method generates a Ruby configuration string by collecting configuration data from various components and combining them into a single formatted output.
Constructor Details
#initialize ⇒ ConfigFile
The initialize method sets up a new instance of the class.
This method is called when creating a new object and performs any necessary initialization tasks for the instance variables and internal state.
38 39 |
# File 'lib/utils/config_file.rb', line 38 def initialize end |
Class Attribute Details
.config_file_paths ⇒ Array<String>
The config_file_paths accessor method provides read and write access to the config_file_paths instance variable.
16 17 18 |
# File 'lib/utils/config_file.rb', line 16 def config_file_paths @config_file_paths end |
Instance Method Details
#classify(&block) ⇒ Classify
The classify method initializes and returns a Classify object.
This method creates a Classify instance either from the provided block or with default settings if no block is given. It ensures that only one Classify object is created per instance by storing it in an instance variable.
800 801 802 803 804 805 |
# File 'lib/utils/config_file.rb', line 800 def classify(&block) if block @classify = Classify.new(&block) end @classify ||= Classify.new end |
#code_comment(&block) ⇒ Utils::ConfigFile::CodeComment
The code_comment method provides access to a CodeComment configuration instance.
This method returns the existing CodeComment instance if one has already been created, or initializes and returns a new CodeComment instance if no instance exists. If a block is provided, it will be passed to the CodeComment constructor when creating a new instance.
876 877 878 879 880 881 |
# File 'lib/utils/config_file.rb', line 876 def code_comment(&block) if block @code_comment = CodeComment.new(&block) end @code_comment ||= CodeComment.new end |
#code_indexer(&block) ⇒ Utils::ConfigFile::CodeIndexer
The code_indexer method manages and returns a CodeIndexer configuration instance.
This method provides access to a CodeIndexer object that handles configuration for generating code indexes such as ctags and cscope files. It ensures that only one CodeIndexer instance is created per object by storing it in an instance variable. When a block is provided, it initializes the CodeIndexer with custom settings; otherwise, it returns a default CodeIndexer instance.
478 479 480 481 482 483 |
# File 'lib/utils/config_file.rb', line 478 def code_indexer(&block) if block @code_indexer = CodeIndexer.new(&block) end @code_indexer ||= CodeIndexer.new end |
#configure_from_paths(paths = self.class.config_file_paths) ⇒ Object
The configure_from_paths method initializes the configuration by parsing configuration files from the specified paths.
This method iterates through an array of configuration file paths and processes each one to load the configuration settings. It is typically used to set up the application’s configuration from multiple sources.
49 50 51 52 53 |
# File 'lib/utils/config_file.rb', line 49 def configure_from_paths(paths = self.class.config_file_paths) for config_file_path in paths parse_config_file config_file_path end end |
#discover(&block) ⇒ Utils::Discover
The discover method initializes and returns a Discover object.
This method sets up a Discover instance, either using a provided block for configuration or creating a default instance. It ensures that only one Discover object is created per instance by storing it in an instance variable.
provided block or with default settings
427 428 429 430 431 432 |
# File 'lib/utils/config_file.rb', line 427 def discover(&block) if block @discover = Discover.new(&block) end @discover ||= Discover.new end |
#edit(&block) ⇒ Edit
The edit method initializes and returns an Edit object.
This method creates an Edit instance either from a provided block or with default settings. It stores the Edit object as an instance variable and returns it on subsequent calls.
757 758 759 760 761 762 |
# File 'lib/utils/config_file.rb', line 757 def edit(&block) if block @edit = Edit.new(&block) end @edit ||= Edit.new end |
#parse(source) ⇒ Object
The parse method processes the provided source code by interpreting it within the given binding context.
This method takes a source code string and evaluates it in the context of the specified binding, allowing for dynamic execution of code with access to the current variable scope.
91 92 93 94 |
# File 'lib/utils/config_file.rb', line 91 def parse(source) interpret_with_binding source, binding self end |
#parse_config_file(config_file_path) ⇒ Utils::ConfigFile
The method will output a warning message to standard error if it fails to read the configuration file and return nil.
The parse_config_file method reads and processes a configuration file.
This method opens the specified configuration file, reads its contents, and parses the configuration data. It handles file path expansion and includes error handling for system call errors during file operations.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/utils/config_file.rb', line 69 def parse_config_file(config_file_path) config_file_path = File.(config_file_path) File.open(config_file_path) do |cf| parse cf.read end self rescue SystemCallError => e $DEBUG and warn "Couldn't read config file "\ "#{config_file_path.inspect}: #{e.class} #{e}" return nil end |
#probe(&block) ⇒ Utils::Probe
The probe method initializes and returns a Probe object.
This method creates a new Probe instance either from the provided block or with default settings, storing it for later use. It ensures that only one Probe instance is created per object, returning the existing instance on subsequent calls.
267 268 269 270 271 272 |
# File 'lib/utils/config_file.rb', line 267 def probe(&block) if block @probe = Probe.new(&block) end @probe ||= Probe.new end |
#search(&block) ⇒ Utils::Search
The search method initializes and returns a Search object.
This method creates a Search instance either from a provided block or with default settings. It maintains a cached instance of the Search object, returning the same instance on subsequent calls.
block or with default settings
359 360 361 362 363 364 |
# File 'lib/utils/config_file.rb', line 359 def search(&block) if block @search = Search.new(&block) end @search ||= Search.new end |
#ssh_tunnel(&block) ⇒ Utils::ConfigFile::SshTunnel
The ssh_tunnel method provides access to an SSH tunnel configuration instance.
This method returns the existing SSH tunnel configuration object if one has already been created, or initializes and returns a new SSH tunnel configuration instance if no instance exists. If a block is provided, it will be passed to the SSH tunnel configuration constructor when creating a new instance.
722 723 724 725 726 727 |
# File 'lib/utils/config_file.rb', line 722 def ssh_tunnel(&block) if block @ssh_tunnel = SshTunnel.new(&block) end @ssh_tunnel ||= SshTunnel.new end |
#strip_spaces(&block) ⇒ Utils::StripSpaces
The strip_spaces method configures and returns a StripSpaces object for processing whitespace.
This method initializes a StripSpaces processor that can be used to remove or modify whitespace in strings. When a block is provided, it sets up the processor with custom behavior defined by the block. Otherwise, it returns a default StripSpaces instance.
528 529 530 531 532 533 |
# File 'lib/utils/config_file.rb', line 528 def strip_spaces(&block) if block @strip_spaces = StripSpaces.new(&block) end @strip_spaces ||= StripSpaces.new end |
#sync_dir(&block) ⇒ SyncDir
The sync_dir method provides access to a SyncDir instance.
This method returns the existing SyncDir instance if one has already been created, or initializes and returns a new SyncDir instance if no instance exists. If a block is provided, it will be passed to the SyncDir constructor when creating a new instance.
849 850 851 852 853 854 |
# File 'lib/utils/config_file.rb', line 849 def sync_dir(&block) if block @sync_dir = SyncDir.new(&block) end @sync_dir ||= SyncDir.new end |
#to_ruby ⇒ String
The to_ruby method generates a Ruby configuration string by collecting configuration data from various components and combining them into a single formatted output.
890 891 892 893 894 895 896 |
# File 'lib/utils/config_file.rb', line 890 def to_ruby result = "# vim: set ft=ruby:\n" for bc in %w[search discover strip_spaces probe ssh_tunnel edit classify] result << "\n" << __send__(bc).to_ruby end result end |