Class: BaseEditingBootstrap::ResourceFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/base_editing_bootstrap/resource_finder.rb

Overview

PORO to find the base classe in the BaseEditingController

Instance Method Summary collapse

Constructor Details

#initialize(controllar_path) ⇒ ResourceFinder

Returns a new instance of ResourceFinder.



7
8
9
10
# File 'lib/base_editing_bootstrap/resource_finder.rb', line 7

def initialize(controllar_path)
  @controllar_path = controllar_path
  @_model_class = false
end

Instance Method Details

#modelNilClass|Object

Returns:

  • (NilClass|Object)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/base_editing_bootstrap/resource_finder.rb', line 13

def model
  if @_model_class === false
    @_model_class = nil
    if (anything = @controllar_path.singularize.camelize.safe_constantize)
      @_model_class = anything
    else
      if @controllar_path.include?("/")
        demodulize_one_level = @controllar_path.split("/")[1..].join("/")
        if demodulize_one_level != @controllar_path
          @_model_class = ResourceFinder.new(demodulize_one_level).model
        end
      end
    end
  end
  @_model_class
end