Sha256: 0ba04ae1acced8d04e203c9f0974f121f0cce107467a0a761b0b822d672bfb20
Contents?: true
Size: 1.98 KB
Versions: 5
Compression:
Stored size: 1.98 KB
Contents
module GraphQLPreview class SchemaModification def self.masks ObjectSpace.each_object(Class).select { |klass| klass < self } end def self.to_h { title: title, description: description, toggled_by: toggled_by, announcement: announcement, updates: updates, toggled_on: toggled_on } end def self.title(new_title = nil) if new_title @title = new_title else @title end end def self.description(new_description = nil) if new_description @description = new_description else @description end end def self.toggled_by(new_toggled_by = nil) if new_toggled_by @toggled_by = new_toggled_by else @toggled_by end end def self.announced_on(date, url: nil) @announcement = { date: date, url: url } end def self.announcement @announcement end def self.updated_on(date, url: nil) @updates ||= [] @updates << { date: date, url: url } end def self.updates @updates end def self.toggled_on(types = nil) if types types.each do |type| unless type.respond_to?(:metadata) raise MethodError, "`#{type}` cannot have its metadata set" end if type.metadata.key?(:preview_toggled_by) raise ArgumentError, "Couldn't add `#{self.toggled_by}` to `#{type.name}`: it's already toggled with `#{type.metadata[:preview_toggled_by].toggled_by}`" end type.metadata[:preview_toggled_by] = self if type.is_a?(GraphQL::InterfaceType) mark_children(type) end end @toggled_on = types else @toggled_on end end private def self.mark_children(type) type.fields.each_value do |field| field.metadata[:preview_toggled_by] = self end end end end
Version data entries
5 entries across 5 versions & 1 rubygems