Class: TRuby::Config
- Inherits:
-
Object
- Object
- TRuby::Config
- Defined in:
- lib/t_ruby/config.rb
Constant Summary collapse
- VALID_STRICTNESS =
Valid strictness levels
%w[strict standard permissive].freeze
- DEFAULT_CONFIG =
New schema structure (v0.0.12+)
{ "source" => { "include" => ["src"], "exclude" => [], "extensions" => [".trb"], }, "output" => { "ruby_dir" => "build", "rbs_dir" => nil, "clean_before_build" => false, }, "compiler" => { "strictness" => "standard", "generate_rbs" => true, "target_ruby" => "3.0", "experimental" => [], "checks" => { "no_implicit_any" => false, "no_unused_vars" => false, "strict_nil" => false, }, }, "watch" => { "paths" => [], "debounce" => 100, "clear_screen" => false, "on_success" => nil, }, }.freeze
- LEGACY_KEYS =
Legacy keys for migration detection
%w[emit paths strict include exclude].freeze
- AUTO_EXCLUDE =
Always excluded (not configurable)
[".git"].freeze
Instance Attribute Summary collapse
-
#compiler ⇒ Object
readonly
Returns the value of attribute compiler.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#version_requirement ⇒ Object
readonly
Returns the value of attribute version_requirement.
-
#watch ⇒ Object
readonly
Returns the value of attribute watch.
Instance Method Summary collapse
-
#check_no_implicit_any? ⇒ Boolean
Check if no_implicit_any check is enabled.
-
#check_no_unused_vars? ⇒ Boolean
Check if no_unused_vars check is enabled.
-
#check_strict_nil? ⇒ Boolean
Check if strict_nil check is enabled.
-
#clean_before_build? ⇒ Boolean
Check if output directory should be cleaned before build.
-
#exclude_patterns ⇒ Object
Get exclude patterns.
-
#excluded?(file_path) ⇒ Boolean
Check if a file path should be excluded.
-
#experimental_enabled?(feature) ⇒ Boolean
Check if a specific experimental feature is enabled.
-
#experimental_features ⇒ Array<String>
Get list of enabled experimental features.
-
#find_source_files ⇒ Array<String>
Find all source files matching include patterns, excluding exclude patterns.
-
#generate_rbs? ⇒ Boolean
Check if RBS files should be generated.
-
#include_patterns ⇒ Object
Get include patterns for file discovery.
-
#initialize(config_path = nil) ⇒ Config
constructor
A new instance of Config.
-
#out_dir ⇒ Object
Backwards compatible: alias for ruby_dir.
-
#rbs_dir ⇒ String
Get output directory for RBS files.
-
#ruby_dir ⇒ String
Get output directory for compiled Ruby files.
-
#source_exclude ⇒ Array<String>
Get source exclude patterns.
-
#source_extensions ⇒ Array<String>
Get source file extensions.
-
#source_include ⇒ Array<String>
Get source include directories.
-
#src_dir ⇒ Object
Backwards compatible: first source.include directory.
-
#strictness ⇒ String
Get compiler strictness level.
-
#target_ruby ⇒ String
Get target Ruby version.
-
#validate! ⇒ Object
Validate the configuration.
-
#version_satisfied? ⇒ Boolean
Check if current T-Ruby version satisfies the version requirement.
-
#watch_clear_screen? ⇒ Boolean
Check if terminal should be cleared before rebuild.
-
#watch_debounce ⇒ Integer
Get watch debounce delay in milliseconds.
-
#watch_on_success ⇒ String?
Get command to run after successful compilation.
-
#watch_paths ⇒ Array<String>
Get additional watch paths.
Constructor Details
#initialize(config_path = nil) ⇒ Config
Returns a new instance of Config.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/t_ruby/config.rb', line 51 def initialize(config_path = nil) raw_config = load_raw_config(config_path) config = process_config(raw_config) @source = config["source"] @output = config["output"] @compiler = config["compiler"] @watch = config["watch"] @version_requirement = raw_config["version"] end |
Instance Attribute Details
#compiler ⇒ Object (readonly)
Returns the value of attribute compiler.
49 50 51 |
# File 'lib/t_ruby/config.rb', line 49 def compiler @compiler end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
49 50 51 |
# File 'lib/t_ruby/config.rb', line 49 def output @output end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
49 50 51 |
# File 'lib/t_ruby/config.rb', line 49 def source @source end |
#version_requirement ⇒ Object (readonly)
Returns the value of attribute version_requirement.
49 50 51 |
# File 'lib/t_ruby/config.rb', line 49 def version_requirement @version_requirement end |
#watch ⇒ Object (readonly)
Returns the value of attribute watch.
49 50 51 |
# File 'lib/t_ruby/config.rb', line 49 def watch @watch end |
Instance Method Details
#check_no_implicit_any? ⇒ Boolean
Check if no_implicit_any check is enabled
113 114 115 |
# File 'lib/t_ruby/config.rb', line 113 def check_no_implicit_any? @compiler.dig("checks", "no_implicit_any") == true end |
#check_no_unused_vars? ⇒ Boolean
Check if no_unused_vars check is enabled
119 120 121 |
# File 'lib/t_ruby/config.rb', line 119 def check_no_unused_vars? @compiler.dig("checks", "no_unused_vars") == true end |
#check_strict_nil? ⇒ Boolean
Check if strict_nil check is enabled
125 126 127 |
# File 'lib/t_ruby/config.rb', line 125 def check_strict_nil? @compiler.dig("checks", "strict_nil") == true end |
#clean_before_build? ⇒ Boolean
Check if output directory should be cleaned before build
76 77 78 |
# File 'lib/t_ruby/config.rb', line 76 def clean_before_build? @output["clean_before_build"] == true end |
#exclude_patterns ⇒ Object
Get exclude patterns
207 208 209 |
# File 'lib/t_ruby/config.rb', line 207 def exclude_patterns @source["exclude"] || [] end |
#excluded?(file_path) ⇒ Boolean
Check if a file path should be excluded
233 234 235 236 |
# File 'lib/t_ruby/config.rb', line 233 def excluded?(file_path) relative_path = relative_to_src(file_path) all_exclude_patterns.any? { |pattern| matches_pattern?(relative_path, pattern) } end |
#experimental_enabled?(feature) ⇒ Boolean
Check if a specific experimental feature is enabled
107 108 109 |
# File 'lib/t_ruby/config.rb', line 107 def experimental_enabled?(feature) experimental_features.include?(feature) end |
#experimental_features ⇒ Array<String>
Get list of enabled experimental features
100 101 102 |
# File 'lib/t_ruby/config.rb', line 100 def experimental_features @compiler["experimental"] || [] end |
#find_source_files ⇒ Array<String>
Find all source files matching include patterns, excluding exclude patterns
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/t_ruby/config.rb', line 213 def find_source_files files = [] @source["include"].each do |include_dir| base_dir = File.(include_dir) next unless Dir.exist?(base_dir) include_patterns.each do |pattern| full_pattern = File.join(base_dir, pattern) files.concat(Dir.glob(full_pattern)) end end # Filter out excluded files files.reject { |f| excluded?(f) }.uniq.sort end |
#generate_rbs? ⇒ Boolean
Check if RBS files should be generated
88 89 90 |
# File 'lib/t_ruby/config.rb', line 88 def generate_rbs? @compiler["generate_rbs"] != false end |
#include_patterns ⇒ Object
Get include patterns for file discovery
201 202 203 204 |
# File 'lib/t_ruby/config.rb', line 201 def include_patterns extensions = @source["extensions"] || [".trb"] extensions.map { |ext| "**/*#{ext}" } end |
#out_dir ⇒ Object
Backwards compatible: alias for ruby_dir
173 174 175 |
# File 'lib/t_ruby/config.rb', line 173 def out_dir ruby_dir end |
#rbs_dir ⇒ String
Get output directory for RBS files
70 71 72 |
# File 'lib/t_ruby/config.rb', line 70 def rbs_dir @output["rbs_dir"] || ruby_dir end |
#ruby_dir ⇒ String
Get output directory for compiled Ruby files
64 65 66 |
# File 'lib/t_ruby/config.rb', line 64 def ruby_dir @output["ruby_dir"] || "build" end |
#source_exclude ⇒ Array<String>
Get source exclude patterns
190 191 192 |
# File 'lib/t_ruby/config.rb', line 190 def source_exclude @source["exclude"] || [] end |
#source_extensions ⇒ Array<String>
Get source file extensions
196 197 198 |
# File 'lib/t_ruby/config.rb', line 196 def source_extensions @source["extensions"] || [".trb"] end |
#source_include ⇒ Array<String>
Get source include directories
184 185 186 |
# File 'lib/t_ruby/config.rb', line 184 def source_include @source["include"] || ["src"] end |
#src_dir ⇒ Object
Backwards compatible: first source.include directory
178 179 180 |
# File 'lib/t_ruby/config.rb', line 178 def src_dir @source["include"].first || "src" end |
#strictness ⇒ String
Get compiler strictness level
82 83 84 |
# File 'lib/t_ruby/config.rb', line 82 def strictness @compiler["strictness"] || "standard" end |
#target_ruby ⇒ String
Get target Ruby version
94 95 96 |
# File 'lib/t_ruby/config.rb', line 94 def target_ruby (@compiler["target_ruby"] || "3.0").to_s end |
#validate! ⇒ Object
Validate the configuration
167 168 169 170 |
# File 'lib/t_ruby/config.rb', line 167 def validate! validate_strictness! true end |
#version_satisfied? ⇒ Boolean
Check if current T-Ruby version satisfies the version requirement
155 156 157 158 159 160 161 162 163 |
# File 'lib/t_ruby/config.rb', line 155 def version_satisfied? return true if @version_requirement.nil? requirement = Gem::Requirement.new(@version_requirement) current = Gem::Version.new(TRuby::VERSION) requirement.satisfied_by?(current) rescue ArgumentError false end |
#watch_clear_screen? ⇒ Boolean
Check if terminal should be cleared before rebuild
143 144 145 |
# File 'lib/t_ruby/config.rb', line 143 def watch_clear_screen? @watch["clear_screen"] == true end |
#watch_debounce ⇒ Integer
Get watch debounce delay in milliseconds
137 138 139 |
# File 'lib/t_ruby/config.rb', line 137 def watch_debounce @watch["debounce"] || 100 end |
#watch_on_success ⇒ String?
Get command to run after successful compilation
149 150 151 |
# File 'lib/t_ruby/config.rb', line 149 def watch_on_success @watch["on_success"] end |
#watch_paths ⇒ Array<String>
Get additional watch paths
131 132 133 |
# File 'lib/t_ruby/config.rb', line 131 def watch_paths @watch["paths"] || [] end |