Sha256: 6d35217f657c2cb1faea83a66229c59c3800f0fee7a7fb5083449c73f1698100

Contents?: true

Size: 807 Bytes

Versions: 42

Compression:

Stored size: 807 Bytes

Contents

module Graphiti
  module Util
    class Class
      def self.infer_resource_class(parent_resource_class, sideload_name)
        namespace = namespace_for(parent_resource_class)
        inferred_name = "#{sideload_name.to_s.singularize.classify}Resource"
        klass_name = "#{namespace}::#{inferred_name}"
        tried = [klass_name, inferred_name]
        klass = klass_name.safe_constantize
        klass ||= inferred_name.safe_constantize
        unless klass
          raise Errors::ResourceNotFound.new(parent_resource_class, sideload_name, tried)
        end
        klass
      end

      def self.namespace_for(klass)
        namespace = klass.name
        return "" unless namespace
        split = namespace.split("::")
        split[0, split.length - 1].join("::")
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
graphiti-1.2.8 lib/graphiti/util/class.rb
graphiti-1.2.7 lib/graphiti/util/class.rb
graphiti-1.2.6 lib/graphiti/util/class.rb
graphiti-1.2.5 lib/graphiti/util/class.rb
graphiti-1.2.4 lib/graphiti/util/class.rb
graphiti-1.2.3 lib/graphiti/util/class.rb
graphiti-1.2.2 lib/graphiti/util/class.rb
graphiti-1.2.1 lib/graphiti/util/class.rb
graphiti-1.2.0 lib/graphiti/util/class.rb
graphiti-1.1.1 lib/graphiti/util/class.rb
graphiti-1.1.0 lib/graphiti/util/class.rb
graphiti-1.0.3 lib/graphiti/util/class.rb
graphiti-1.0.2 lib/graphiti/util/class.rb
graphiti-1.0.1 lib/graphiti/util/class.rb
graphiti-1.0.0 lib/graphiti/util/class.rb
graphiti-1.0.rc.28 lib/graphiti/util/class.rb
graphiti-1.0.rc.27 lib/graphiti/util/class.rb
graphiti-1.0.rc.26 lib/graphiti/util/class.rb
graphiti-1.0.rc.25 lib/graphiti/util/class.rb
graphiti-1.0.rc.24 lib/graphiti/util/class.rb