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, "type_check" => 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.
-
#type_check? ⇒ Boolean
Check if type checking is enabled.
-
#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.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/t_ruby/config.rb', line 52 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.
50 51 52 |
# File 'lib/t_ruby/config.rb', line 50 def compiler @compiler end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
50 51 52 |
# File 'lib/t_ruby/config.rb', line 50 def output @output end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
50 51 52 |
# File 'lib/t_ruby/config.rb', line 50 def source @source end |
#version_requirement ⇒ Object (readonly)
Returns the value of attribute version_requirement.
50 51 52 |
# File 'lib/t_ruby/config.rb', line 50 def version_requirement @version_requirement end |
#watch ⇒ Object (readonly)
Returns the value of attribute watch.
50 51 52 |
# File 'lib/t_ruby/config.rb', line 50 def watch @watch end |
Instance Method Details
#check_no_implicit_any? ⇒ Boolean
Check if no_implicit_any check is enabled
120 121 122 |
# File 'lib/t_ruby/config.rb', line 120 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
126 127 128 |
# File 'lib/t_ruby/config.rb', line 126 def check_no_unused_vars? @compiler.dig("checks", "no_unused_vars") == true end |
#check_strict_nil? ⇒ Boolean
Check if strict_nil check is enabled
132 133 134 |
# File 'lib/t_ruby/config.rb', line 132 def check_strict_nil? @compiler.dig("checks", "strict_nil") == true end |
#clean_before_build? ⇒ Boolean
Check if output directory should be cleaned before build
77 78 79 |
# File 'lib/t_ruby/config.rb', line 77 def clean_before_build? @output["clean_before_build"] == true end |
#exclude_patterns ⇒ Object
Get exclude patterns
214 215 216 |
# File 'lib/t_ruby/config.rb', line 214 def exclude_patterns @source["exclude"] || [] end |
#excluded?(file_path) ⇒ Boolean
Check if a file path should be excluded
240 241 242 243 |
# File 'lib/t_ruby/config.rb', line 240 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
114 115 116 |
# File 'lib/t_ruby/config.rb', line 114 def experimental_enabled?(feature) experimental_features.include?(feature) end |
#experimental_features ⇒ Array<String>
Get list of enabled experimental features
107 108 109 |
# File 'lib/t_ruby/config.rb', line 107 def experimental_features @compiler["experimental"] || [] end |
#find_source_files ⇒ Array<String>
Find all source files matching include patterns, excluding exclude patterns
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/t_ruby/config.rb', line 220 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
89 90 91 |
# File 'lib/t_ruby/config.rb', line 89 def generate_rbs? @compiler["generate_rbs"] != false end |
#include_patterns ⇒ Object
Get include patterns for file discovery
208 209 210 211 |
# File 'lib/t_ruby/config.rb', line 208 def include_patterns extensions = @source["extensions"] || [".trb"] extensions.map { |ext| "**/*#{ext}" } end |
#out_dir ⇒ Object
Backwards compatible: alias for ruby_dir
180 181 182 |
# File 'lib/t_ruby/config.rb', line 180 def out_dir ruby_dir end |
#rbs_dir ⇒ String
Get output directory for RBS files
71 72 73 |
# File 'lib/t_ruby/config.rb', line 71 def rbs_dir @output["rbs_dir"] || ruby_dir end |
#ruby_dir ⇒ String
Get output directory for compiled Ruby files
65 66 67 |
# File 'lib/t_ruby/config.rb', line 65 def ruby_dir @output["ruby_dir"] || "build" end |
#source_exclude ⇒ Array<String>
Get source exclude patterns
197 198 199 |
# File 'lib/t_ruby/config.rb', line 197 def source_exclude @source["exclude"] || [] end |
#source_extensions ⇒ Array<String>
Get source file extensions
203 204 205 |
# File 'lib/t_ruby/config.rb', line 203 def source_extensions @source["extensions"] || [".trb"] end |
#source_include ⇒ Array<String>
Get source include directories
191 192 193 |
# File 'lib/t_ruby/config.rb', line 191 def source_include @source["include"] || ["src"] end |
#src_dir ⇒ Object
Backwards compatible: first source.include directory
185 186 187 |
# File 'lib/t_ruby/config.rb', line 185 def src_dir @source["include"].first || "src" end |
#strictness ⇒ String
Get compiler strictness level
83 84 85 |
# File 'lib/t_ruby/config.rb', line 83 def strictness @compiler["strictness"] || "standard" end |
#target_ruby ⇒ String
Get target Ruby version
101 102 103 |
# File 'lib/t_ruby/config.rb', line 101 def target_ruby (@compiler["target_ruby"] || "3.0").to_s end |
#type_check? ⇒ Boolean
Check if type checking is enabled
95 96 97 |
# File 'lib/t_ruby/config.rb', line 95 def type_check? @compiler["type_check"] != false end |
#validate! ⇒ Object
Validate the configuration
174 175 176 177 |
# File 'lib/t_ruby/config.rb', line 174 def validate! validate_strictness! true end |
#version_satisfied? ⇒ Boolean
Check if current T-Ruby version satisfies the version requirement
162 163 164 165 166 167 168 169 170 |
# File 'lib/t_ruby/config.rb', line 162 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
150 151 152 |
# File 'lib/t_ruby/config.rb', line 150 def watch_clear_screen? @watch["clear_screen"] == true end |
#watch_debounce ⇒ Integer
Get watch debounce delay in milliseconds
144 145 146 |
# File 'lib/t_ruby/config.rb', line 144 def watch_debounce @watch["debounce"] || 100 end |
#watch_on_success ⇒ String?
Get command to run after successful compilation
156 157 158 |
# File 'lib/t_ruby/config.rb', line 156 def watch_on_success @watch["on_success"] end |
#watch_paths ⇒ Array<String>
Get additional watch paths
138 139 140 |
# File 'lib/t_ruby/config.rb', line 138 def watch_paths @watch["paths"] || [] end |