Class: GraphQL::Configuration::Slot

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/configuration/slot.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Slot

Returns a new instance of Slot.



6
7
8
9
10
11
12
13
14
# File 'lib/graphql/configuration/slot.rb', line 6

def initialize(*args, &block)
  define_methods
  options = args.last.is_a?(Hash) ? args.pop : {}
  options.keys.each { |key| options[key.to_sym] = options.delete(key) }
  attributes.each { |name| options[name.to_sym] = args.shift if args.size > 0 }
  options.each { |key, value| public_send(key, value) }
  instance_eval(&block) if block_given?
  validate!
end

Instance Method Details

#effective_typeObject



20
21
22
23
24
25
26
# File 'lib/graphql/configuration/slot.rb', line 20

def effective_type
  @effective_type ||= begin
    t = list? ? type.first : type
    t = t.call if t.is_a?(Proc)
    t
  end
end

#errorsObject



28
29
30
# File 'lib/graphql/configuration/slot.rb', line 28

def errors
  @errors ||= {}
end

#list?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/graphql/configuration/slot.rb', line 16

def list?
  type.is_a?(Array)
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/graphql/configuration/slot.rb', line 32

def valid?
  errors.size == 0
end

#validateObject



36
37
38
39
# File 'lib/graphql/configuration/slot.rb', line 36

def validate
  @errors = {}
  attributes.each { |name| send(:"validate_#{name}") }
end