Module: Syntaxer
- Defined in:
- lib/syntaxer/reader.rb,
lib/syntaxer.rb,
lib/syntaxer/runner.rb,
lib/syntaxer/writer.rb,
lib/syntaxer/checker.rb,
lib/syntaxer/printer.rb,
lib/syntaxer/railtie.rb,
lib/syntaxer/wizzard.rb,
lib/syntaxer/repository.rb,
lib/syntaxer/file_status.rb,
lib/syntaxer/progress_bar.rb,
lib/syntaxer/language_definition.rb
Overview
Defined Under Namespace
Modules: Reader, Runners Classes: Checker, FileStatus, Git, GitRepositoryError, LanguageDefinition, LanguageDefinitionException, LanguageRules, PlainChecker, Printer, ProgressBar, Railtie, RepoChecker, Repository, RepositoryError, Runner, Svn, SvnRepositoryError, Wizzard, Writer
Constant Summary collapse
- DEFAULT_FILES_MASK =
"**/*"
- SYNTAXER_RULES_FILE =
File.join(File.dirname(__FILE__), "..", "syntaxer_rules.dist.rb")
- SYNTAXER_CONFIG_FILE_NAME =
"syntaxer.rb"
Class Attribute Summary collapse
-
.hook ⇒ Object
readonly
Returns the value of attribute hook.
-
.jslint ⇒ Object
readonly
Returns the value of attribute jslint.
-
.reader ⇒ Object
readonly
Returns the value of attribute reader.
-
.repository ⇒ Object
readonly
Returns the value of attribute repository.
-
.results ⇒ Object
readonly
Returns the value of attribute results.
-
.root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
.warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
-
.check_syntax(options = {}) ⇒ Boolean
Main method to be used for syntax checking.
- .configure {|_self| ... } ⇒ Object
-
.make_hook(options) ⇒ Nil
This method generate and put hook to .git/hooks.
- .wizzard(options) ⇒ Object
Class Attribute Details
.hook ⇒ Object (readonly)
Returns the value of attribute hook.
29 30 31 |
# File 'lib/syntaxer.rb', line 29 def hook @hook end |
.jslint ⇒ Object (readonly)
Returns the value of attribute jslint.
29 30 31 |
# File 'lib/syntaxer.rb', line 29 def jslint @jslint end |
.reader ⇒ Object (readonly)
Returns the value of attribute reader.
29 30 31 |
# File 'lib/syntaxer.rb', line 29 def reader @reader end |
.repository ⇒ Object (readonly)
Returns the value of attribute repository.
29 30 31 |
# File 'lib/syntaxer.rb', line 29 def repository @repository end |
.results ⇒ Object (readonly)
Returns the value of attribute results.
29 30 31 |
# File 'lib/syntaxer.rb', line 29 def results @results end |
.root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
29 30 31 |
# File 'lib/syntaxer.rb', line 29 def root_path @root_path end |
.warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
29 30 31 |
# File 'lib/syntaxer.rb', line 29 def warnings @warnings end |
Class Method Details
.check_syntax(options = {}) ⇒ Boolean
Main method to be used for syntax checking.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/syntaxer.rb', line 45 def check_syntax( = {}) @root_path = [:root_path] @warnings = [:warnings] @hook = [:hook] @jslint = [:jslint] Printer.quite = [:quite] || false Printer.loud = [:loud] || false @reader = Reader::DSLReader.load([:config_file]) if @jslint # if jslint option passed set from command line we have to add new rule with indicated dir rule = LanguageDefinition.new(:javascript, %w{js}, nil, [@jslint+"*", @jslint+"**/*"], nil, nil, nil, true, true) rule.exec_rule = Runner.javascript.call @reader.add_rule rule end @repository = Repository.factory(@root_path, [:repository]) if [:repository] $stdmyout = StringIO.new checker = Checker.process(self) Printer.print_result checker exit(1) unless checker.error_files.empty? && $stdmyout.string.empty? end |
.configure {|_self| ... } ⇒ Object
31 32 33 |
# File 'lib/syntaxer.rb', line 31 def configure yield(self) if block_given? end |
.make_hook(options) ⇒ Nil
This method generate and put hook to .git/hooks
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/syntaxer.rb', line 78 def make_hook() @root_path = [:root_path] raise ArgumentError, 'Indicate repository type' unless .include?(:repository) raise ArgumentError, "SVN is temporarily not supported" if [:repository].to_sym == :svn hook_file = "#{@root_path}/.git/hooks/pre-commit" hook_string = 'syntaxer ' if [:restore] && File.exist?(File.join(@root_path,'.syntaxer')) hook_string += File.open(File.join(@root_path,'.syntaxer')).read else repo = Repository.factory(@root_path, [:repository]) hook_string += "-r git --hook" hook_string += " -c config/syntaxer.rb" if [:rails] hook_string += " -c #{[:config_file]}" unless [:config_file].nil? end File.open(hook_file, 'w') do |f| f.puts hook_string end File.chmod(0755, hook_file) # save syntaxer options File.open(File.join([:root_path],'.syntaxer'), 'w') do |f| f.write(hook_string.gsub('syntaxer ','')) end rescue Exception => e puts e..color(:red) raise e end |