Sha256: bb2d08fd43288f4a8d7ee1ce27eabe0876541e2bb432257147ed8829b2177c5a

Contents?: true

Size: 715 Bytes

Versions: 2

Compression:

Stored size: 715 Bytes

Contents

module Chanko
  module Unit
    class ScopeFinder
      LABEL_SCOPE_MAP = {
        :controller => ActionController::Base,
        :model      => ActiveRecord::Base,
        :view       => ActionView::Base,
      }

      def self.find(*args)
        new(*args).find
      end

      def initialize(identifier)
        @identifier = identifier
      end

      def find
        case
        when class?
          @identifier
        when label
          label
        else
          @identifier.to_s.constantize
        end
      rescue NameError
      end

      private

      def class?
        @identifier.is_a?(Class)
      end

      def label
        LABEL_SCOPE_MAP[@identifier]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chanko-2.0.1 lib/chanko/unit/scope_finder.rb
chanko-2.0.0 lib/chanko/unit/scope_finder.rb