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" => nil, # Auto-detect from current Ruby version "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 If not specified in config, auto-detects from current Ruby environment.
-
#target_ruby_version ⇒ RubyVersion
Get target Ruby version as RubyVersion object.
-
#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
135 136 137 |
# File 'lib/t_ruby/config.rb', line 135 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
141 142 143 |
# File 'lib/t_ruby/config.rb', line 141 def check_no_unused_vars? @compiler.dig("checks", "no_unused_vars") == true end |
#check_strict_nil? ⇒ Boolean
Check if strict_nil check is enabled
147 148 149 |
# File 'lib/t_ruby/config.rb', line 147 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
229 230 231 |
# File 'lib/t_ruby/config.rb', line 229 def exclude_patterns @source["exclude"] || [] end |
#excluded?(file_path) ⇒ Boolean
Check if a file path should be excluded
255 256 257 258 |
# File 'lib/t_ruby/config.rb', line 255 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
129 130 131 |
# File 'lib/t_ruby/config.rb', line 129 def experimental_enabled?(feature) experimental_features.include?(feature) end |
#experimental_features ⇒ Array<String>
Get list of enabled experimental features
122 123 124 |
# File 'lib/t_ruby/config.rb', line 122 def experimental_features @compiler["experimental"] || [] end |
#find_source_files ⇒ Array<String>
Find all source files matching include patterns, excluding exclude patterns
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/t_ruby/config.rb', line 235 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
223 224 225 226 |
# File 'lib/t_ruby/config.rb', line 223 def include_patterns extensions = @source["extensions"] || [".trb"] extensions.map { |ext| "**/*#{ext}" } end |
#out_dir ⇒ Object
Backwards compatible: alias for ruby_dir
195 196 197 |
# File 'lib/t_ruby/config.rb', line 195 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
212 213 214 |
# File 'lib/t_ruby/config.rb', line 212 def source_exclude @source["exclude"] || [] end |
#source_extensions ⇒ Array<String>
Get source file extensions
218 219 220 |
# File 'lib/t_ruby/config.rb', line 218 def source_extensions @source["extensions"] || [".trb"] end |
#source_include ⇒ Array<String>
Get source include directories
206 207 208 |
# File 'lib/t_ruby/config.rb', line 206 def source_include @source["include"] || ["src"] end |
#src_dir ⇒ Object
Backwards compatible: first source.include directory
200 201 202 |
# File 'lib/t_ruby/config.rb', line 200 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 If not specified in config, auto-detects from current Ruby environment
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/t_ruby/config.rb', line 103 def target_ruby configured = @compiler["target_ruby"] if configured RubyVersion.parse(configured).validate! configured.to_s else version = RubyVersion.current.validate! "#{version.major}.#{version.minor}" end end |
#target_ruby_version ⇒ RubyVersion
Get target Ruby version as RubyVersion object
116 117 118 |
# File 'lib/t_ruby/config.rb', line 116 def target_ruby_version RubyVersion.parse(target_ruby) 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
189 190 191 192 |
# File 'lib/t_ruby/config.rb', line 189 def validate! validate_strictness! true end |
#version_satisfied? ⇒ Boolean
Check if current T-Ruby version satisfies the version requirement
177 178 179 180 181 182 183 184 185 |
# File 'lib/t_ruby/config.rb', line 177 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
165 166 167 |
# File 'lib/t_ruby/config.rb', line 165 def watch_clear_screen? @watch["clear_screen"] == true end |
#watch_debounce ⇒ Integer
Get watch debounce delay in milliseconds
159 160 161 |
# File 'lib/t_ruby/config.rb', line 159 def watch_debounce @watch["debounce"] || 100 end |
#watch_on_success ⇒ String?
Get command to run after successful compilation
171 172 173 |
# File 'lib/t_ruby/config.rb', line 171 def watch_on_success @watch["on_success"] end |
#watch_paths ⇒ Array<String>
Get additional watch paths
153 154 155 |
# File 'lib/t_ruby/config.rb', line 153 def watch_paths @watch["paths"] || [] end |