Class: Graphiti::Util::Class
Class Method Summary collapse
- .graphql_type_name(name) ⇒ Object
- .infer_resource_class(parent_resource_class, sideload_name) ⇒ Object
- .namespace_for(klass) ⇒ Object
Class Method Details
.graphql_type_name(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/graphiti/util/class.rb', line 24 def self.graphql_type_name(name) name.gsub("Resource", "") .gsub("::", "") # remove modules .gsub(".", "__") # remove remote resource . end |
.infer_resource_class(parent_resource_class, sideload_name) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/graphiti/util/class.rb', line 4 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 |
.namespace_for(klass) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/graphiti/util/class.rb', line 17 def self.namespace_for(klass) namespace = klass.name return "" unless namespace split = namespace.split("::") split[0, split.length - 1].join("::") end |