Class: Syntaxer::Reader::DSLReader
- Inherits:
-
Object
- Object
- Syntaxer::Reader::DSLReader
- Defined in:
- lib/syntaxer/reader.rb
Instance Attribute Summary collapse
-
#ignored_folders ⇒ Object
readonly
Returns the value of attribute ignored_folders.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
- .build(skip_default_rules = false, default_rules_file = SYNTAXER_RULES_FILE) ⇒ Object
-
.load(*dsl_files) ⇒ DSLReader
Read files from params and send to #parse method to fill in LanguageDefinition objects.
Instance Method Summary collapse
- #exec_rule(exec_string) ⇒ Object
- #extensions(*args) ⇒ Object
- #files_count(syntaxer) ⇒ Object
-
#folders(*args) ⇒ args
(also: #f)
Stub for DSL folders method.
- #ignore_folders(ignore_folders) ⇒ Object
-
#initialize ⇒ DSLReader
constructor
A new instance of DSLReader.
-
#languages(*args) {|langs_name| ... } ⇒ nil
(also: #lang)
The languages block executor.
- #overall_ignore_folders(*args) ⇒ Object (also: #ignore)
-
#parse(dsl_data) ⇒ Object
Parses a syntaxer DSL specification from the string given.
- #specific_files(*args) ⇒ Object
-
#syntaxer { ... } ⇒ Object
The top level block executor.
Constructor Details
#initialize ⇒ DSLReader
Returns a new instance of DSLReader.
12 13 14 15 |
# File 'lib/syntaxer/reader.rb', line 12 def initialize @rules = LanguageRules.new @ignore_folders = [] end |
Instance Attribute Details
#ignored_folders ⇒ Object (readonly)
Returns the value of attribute ignored_folders.
10 11 12 |
# File 'lib/syntaxer/reader.rb', line 10 def ignored_folders @ignored_folders end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
10 11 12 |
# File 'lib/syntaxer/reader.rb', line 10 def rules @rules end |
Class Method Details
.build(skip_default_rules = false, default_rules_file = SYNTAXER_RULES_FILE) ⇒ Object
45 46 47 48 49 |
# File 'lib/syntaxer/reader.rb', line 45 def build(skip_default_rules = false, default_rules_file = SYNTAXER_RULES_FILE) reader = new reader.parse(File.read(default_rules_file)) unless skip_default_rules reader end |
.load(*dsl_files) ⇒ DSLReader
Read files from params and send to #parse method to fill in LanguageDefinition objects.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/syntaxer/reader.rb', line 32 def load(*dsl_files) reader = build dsl_files = [dsl_files].flatten dsl_files.each do |file| begin reader.parse(File.read(file)) rescue SystemCallError raise ::Syntaxer::Reader::DSLFileNotFoundError, "Error reading syntaxer rules file with path '#{file}'! Please ensure it exists and that it is accessible." end end reader end |
Instance Method Details
#exec_rule(exec_string) ⇒ Object
127 128 129 130 131 |
# File 'lib/syntaxer/reader.rb', line 127 def exec_rule(exec_string) current_rule.executor = exec_string.scan(/\w+/).first current_rule.exec_existence = system("which #{current_rule.executor} > /dev/null") current_rule.exec_rule = exec_string end |
#extensions(*args) ⇒ Object
119 120 121 |
# File 'lib/syntaxer/reader.rb', line 119 def extensions(*args) current_rule.extensions = args end |
#files_count(syntaxer) ⇒ Object
17 18 19 20 21 |
# File 'lib/syntaxer/reader.rb', line 17 def files_count syntaxer @rules.map{ |rule| rule.files_list(syntaxer.root_path).length }.inject(:+) end |
#folders(*args) ⇒ args Also known as: f
Note:
This method won’t check if files are really exist.
Stub for DSL folders method.
115 116 117 |
# File 'lib/syntaxer/reader.rb', line 115 def folders(*args) current_rule.folders = (args.empty? ? [DEFAULT_FILES_MASK] : args.flatten) end |
#ignore_folders(ignore_folders) ⇒ Object
133 134 135 |
# File 'lib/syntaxer/reader.rb', line 133 def ignore_folders(ignore_folders) current_rule.ignore_folders = ignore_folders end |
#languages(*args) {|langs_name| ... } ⇒ nil Also known as: lang
The languages block executor
96 97 98 99 100 101 |
# File 'lib/syntaxer/reader.rb', line 96 def languages(*args, &block) args.each do |lang| @current_rule = @rules.find_or_create(lang) self.instance_eval(&block) end end |
#overall_ignore_folders(*args) ⇒ Object Also known as: ignore
137 138 139 |
# File 'lib/syntaxer/reader.rb', line 137 def overall_ignore_folders(*args) @ignored_folders = args end |
#parse(dsl_data) ⇒ Object
Parses a syntaxer DSL specification from the string given.
65 66 67 68 69 |
# File 'lib/syntaxer/reader.rb', line 65 def parse(dsl_data) self.instance_eval(dsl_data) rescue SyntaxError, NoMethodError, NameError => e raise DSLSyntaxError, "Illegal DSL syntax: #{e}" end |
#specific_files(*args) ⇒ Object
123 124 125 |
# File 'lib/syntaxer/reader.rb', line 123 def specific_files(*args) current_rule.specific_files = args end |
#syntaxer { ... } ⇒ Object
The top level block executor
81 82 83 |
# File 'lib/syntaxer/reader.rb', line 81 def syntaxer(&block) self.instance_eval(&block) end |