Class: Silicon::Routing::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/silicon/routing/file_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(silicon_config) ⇒ FileReader

Returns a new instance of FileReader.



4
5
6
# File 'lib/silicon/routing/file_reader.rb', line 4

def initialize(silicon_config)
  @config = silicon_config
end

Instance Method Details

#readObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/silicon/routing/file_reader.rb', line 8

def read
  path = File.join('./', @config[:path][:routes])
  content = File.read(path)

  # use '^' instead spaces and tabs
  raw_content = content.gsub(/\t/, '  ')
                  .gsub('  ', '^')
                  .gsub(' ', '')

  ###Hack:
  # grammar problem - can't simply match '-' character in route path when '->' present.
  # Will be resolved later. Replace '->', '<-' with '*>', '<*' for a while for syntax parser.
  ###
  raw_content = raw_content.gsub('->', '*>').gsub('<-', '<*')

  raw_content.gsub!("\n", ';') + ';'
end