Class: Fierce::PresenterFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/fierce/presenter_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PresenterFinder

Returns a new instance of PresenterFinder.



5
6
7
# File 'lib/fierce/presenter_finder.rb', line 5

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/fierce/presenter_finder.rb', line 3

def path
  @path
end

Instance Method Details

#file_path(base_path) ⇒ Object



13
14
15
# File 'lib/fierce/presenter_finder.rb', line 13

def file_path(base_path)
  "#{base_path}/#{path}.rb"
end

#foundObject



17
18
19
20
21
# File 'lib/fierce/presenter_finder.rb', line 17

def found
  @found = Fierce.paths.map do |base_path|
    base_path if File.exist?(file_path(base_path))
  end.compact.first
end

#path_to_classifyObject



27
28
29
30
31
32
# File 'lib/fierce/presenter_finder.rb', line 27

def path_to_classify
  found
    .gsub(root, '')
    .gsub('/app', '')
    .gsub(/\.rb$/, '') + "/#{path}"
end

#performObject



23
24
25
# File 'lib/fierce/presenter_finder.rb', line 23

def perform
  presenter_class if found
end

#presenter_classObject



34
35
36
37
# File 'lib/fierce/presenter_finder.rb', line 34

def presenter_class
  require file_path(found)
  path_to_classify.classify.constantize
end

#rootObject



9
10
11
# File 'lib/fierce/presenter_finder.rb', line 9

def root
  Rails.root.to_s
end