Sha256: ae0d4fafdc6c38ab6305ed769b8f5ed30838eb2eff86bc22345a31aab0015280

Contents?: true

Size: 988 Bytes

Versions: 40

Compression:

Stored size: 988 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

      def self.graphql_type_name(name)
        name.gsub("Resource", "")
          .gsub("::", "") # remove modules
          .gsub(".", "__") # remove remote resource .
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
graphiti-1.7.6 lib/graphiti/util/class.rb
graphiti-1.7.5 lib/graphiti/util/class.rb
graphiti-1.7.4 lib/graphiti/util/class.rb
graphiti-1.7.3 lib/graphiti/util/class.rb
graphiti-1.7.2 lib/graphiti/util/class.rb
graphiti-1.7.1 lib/graphiti/util/class.rb
graphiti-1.7.0 lib/graphiti/util/class.rb
graphiti-1.6.4 lib/graphiti/util/class.rb
graphiti-1.6.3 lib/graphiti/util/class.rb
graphiti-1.6.2 lib/graphiti/util/class.rb
graphiti-1.6.1 lib/graphiti/util/class.rb
graphiti-1.6.0 lib/graphiti/util/class.rb
graphiti-1.5.3 lib/graphiti/util/class.rb
graphiti-1.5.2 lib/graphiti/util/class.rb
graphiti-1.5.1 lib/graphiti/util/class.rb
graphiti-1.5.0 lib/graphiti/util/class.rb
graphiti-1.4.0 lib/graphiti/util/class.rb
graphiti-1.3.9 lib/graphiti/util/class.rb
graphiti-1.3.8 lib/graphiti/util/class.rb
graphiti-1.3.7 lib/graphiti/util/class.rb