Class: CrystalRuby::Configuration
- Inherits:
-
Object
- Object
- CrystalRuby::Configuration
- Includes:
- Singleton
- Defined in:
- lib/crystalruby/config.rb
Overview
Defines our configuration singleton Config can be specified through either:
-
crystalruby.yaml OR
-
CrystalRuby.configure block
Instance Attribute Summary collapse
-
#colorize_log_output ⇒ Object
Returns the value of attribute colorize_log_output.
-
#crystal_missing_ignore ⇒ Object
Returns the value of attribute crystal_missing_ignore.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#single_thread_mode ⇒ Object
Returns the value of attribute single_thread_mode.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
- #file_config ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #log_level=(level) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/crystalruby/config.rb', line 23 def initialize @paths_cache = {} config = read_config || {} @crystal_src_dir = config.fetch("crystal_src_dir", "./crystalruby") @crystal_codegen_dir = config.fetch("crystal_codegen_dir", "generated") @crystal_project_root = config.fetch("crystal_project_root", Pathname.pwd) @crystal_missing_ignore = config.fetch("crystal_missing_ignore", false) @debug = config.fetch("debug", false) @verbose = config.fetch("verbose", false) @single_thread_mode = config.fetch("single_thread_mode", false) @colorize_log_output = config.fetch("colorize_log_output", false) @log_level = config.fetch("log_level", ENV.fetch("CRYSTALRUBY_LOG_LEVEL", "info")) @logger = Logger.new($stdout) @logger.level = Logger.const_get(@log_level.to_s.upcase) end |
Instance Attribute Details
#colorize_log_output ⇒ Object
Returns the value of attribute colorize_log_output.
20 21 22 |
# File 'lib/crystalruby/config.rb', line 20 def colorize_log_output @colorize_log_output end |
#crystal_missing_ignore ⇒ Object
Returns the value of attribute crystal_missing_ignore.
20 21 22 |
# File 'lib/crystalruby/config.rb', line 20 def crystal_missing_ignore @crystal_missing_ignore end |
#debug ⇒ Object
Returns the value of attribute debug.
20 21 22 |
# File 'lib/crystalruby/config.rb', line 20 def debug @debug end |
#logger ⇒ Object
Returns the value of attribute logger.
20 21 22 |
# File 'lib/crystalruby/config.rb', line 20 def logger @logger end |
#single_thread_mode ⇒ Object
Returns the value of attribute single_thread_mode.
20 21 22 |
# File 'lib/crystalruby/config.rb', line 20 def single_thread_mode @single_thread_mode end |
#verbose ⇒ Object
Returns the value of attribute verbose.
20 21 22 |
# File 'lib/crystalruby/config.rb', line 20 def verbose @verbose end |
Class Method Details
.define_directory_accessors!(parent, directory_node) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/crystalruby/config.rb', line 47 def self.define_directory_accessors!(parent, directory_node) case directory_node when Array then directory_node.each(&method(:define_directory_accessors!).curry[parent]) when Hash directory_node.each do |par, children| define_directory_accessors!(parent, par) define_directory_accessors!(par, children) end else define_method(directory_node) do @paths_cache[directory_node] ||= Pathname.new(instance_variable_get(:"@#{directory_node}")) end define_method("#{directory_node}_abs") do @paths_cache["#{directory_node}_abs"] ||= parent ? send("#{parent}_abs") / Pathname.new(instance_variable_get(:"@#{directory_node}")) : send(directory_node) end end end |
Instance Method Details
#file_config ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/crystalruby/config.rb', line 39 def file_config @file_config ||= File.exist?("crystalruby.yaml") && begin YAML.safe_load(IO.read("crystalruby.yaml")) rescue StandardError nil end || {} end |
#log_level=(level) ⇒ Object
67 68 69 |
# File 'lib/crystalruby/config.rb', line 67 def log_level=(level) @logger.level = Logger.const_get(@log_level = level.to_s.upcase) end |