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.31 lib/graphiti/util/class.rb
graphiti-1.2.30 lib/graphiti/util/class.rb
graphiti-1.2.29 lib/graphiti/util/class.rb
graphiti-1.2.28 lib/graphiti/util/class.rb
graphiti-1.2.27 lib/graphiti/util/class.rb
graphiti-1.2.26 lib/graphiti/util/class.rb
graphiti-1.2.25 lib/graphiti/util/class.rb
graphiti-1.2.21 lib/graphiti/util/class.rb
graphiti-1.2.20 lib/graphiti/util/class.rb
graphiti-1.2.19 lib/graphiti/util/class.rb
graphiti-1.2.18 lib/graphiti/util/class.rb
graphiti-1.2.17 lib/graphiti/util/class.rb
graphiti-1.2.16 lib/graphiti/util/class.rb
graphiti-1.2.15 lib/graphiti/util/class.rb
graphiti-1.2.14 lib/graphiti/util/class.rb
graphiti-1.2.13 lib/graphiti/util/class.rb
graphiti-1.2.12 lib/graphiti/util/class.rb
graphiti-1.2.11 lib/graphiti/util/class.rb
graphiti-1.2.10 lib/graphiti/util/class.rb
graphiti-1.2.9 lib/graphiti/util/class.rb