Sha256: 79dbbd22b3d81c9dc622769a5dac40750525295fc136906d257fdcece1a8d840

Contents?: true

Size: 842 Bytes

Versions: 5

Compression:

Stored size: 842 Bytes

Contents

# frozen_string_literal: true

module BaseEditingBootstrap
  ##
  # PORO to find the base classe in the BaseEditingController
  class ResourceFinder
    def initialize(controllar_path)
      @controllar_path = controllar_path
      @_model_class = false
    end

    # @return [NilClass|Object]
    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
base_editing_bootstrap-1.0.0 lib/base_editing_bootstrap/resource_finder.rb
base_editing_bootstrap-0.16.1 lib/base_editing_bootstrap/resource_finder.rb
base_editing_bootstrap-0.16.0 lib/base_editing_bootstrap/resource_finder.rb
base_editing_bootstrap-0.15.0 lib/base_editing_bootstrap/resource_finder.rb
base_editing_bootstrap-0.14.0 lib/base_editing_bootstrap/resource_finder.rb