Class: LazyFeatures::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
# File 'lib/lazyfeatures/parser.rb', line 6

def initialize(file_path)
  self.route_contents = File.open(file_path).read.split("\n")
  parse_resources
end

Instance Attribute Details

#collection_resourcesObject

Returns the value of attribute collection_resources.



4
5
6
# File 'lib/lazyfeatures/parser.rb', line 4

def collection_resources
  @collection_resources
end

#route_contentsObject

Returns the value of attribute route_contents.



4
5
6
# File 'lib/lazyfeatures/parser.rb', line 4

def route_contents
  @route_contents
end

#singleton_resourcesObject

Returns the value of attribute singleton_resources.



4
5
6
# File 'lib/lazyfeatures/parser.rb', line 4

def singleton_resources
  @singleton_resources
end

Instance Method Details

#parse_collectionsObject



23
24
25
26
27
28
# File 'lib/lazyfeatures/parser.rb', line 23

def parse_collections
  route_contents.map do |route|
    match = route.match(/^.*\.resources\s\:(\w+).*$/)
    match[1] if match
  end.compact
end

#parse_resourcesObject



11
12
13
14
# File 'lib/lazyfeatures/parser.rb', line 11

def parse_resources
  self.singleton_resources = parse_singletons
  self.collection_resources = parse_collections
end

#parse_singletonsObject



16
17
18
19
20
21
# File 'lib/lazyfeatures/parser.rb', line 16

def parse_singletons
  route_contents.map do |route|
    match = route.match(/^.*\.resource\s\:(\w+).*$/)
    match[1] if match
  end.compact
end