Module: JSHint::Utils
- Defined in:
- lib/jshint/utils.rb
Class Method Summary collapse
- .copy_config_file ⇒ Object
- .default_config_path ⇒ Object
- .display(txt) ⇒ Object
-
.exclude_files(list, excluded) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac.
- .in_rails? ⇒ Boolean
- .load_config_file(file_name) ⇒ Object
- .log(txt) ⇒ Object
- .path_from_command_line(field) ⇒ Object
- .paths_from_command_line(field) ⇒ Object
- .pluralize(amount, word) ⇒ Object
- .remove_config_file ⇒ Object
-
.unique_files(list) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac.
Class Method Details
.copy_config_file ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/jshint/utils.rb', line 75 def copy_config_file display "Creating example JSHint config file in #{File.(JSHint.config_path)}... " if File.exists?(JSHint.config_path) log "\n\nWarning: config file exists, so it won't be overwritten. " + "You can copy it manually from the jshint_on_rails directory if you want to reset it." else FileUtils.copy(JSHint::DEFAULT_CONFIG_FILE, JSHint.config_path) log "done." end end |
.default_config_path ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/jshint/utils.rb', line 23 def default_config_path if in_rails? File.(File.join(Rails.root, 'config', 'jslint.yml')) else 'config/jslint.yml' end end |
.display(txt) ⇒ Object
31 32 33 |
# File 'lib/jshint/utils.rb', line 31 def display(txt) print txt end |
.exclude_files(list, excluded) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac
62 63 64 |
# File 'lib/jshint/utils.rb', line 62 def exclude_files(list, excluded) list.reject { |entry| excluded.any? { |f| File.identical?(f, entry) }} end |
.in_rails? ⇒ Boolean
19 20 21 |
# File 'lib/jshint/utils.rb', line 19 def in_rails? defined?(Rails) && Rails.respond_to?(:root) end |
.load_config_file(file_name) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/jshint/utils.rb', line 44 def load_config_file(file_name) if file_name && File.exists?(file_name) && File.file?(file_name) && File.readable?(file_name) YAML.load_file(file_name) else {} end end |
.log(txt) ⇒ Object
35 36 37 |
# File 'lib/jshint/utils.rb', line 35 def log(txt) puts txt end |
.path_from_command_line(field) ⇒ Object
66 67 68 |
# File 'lib/jshint/utils.rb', line 66 def path_from_command_line(field) ENV[field] || ENV[field.upcase] end |
.paths_from_command_line(field) ⇒ Object
70 71 72 73 |
# File 'lib/jshint/utils.rb', line 70 def paths_from_command_line(field) argument = ENV[field] || ENV[field.upcase] argument && argument.split(/,/) end |
.pluralize(amount, word) ⇒ Object
39 40 41 42 |
# File 'lib/jshint/utils.rb', line 39 def pluralize(amount, word) s = "s" unless amount == 1 "#{amount} #{word}#{s}" end |
.remove_config_file ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/jshint/utils.rb', line 86 def remove_config_file raise ArgumentError, "Please set JSHint.config_path" if JSHint.config_path.nil? display "Removing config file... " if File.exists?(JSHint.config_path) && File.file?(JSHint.config_path) if File.read(JSHint.config_path) == File.read(JSHint::DEFAULT_CONFIG_FILE) File.delete(JSHint.config_path) log "OK." else log "File was modified, so it won't be deleted automatically." end else log "OK (no config file found)." end end |
.unique_files(list) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac
53 54 55 56 57 58 59 |
# File 'lib/jshint/utils.rb', line 53 def unique_files(list) files = [] list.each do |entry| files << entry unless files.any? { |f| File.identical?(f, entry) } end files end |