Class: Erbf::Config
- Inherits:
-
Object
- Object
- Erbf::Config
- Defined in:
- lib/erbf/config.rb
Constant Summary collapse
- DEFAULT_FILEPATHS =
%w[config/erbf.yml .erbf.yml].freeze
Instance Attribute Summary collapse
-
#embedded ⇒ Object
readonly
Returns the value of attribute embedded.
-
#line_length ⇒ Object
readonly
Returns the value of attribute line_length.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#ruby ⇒ Object
readonly
Returns the value of attribute ruby.
Class Method Summary collapse
- .default_embedded ⇒ Object
- .default_options ⇒ Object
- .default_ruby ⇒ Object
- .load(config_file: nil, **options) ⇒ Object
- .options_from_default_file ⇒ Object
- .options_from_file(path) ⇒ Object
Instance Method Summary collapse
- #debug? ⇒ Boolean
-
#initialize(line_length:, logger:, debug:, embedded:, ruby:) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(line_length:, logger:, debug:, embedded:, ruby:) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 16 17 |
# File 'lib/erbf/config.rb', line 11 def initialize(line_length:, logger:, debug:, embedded:, ruby:) @line_length = line_length @logger = logger @debug = debug @embedded = @ruby = ruby end |
Instance Attribute Details
#embedded ⇒ Object (readonly)
Returns the value of attribute embedded.
9 10 11 |
# File 'lib/erbf/config.rb', line 9 def @embedded end |
#line_length ⇒ Object (readonly)
Returns the value of attribute line_length.
9 10 11 |
# File 'lib/erbf/config.rb', line 9 def line_length @line_length end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/erbf/config.rb', line 9 def logger @logger end |
#ruby ⇒ Object (readonly)
Returns the value of attribute ruby.
9 10 11 |
# File 'lib/erbf/config.rb', line 9 def ruby @ruby end |
Class Method Details
.default_embedded ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/erbf/config.rb', line 31 def prettier = "node_modules/.bin/prettier" if File.exist?(prettier) [ { types: %w[text/javascript module], command: "#{prettier} --stdin-filepath file.js --print-width %<line_length>d" }, { types: ["text/css"], command: "#{prettier} --stdin-filepath file.css --print-width %<line_length>d" }, { types: %w[importmap application/json application/ld+json], command: "#{prettier} --stdin-filepath file.json --print-width %<line_length>d" } ] else [] end end |
.default_options ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/erbf/config.rb', line 57 def { line_length: 80, logger: Logger.new($stderr, level: Logger::WARN), debug: false, embedded: , ruby: default_ruby } end |
.default_ruby ⇒ Object
53 54 55 |
# File 'lib/erbf/config.rb', line 53 def default_ruby { formatter: "syntax_tree", syntax_tree_plugins: [] } end |
.load(config_file: nil, **options) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/erbf/config.rb', line 22 def load(config_file: nil, **) opts = .merge( config_file.nil? ? : (config_file), ) new(**opts) end |
.options_from_default_file ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/erbf/config.rb', line 72 def DEFAULT_FILEPATHS.each do |path| next unless File.exist?(path) return (path) end {} end |
.options_from_file(path) ⇒ Object
67 68 69 70 |
# File 'lib/erbf/config.rb', line 67 def (path) yaml = YAML.safe_load_file(path, symbolize_names: true) { line_length: yaml[:line_length], embedded: yaml[:embedded], ruby: yaml[:ruby] }.compact end |
Instance Method Details
#debug? ⇒ Boolean
19 |
# File 'lib/erbf/config.rb', line 19 def debug? = @debug |