Class: DataShifter::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/data_shifter/railtie.rb

Class Method Summary collapse

Class Method Details

.extract_description(file_path) ⇒ Object

Extract description DSL from shift file without loading it. Supports: description “text”, description ‘text’, description %(text), description <<~HEREDOC



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/data_shifter/railtie.rb', line 11

def self.extract_description(file_path)
  content = File.read(file_path)

  # Single/double quoted strings: description "text" or description 'text'
  if (match = content.match(/^\s*description\s+["'](.+?)["']/))
    return match[1]
  end

  # Percent strings: description %(text) or description %Q(text)
  if (match = content.match(/^\s*description\s+%Q?\((.+?)\)/m))
    return match[1].gsub(/\s+/, " ").strip
  end

  # Heredoc: description <<~HEREDOC or <<-HEREDOC or <<HEREDOC
  if (match = content.match(/^\s*description\s+<<[~-]?(\w+)\s*\n(.*?)\n\s*\1/m))
    return match[2].gsub(/\s+/, " ").strip
  end

  nil
end