Class: Redcar::Declarations::Parser

Inherits:
Object
  • Object
show all
Defined in:
plugins/declarations/lib/declarations/parser.rb

Constant Summary

DEFINITIONS =
{
  /_steps\.rb$/ => YAML.load(CUKE_YAML) + YAML.load(RUBY_YAML),
  /_spec\.rb$/ => YAML.load(RUBY_YAML) + YAML.load(SPEC_YAML),
  /\.rb$/       => YAML.load(RUBY_YAML),
  /\.java$/     => YAML.load(JAVA_YAML),
  /\.groovy$/   => YAML.load(GROOVY_YAML),
  /\.php$/      => YAML.load(PHP_YAML),
  /\.js$/       => YAML.load(JS_YAML),
  /\.feature$/  => YAML.load(CUKE_YAML)
}

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Parser) initialize

A new instance of Parser



158
159
160
# File 'plugins/declarations/lib/declarations/parser.rb', line 158

def initialize
  @tags = []
end

Instance Attribute Details

- (Object) tags (readonly)

Returns the value of attribute tags



156
157
158
# File 'plugins/declarations/lib/declarations/parser.rb', line 156

def tags
  @tags
end

Class Method Details

+ (Object) definitions



145
146
147
148
149
150
151
152
153
154
# File 'plugins/declarations/lib/declarations/parser.rb', line 145

def self.definitions
  @definitions = nil
  @definitions ||= begin
    definitions = DEFINITIONS.clone
    Redcar.plugin_manager.objects_implementing(:declaration_definitions).each do
      definitions.merge(object.declaration_definitions)
    end
    definitions
  end
end

Instance Method Details

- (Object) decls_for_file(path)



168
169
170
171
172
173
174
175
# File 'plugins/declarations/lib/declarations/parser.rb', line 168

def decls_for_file(path)
  Parser.definitions.each do |fn_re, decls|
    if path =~ fn_re
      return decls
    end
  end
  nil
end

- (Object) match_kind(path, match)



177
178
179
180
181
182
183
184
185
# File 'plugins/declarations/lib/declarations/parser.rb', line 177

def match_kind(path, match)
  if decls = decls_for_file(path)
    decls.each do |decl|
      if match.match(Regexp.new(decl["regex"]))
        return decl["kind"]
      end
    end
  end
end

- (Object) parse(files)



162
163
164
165
166
# File 'plugins/declarations/lib/declarations/parser.rb', line 162

def parse(files)
  files.each do |path|
    @tags += match_in_file(path)
  end
end