Class: Ordit::DefinitionMatcher
- Inherits:
-
Object
- Object
- Ordit::DefinitionMatcher
- Defined in:
- lib/ordit/definition_matcher.rb
Constant Summary collapse
- HTML_PATTERN =
Match data-controller in HTML attributes
/data-controller=["']([^"']+)["']/.freeze
- RUBY_PATTERN =
Match controller: in Ruby/ERB
/controller:\s*['"]([^'"]+)['"]/.freeze
- HASH_ROCKET_PATTERN =
Match ‘controller’ => in Ruby/ERB
/(?:['"]controller['"]|:controller)\s*=>\s*['"]([^'"]+)['"]/.freeze
- ALL_REGEX =
[HTML_PATTERN, RUBY_PATTERN, HASH_ROCKET_PATTERN].freeze
Class Method Summary collapse
Class Method Details
.run(str) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/ordit/definition_matcher.rb', line 14 def self.run(str) ALL_REGEX.each_with_object(Set.new) do |pattern, controllers| matches = str.scan(pattern) next if matches.empty? || matches.nil? flattened_matches = matches.flatten.flat_map(&:split) controllers.merge(flattened_matches) end.to_a end |